Black Lives Matter. Please consider donating to Black Girls Code today.

SOLVED: How do I create a multi select datatable that only allows a single selection

I am trying to create a datatable that only allows a single selection. I know there is a single mode but that uses radio buttons and I need to be able to clear the selection. I cannot find a way to clear the selection once a radio is selected, additionally the radio remains selected even when applying custom dataset filters (index one remains index one selected even after reloading dataset).

What I am trying to do is create a callback that will, in the event more than one checkbox is ticked, pop the first item from the selected rows list, and return the list of only the newest selected checkbox thus unchecking the popped item.

For example:

  1. The first row is selected so ‘selected_rows’ is list[0]
  2. The second row is selected so ‘selected_rows’ is list[0, 1]
    a. The callback performs selected_rows.pop(0) thereby removing the first item from the list so ‘selected_rows’ is list[1]
  3. The new ‘selected_rows’ list is Output to the datatable and only the returned list indicies are selected

This is what I currently have setup however it just flat out does not work. I have not had any luck searching for answers for the last two days so any help would be appreciated.

This looks awfully complex for what you’re trying to do.

You could add a radio button with option 'none of the above' and when it is selected it behaves as if none is selected?
Or you could add a button to programmatically clear the radio (return None for the value property).

Yes I had definitely spent far too long looking at the problem. I came in today with a fresh brain and a quick read of your comment and realized I could single select the table to get the behavior I wanted and clear it out by simply returning [] to selected_rows.

I could have sworn I tried this yesterday but I guess I didn’t. Thanks for the sanity check @RenaudLN