The problem is still there as of July 2021 with dash-table==4.12.0 and dash==1.21.0
Here is a simple code for reproducing the problem
import dash
import dash_html_components as html
import dash_table
import pandas as pd
from dash.dependencies import Output, Input, State
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/solar.csv')
df['id'] = pd.Series(range(len(df)))
app = dash.Dash(__name__)
app.layout = html.Div([
html.Button('select_all', id='btn_select_all'),
html.Button('print_selected_indices', id='btn_print'),
html.Div(id='output'),
dash_table.DataTable(
id='table',
columns=[{"name": i, "id": i} for i in df.columns],
data=df.to_dict('records'),
row_selectable='multi',
),
])
@app.callback(
Output('table', 'selected_rows'),
Input('btn_select_all', 'n_clicks'),
prevent_initial_call=True
)
def select_all(n_clicks):
return list(range(len(df)))
@app.callback(
Output('output', 'children'),
Input('btn_print', 'n_clicks'),
State('table', 'selected_row_ids'),
State('table', 'selected_rows'),
prevent_initial_call=True
)
def print_selected_indices(n_clicks, selected_row_ids, selected_rows):
return f'selected_row_ids={selected_row_ids}, selected_rows={selected_rows}'
if __name__ == '__main__':
app.run_server(debug=True)
Run the program, click the ‘select all’ button first and then click the ‘print_selected_indices’. You will see the selected_row_ids remain while selected_rows is correct.