dash-table icon indicating copy to clipboard operation
dash-table copied to clipboard

Select all rows

Open pmajmudar opened this issue 6 years ago • 13 comments

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 avatar Nov 20 '18 19:11 pmajmudar

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

Marc-Andre-Rivet avatar Nov 20 '18 19:11 Marc-Andre-Rivet

Any update on this ?

smeet20 avatar Jun 17 '19 10:06 smeet20

Any updates on this?

chirayu11 avatar Aug 12 '19 14:08 chirayu11

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?

manakulkarni avatar Oct 03 '19 00:10 manakulkarni

You can select all the rows by using the parameter selected_rows of datatable. :)

biraj094 avatar Nov 23 '19 16:11 biraj094

You can select all the rows by using the parameter selected_rows of datatable. :)

@biraj094 Can you explain this in detail please? @chriddyp

KavyaSrini96 avatar Apr 23 '20 15:04 KavyaSrini96

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

shieldofchaos avatar May 19 '20 07:05 shieldofchaos

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 avatar May 28 '20 13:05 pandhora

@pandhora That only works if you don't have another part of the dash that's already using selected_rows as output however...

wabiloo avatar Jun 10 '20 00:06 wabiloo

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

neilpanchal avatar Sep 16 '20 02:09 neilpanchal

Any update on this?

ghost avatar Mar 10 '21 09:03 ghost

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

jwhendy avatar Feb 07 '22 18:02 jwhendy

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

giofogalli avatar Jul 11 '22 13:07 giofogalli