When creating a dynamic amount of datatables with sort_by=[]
the selected rows in the other datatables get deselected.
Example code to see the issue.
import pandas as pd
from dash import Dash, Input, Output, State, dash_table, html
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/solar.csv")
app = Dash(__name__)
app.layout = html.Div(
children=[
html.Div(
children=[],
id="list-of-datatables",
),
html.Button("Add Datatable", id="add-datatable", n_clicks=0),
]
)
@app.callback(
Output("list-of-datatables", "children"),
State("list-of-datatables", "children"),
Input("add-datatable", "n_clicks"),
prevent_initial_call=True,
)
def add_datatable(children, n_clicks):
children.append(
dash_table.DataTable(
id={"type": "datatable", "index": len(children)},
columns=[{"name": i, "id": i} for i in df.columns],
data=df.to_dict("records"),
row_selectable="multi",
page_current=0,
page_size=10,
page_action="custom",
filter_action="custom",
filter_query="",
sort_action="custom",
sort_mode="multi",
sort_by=[], # Comment this line and the bug will be fixed
)
)
return children
if __name__ == "__main__":
app.run_server(debug=True)
Is this intended or is it a bug?