0

I want to allow on a list web part a mutually exclusive selection for the items, so that I can force the user to select a single item and retrieve the item id using the SP.js JSOM.

There is a problem in achieving this:

1) Leaving default view configuration: I can use SP.js to retrieve the items but the user will be able to select multiple items.

2) I can disable in the view the Tabular View option (Allow Individual item checkboxes) to force the user single selection, but then I will not be able anymore to retireve a selected item, as it seems that selection is removed at all.

I need to execute a single custom action on a single selected item (for example through a button on the page); that's why I'm thinking about a way to force single item selection.

Please advise.

  • What do you want to do (with the id) when the user clicks an item? – Danny '365CSI' Engelman Aug 4 '15 at 13:58
  • @DannyEngelman for example read some field from the item. – Emiliano Poggi Aug 4 '15 at 14:49
  • So you mean: You have a View which does not include all fields and you want to retrieve a field? Then what do you want to do with it? – Danny '365CSI' Engelman Aug 4 '15 at 14:54
  • @DannyEngelman tried to make the question more clear. – Emiliano Poggi Aug 4 '15 at 15:02
2

There is all sorts of ways to skin this cat.

  • Add a Custom Action which can only be used once
  • Use CSR to render a button for each item

This all requires some coding.

For quick prototyping I stuff HTML+JavaScript in a Calculated Column (and then instruct the 5 US$ an hour programmers in India to replicate the behaviour in more solid code, although to be honest most often the client is fine with my ductape approach)

  • Create a Calculated Column
  • Set the datatype to Number
  • Paste the Formula

    ="<button class=""myButtons"" style=""cursor:pointer;"" onclick=""{"
    &"  event.preventDefault();"
    &"  var TR=this;while(TR.tagName!='TR'){TR=TR.parentNode}"    
    &"  var id=TR.id.split(',')[1];"
    &"  alert(id);"
    &"  [].forEach.call( document.getElementsByClassName('myButtons') , function(me){"
    &"      me.style.display='none';"
    &"  });"
    &"}"">My ID is ... </button>"
    

You can click a button once, it then hides all buttons.

For more inspiration see how we recenlty used this to kick off a Workflow for an Item:
Can I add a start workflow link to a column in a list view?

CalcMaster Bookmarklet to edit Formulas

It is a PITA to debug Calculated Columns. Because you don't get feedback until you save a Formula and you end up having to click multiple times to get back to your Formula.

I have written a small 'CalcMaster' bookmarklet which hooks into the formula-editor and does a save of the Formula on every keypress; giving immediate feedback.
Published a first version on GitHub:

https://github.com/Danny-Engelman/CalcMaster

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.