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 had a similar requirement and didn't want to give a validation error message. The intention is to automatically change the selection to the latest selected value in the grid. When User selects check all it persists the value that was selected before this operation. This is done as below in Grid's SaveInto
saveInto: { local!gridSelection, a!save( local!gridSelection.selected, if( rule!APN_isEmpty( local!gridSelection.selected ), {}, if( length( local!gridSelection.selected ) > 2, index( local!gridSelection.selected, 1, "" ), index( reverse( local!gridSelection.selected ), 1, "" ) ) ) ) }
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