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.

Emiliano Poggi
  • 759
  • 3
  • 11
  • 23

1 Answers1

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

Danny '365CSI' Engelman
  • 21,176
  • 7
  • 35
  • 79
  • Thanks for your answer, but i'm not convinced at all. I'm more for adding a custom action using js with CAMOpt (https://msdn.microsoft.com/en-us/library/aa505327.aspx#wsstipstricks_customizingthecontextmenuofdocumentlibraryitems). Please check the question again for more information. – Emiliano Poggi Aug 04 '15 at 15:40
  • I'm going to accept this answer as it is the only one and it's really pertinent to the initial question. I've created another question for the CAMOpt option I mentioned. Thank you again. – Emiliano Poggi Aug 04 '15 at 20:20
  • http://sharepoint.stackexchange.com/questions/151339/how-to-retrieve-target-menu-of-specific-list-web-part-for-camopt – Emiliano Poggi Aug 04 '15 at 20:21