dash-table
dash-table copied to clipboard
Select all rows
I don't think its possible to select all rows in the table / filtered view.
Is this something that can be added?
Thanks! And thanks for all your work on the project - excited to see how it develops
@pmajmudar Thanks for your suggestion and encouragements :)
Note to future self: If/when we decide to add this feature, it may be interesting to be able to select by column too.
Any update on this ?
Any updates on this?
This looks like an interesting feature. I am also looking at something that checks all the checkboxes on the default page load. I am trying to tweak the 'row_selectable' property and the 'selected_rows' as a workaround but haven't been hitting success really. Is there an update on this?
You can select all the rows by using the parameter selected_rows of datatable. :)
You can select all the rows by using the parameter selected_rows of datatable. :)
@biraj094 Can you explain this in detail please? @chriddyp
You can select all the rows by using the parameter selected_rows of datatable. :)
@biraj094 Can you explain this in detail please? @chriddyp
Hi, appreciate more details on this too. :)
Hi the we did it here was creating a buttom "Select All" and making so the callback would change the property "selected_rows" of the datatable to a list with intergers for each row we would like to select. So it would be something like: @app.callback( [Output(component_id="datatable", component_property="selected_rows")], [Input(component_id="select_all_buttom", component_property="n_clicks")], [State(component_id="datatable", component_property="rows")] ) def select_all(n_clicks, rows): return [i for i, row in enumerate(rows)]
@pandhora That only works if you don't have another part of the dash that's already using selected_rows as output however...
If anyone wants to implement this using existing features:
Works with filters as well.
@app.callback(
inputs=[
Input('select-all-button', 'n_clicks'),
Input('deselect-all-button', 'n_clicks')
],
output=[Output('my-dash-table', 'selected_rows')],
state=[
State('my-dash-table', 'data'),
State('my-dash-table', 'derived_virtual_data'),
State('my-dash-table', 'derived_virtual_selected_rows')
]
)
def selection(select_n_clicks, deselect_n_clicks, original_rows, filtered_rows, selected_rows):
ctx = dash.callback_context.triggered[0]
ctx_caller = ctx['prop_id']
if filtered_rows is not None:
if ctx_caller == 'select-all-button.n_clicks':
selected_ids = [row['id'] for row in filtered_rows]
return [[i for i, row in enumerate(original_rows) if row['id'] in selected_ids]]
if ctx_caller == 'deselect-all-button.n_clicks':
return [[]]
raise PreventUpdate
else:
raise PreventUpdate
Any update on this?
@neilpanchal could you post a fully reproducible example? I'm trying this on my own table and get an o is null error when trying to implement your callback as well as similar other ones. Not sure if this is a nuance with my specific table, or something else.
@wabiloo Actually now there is an extension for Dash which allows multiple callbacks with the same output id. You can check this: https://www.dash-extensions.com/transforms/multiplexer-transform.