How to deselect datatable row

I currently have the row buttons on my datatable opening a modal with information based on the data in that row. Due to the nature of my code, when I update the table a modal automatically appears because a row is still selected from the previous table. Is there a way to clear the selected rows so I can avoid this problem?

1 Like

Hi @ilias0201 welcome to the forum! You can use the selected_rows or selected_row_ids (I haven’t tried which one works best) attributes of a dash datatable as output of a callback, in order to deselect rows. See https://dash.plot.ly/datatable/reference for the full list of attributes.

1 Like

Hi @ilias0201
Where you able to figure this out?. Can you tell me how?

Hey @nivek,

One way I solved this was to add the state of the selected cells argument for the table in question to the callback and then some initial handling at the beginning of the function inside that callback such as …

if selected_cell is None:
    raise dash.exceptions.PreventUpdate
elif not selected_cell:
    raise dash.exceptions.PreventUpdate

and then wrap up said function with an output of the selected cells argument setting it back to an empty list when appropriate []