I have a dash datatable with row_selectable=‘multi’. It is working great.
What I want to do is have all rows selected upon loading, and be able to deselect all at once, so the user can then select whichever rows they like. Is there a property/method built-in to do this? I was unable to find one…
I figured a workaround for this. I created a button on top of the table that when clicked will update the selected_rows property of the DataTable.
For example:
@app.callback(
[Output('datatable-interactivity-channel', "selected_rows"),],
[Input('all-button', 'n_clicks'),],
[State('datatable-interactivity-channel', "derived_virtual_data"),]
)
def select_all(n_clicks, selected_rows):
if selected_rows is None:
return [[]]
else:
return [[i for i in range(len(selected_rows))]]
Hi there! I tried this method and it works if there is no filtering on the datatable.
There is a problem where once I use the native filter to filter the datatable and click on this button, the checkboxes will not be tick properly even though the indices for the selected row correspond to the number of rows appearing in the datatable after filter. For example, once I filter and click on the button, it will not tick on the rows that appear in the filtered datatable.
Based on the callbacks, this method continue to tick the checkboxes of the ORIGINAL datatable data (if after filter there are 32 rows, then once I click on this button it will check the first 32 rows from the original data in the datatable instead of the filtered data).