Select only one choice in grid selection

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

OriginalPostID-202357

  Discussion posts and replies are publicly visible

  • - "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 */
              {}
            )
          )
        )
      )
    }

  • ...

    selectionValue: local!gridSelection,
    selectionSaveInto: {
      local!gridSelection,
      if(
        length(local!gridSelection)=1,
        local!gridSelection,
        a!save(local!gridSelection, local!gridSelection[2])
      )
    },

    ...

  • 0
    Appian Employee
    in reply to Jaume

    I don't think this is correct - your grid will error if you deselect a row because the if() condition will return false and the second save won't have 2 values.

    There's actually a recipe in the documentation that describes how to do this: docs.appian.com/.../recipe-limit-rows-to-one.html

  • This is a very old thread, and several of the original comments contain robust and still-working solutions to this. Though with the advent of the 19.2+ paging grid, all of this is a bit out-of-date.  For instance, designers now have the ability to turn off selection for all rows other than a single selected row, among other possible options.

  • 0
    Certified Senior Developer
    in reply to Shivam Gupta

    I found success w/ this use case in 23.1 by mimicking the above code w/ a few changes shown below. It mainly just adds a bit more handling for when you're de-selecting a row. 

    a!gridField(
        /*...*/
        selectionValue: local!gridSelection,
        selectionSaveInto: {
            local!gridSelection,
            if(
                a!isNullOrEmpty(local!gridSelection),
                {
                    a!save(local!gridSelection, {}),
                    a!save(local!selectionIndex, {})
                },
                {
                    a!save(local!selectionIndex, reverse(local!gridSelection)[1],
                    a!save(local!gridSelection, local!selectionIndex)
                }
            ),
            /*more saves*/
        },
        /*...*/
    )