Updating selectedRows in dash-ag-grid 31.0.0

Hello @valsorim,

It looks like the grid made applying the rowData as an asynchronous process vs sync, which means passing the data and selecting a row happens at the same time instead of rowData update → selectedRows implemented.

To make it so that this doesnt happen, you need to use rowTransaction and pass async: False to it, here is an example:

from dash import Dash, html, Output, Input

import dash_ag_grid as dag
import pandas as pd

df = pd.DataFrame(
    dict(
        A=[1, 2, 3],
        B=[3, 4, 5]
    )
)

app = Dash(prevent_initial_callbacks=True)

app.layout = html.Div(
    [
        html.Button(id="btn", children="Select first row"),
        dag.AgGrid(
            id="aggrid",
            dashGridOptions={
                "rowSelection": "single",
                "suppressRowClickSelection": True,
            },
            columnDefs=[
                {
                    "headerName": "A",
                    "field": "A",
                    "showDisabledCheckboxes": True,
                    "checkboxSelection": True,
                },
                {

                    "headerName": "B",
                    "field": "B",
                },
            ],
        )
    ]
)


@app.callback(
    Output("aggrid", "rowTransaction"),
    Output("aggrid", "selectedRows"),
    Input("btn", "n_clicks"),
)
def update_selected_rows(n_clicks):
    return {'add': df.to_dict("records"), 'async': False}, df.head(1).to_dict("records")


if __name__ == "__main__":
    app.run_server(debug=True)

With the above code, you are adding all of the data, to the grid. For your purposes, I dont know if this 100% works for you.

2 Likes