Skip to content

Unable to set selection for DataTable with custom action settings #3030

Closed

Description

@riaanbooysen
dash                 2.18.1
dash-core-components 2.0.0
dash-html-components 2.0.0
dash-table           5.0.0

When the DataTable is created with "native" filter_action, sort_action and page_action the selection can be changed
by the selected_rows property, but when these action properties are set to "custom", setting the selected_rows
applies for a very brief moment but is then cleared.

The issue is specifically triggered when selected_rows is combined with sort_by.

Here is a small sample that demonstrates the issue:

import dash
from dash.dependencies import Input, Output, State
from dash import dcc, html
from dash import dash_table as dt

app = dash.Dash(__name__,
                suppress_callback_exceptions=True)

app.layout = html.Div([
    html.Div(dt.DataTable(
        id='datatable',
        columns=[
            {'name': 'a', 'id': 'a'},
            {'name': 'b', 'id': 'b'},
        ],
        data=[
            {'id': 0, 'a': 1, 'b': 4},
            {'id': 1, 'a': 2, 'b': 5},
            {'id': 2, 'a': 3, 'b': 6},
        ],
        editable=True,
        filter_action='native',
        sort_action='native',
        sort_by=[],
        sort_mode='multi',
        row_selectable='multi',
        selected_rows=[0, 1],
        page_action='native',
        page_current= 0,
        page_size= 10,
    ), id='datatable-div'),
    dcc.RadioItems(['Native', 'Custom'], 'Native', id='table-mode', style={'color': 'white'}),
    html.Button('Set Selection', id='set-selection', style={'color': 'white'}),
])

@app.callback(
    [Output('datatable', 'selected_rows'),
     Output('datatable', 'sort_by'),],
    [Input('set-selection', 'n_clicks')],
    [State('datatable', 'sort_by')], 
    prevent_initial_call=True)
def set_selection(clicks, sort_by):
    return [
        [0, 1, 2],
        sort_by,
    ]

@app.callback(
    [Output('datatable', 'filter_action'),
     Output('datatable', 'sort_action'),
     Output('datatable', 'page_action')],
    [Input('table-mode', 'value')], 
    prevent_initial_call=True)
def set_table_mode(value):
    return [value.lower()] * 3

    
if __name__ == '__main__':
    app.run(debug=True)
    

Activity

  1. Francisc0C commented on Mar 9, 2026

    @Francisc0C
    Contributor

    Hi! I’m going to work on fixing this bug. Could I please be assigned to the issue?

  2. added 2 commits that reference this issue on Mar 17, 2026
    1a7edab
    293e854
  3. added 9 commits that reference this issue on Apr 1, 2026
    70a4903
    8b2d9e8
    3818ec1
    26462f1
    286c212
    a2d238a
    519526c
    274b797
    7a23cf8
  4. added a commit that references this issue on Apr 23, 2026
    96969d1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3backlogbugsomething broken

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions