Data_table - select all rows

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…

Any help is appreciated.

Thanks

1 Like

Currently it seems like Dash DataTable does not have this functionality.

You can follow this issue on GitHub:

I would also like to say this question, what’s the use of column selection? Multi-selection features and all-select checkbox are a natural match.

Solve your problem first, I have a way to compromise.

You can pass the value of the ‘derived_viewport_indices’ to ‘selected_rows’ through a callback of the dcc.Checklist.

Do we have any update on ‘select all rows’?

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))]]
5 Likes

Hello Can you please share the code for datatable. I am working on the same issue.

Thanks

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).

Anyone has any idea how to workaround?

Thanks.

2 Likes

let’s come to the top