Select all rows in Dash DataTable

I managed to find a workaround using the selected_rows property and derived view port. I’ve made Select All and Deselect All buttons in the layout as inputs. For anyone else looking for the same functionality please refer to the snippet below:

@app.callback(
    [Output('in-table', 'selected_rows'),],
    [Input('select-all-button', 'n_clicks'),
    Input('deselect-all-button', 'n_clicks')],
    [State('in-table', 'derived_virtual_data'),]
)
def select_deselect(selbtn, deselbtn, selected_rows):
    ctx = dash.callback_context
    if ctx.triggered:
        trigger = (ctx.triggered[0]['prop_id'].split('.')[0])
    if trigger == 'select-all-button':
        if selected_rows is None:
            return [[]]
        else:
            return [[i for i in range(len(selected_rows))]]
    else:
        return [[]]
3 Likes