plotly / dash-ag-grid

Dash AG Grid is a high-performance and highly customizable component that wraps AG Grid, designed for creating rich datagrids.
https://dash.plotly.com/dash-ag-grid
MIT License
175 stars 25 forks source link

rowData does not change upon managed row dragging #255

Closed yreiss closed 11 months ago

yreiss commented 11 months ago

When creating a table allowing row dragging, I expected the row data to change upon re-ordering (or have any other indication of the new row order).

Running the code below, I expected the row_changed() callback to be called upon any change in row order but it doesn't get called.

Also, using other callbacks that are being called I inspected the state of the rowData and it indeed it never changes (does not appear in the code).

Could you please provide a way for the application to retrieve the new order of rows?

from dash import Dash, html, Output, Input
import dash_ag_grid as dag

app = Dash(__name__)

columnDefs = [
    { 'field': 'Id' },
    { 'field': 'Value' },
]

data = [{"Id": 1, "Value": 1}, {"Id": 2, "Value": 2}]

grid = dag.AgGrid(
    id="draggable",
    rowData=data,
    columnDefs=columnDefs,
    defaultColDef={"rowDrag": True},
    dashGridOptions={"rowDragManaged": True}
)

app.layout = html.Div([grid])

app.run()

@app.callback(
    Output("draggable", "rowData"),
    Input("draggable", "rowData")
)
def rows_changed(data: list) -> list:
    print("got here")
    return data
BSd3v commented 11 months ago

Hello @yreiss,

The adjusted rows will be reflected in virtualRowData, rowData is just data in the original order.

yreiss commented 11 months ago

Hi @BSd3v Awesome! I'll close the issue.