Hello,I'd like to be able to select only one choice in a grid selection at the same time.Is there a way to force that?
OriginalPostID-202357
Discussion posts and replies are publicly visible
I find the official appian SAIL recipe approach of throwing a validation error to be unnecessary and kinda clunky, no offense, and to be quite honest it doesn't make much sense to me that after all this time they've never engineered the paging grid component to contain a "singleSelect" parameter (or alternatively "maxSelections" for greater flexibility) where the "select all" control will be hidden when # of selections is restricted (or at least, smaller than the current page size).
Out of necessity I've developed the following code which handles the single-select use case pretty strongly IMHO, and it has been refined quite a bit over the past 3 years or so:
saveInto: { a!save( local!gridSelection, a!gridSelection( pagingInfo: save!value.pagingInfo, selected: index( save!value.selected, length(save!value.selected), {} ) ) ) }
This code does similar to what some of the prior examples here suggest, though a bit more compact, and automatically handles the use case of de-selecting the current selected item. Note that there's currently no way to avoid the behavior where clicking the "select all" control causes the last item on the current page to be selected, as mentioned above - this is probably the single strongest reason there really needs to be an OOB control for restricting the number of selections.
Hey Mike,
Agree that there should be an out of the box option to handle it in an elegant manner.
Also, When you say ,"Note that there's currently no way to avoid the behavior where clicking the "select all" control causes the last item on the current page to be selected, as mentioned above". Did you try the code I gave above.
because it works for me, i.e retains the previous selected value.For this reason only I wont directly index the length but use it to see if I have to index the first or the last one
see the lines -
if( --If below is true it means you have clicked select all length( local!gridSelection.selected ) > 2, --logic to retain the older value index( local!gridSelection.selected, 1, "" ), --Logic to retain the new value index( reverse( local!gridSelection.selected ), 1, "" ) )
please let me know if this helps
manisht209 - "it works for me, i.e retains the previous selected value."
You're right - I suppose what I should really say instead is "there's no way to disable the select all control, as it will not give the user their desired results" - but I never thought to try retaining the original selection. I will try incorporating something similar into my current code.
The following should take that into account, plus if the user clicks "select all" when nothing is selected yet, the selection will remain empty in this version.
(Note that this code, as well as your code, both have a quirk when "select all" is clicked on a page containing 2 items - I can't find an easy way around this but it's probably not a big deal)
saveInto: { a!save( local!gridSelection, a!gridSelection( pagingInfo: save!value.pagingInfo, selected: if( length(save!value.selected) > 2, /* override if "select all" was clicked: retain original value */ local!gridSelection.selected, index( save!value.selected, length(save!value.selected), /* for normal clicks, this will correctly capture the first or any subsequent click, as well as a de-select click */ {} ) ) ) ) }