plotly / plotly/dash

Datatable with backend filtering loses selected row when another table is added in div

Aperta
#2,101 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug dash-data-table P3
Lingua principale
Python
Stelle
24.4k
Fork
2.3k
Merge medio
2g 7h
PR unite (30g)
13

Descrizione

Describe your context
I am using the datatable as described in Backend Paging with Filtering and Multi-Column Sorting

I have taken that code one step further by adding a dynamic amount of them inside a div.

dash                      2.5.1
dash-bootstrap-components 1.1.0
dash-core-components      2.0.0
dash-extensions           0.1.3
dash-html-components      2.0.0
dash-table                5.0.0

Describe the bug

When adding another datatable in the div, the selected rows in the other datatables get deselected. I think this has something to do with sort_by since if I comment it from the datatable creation the problem disappears.

Expected behavior

I expect that the selected rows should not be removed as I add more datatables

Example Code to reproduce bug

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)

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Esegui la riproduzione Dash fornita e aggiungi datatables con righe selezionate, usando la configurazione sort_by e dynamic children mostrata. Analizza in che modo l’aggiunta di una tabella influisce sullo stato di selezione esistente di DataTable quando sort_by è presente. Il lavoro è completato quando le righe precedentemente selezionate rimangono selezionate dopo l’aggiunta di un’altra tabella, mentre la riproduzione continua a supportare il filtraggio e l’ordinamento lato backend.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
frontend
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.