Hi,
I have a ag-grid table and am trying to make a callback from the selected cell. I would like to return the information to another ag-grid, but with the colId and rowId information as the selection criteria.
this is the app definition. The problem that I encounter is that the “rowId” is the row number (same as rowIndex) and not the actual information. The cell value in the callback is “{‘value’: -13827.24, ‘colId’: ‘2025-07’, ‘rowIndex’: 3, ‘rowId’: ‘3’, ‘timestamp’: 1778238807624}”
app.layout = html.Div(
[
dag.AgGrid(
id="getting-started-themes-example",
columnDefs=[{"field": "Category", "type": "text"}] +
[
{
"field": x,
"type": "rightAligned",
"width": 80,
"maxWidth": 100,
"valueFormatter": {"function": "d3.format(',.0f')(params.value)",}
} for x in df.columns if x != "Category"
] ,
rowData=df.to_dict('records'),
dashGridOptions={"theme": "themeMaterial"},
columnSize="autoSize",
style={"height": 800, "width": "75%"},
),
dag.AgGrid(
id="details-grid",
rowData=df.to_dict('records'),
dashGridOptions={"theme": "themeMaterial"},
columnSize="autoSize",
style={"height": 800, "width": "75%"},
),
]
)
@callback(
Output("details-grid", "rowData"),
Input("getting-started-themes-example", "cellClicked"),
)
def cell_details(cell):
print(cell)
if cell and cell.get("colDef", {}).get("field") != "Category":
category = cell["colId"]
month = cell["rowId"]
filtered_df = details_df[(details_df["Category"] == category) & (details_df["Year_Month"] == month)]
return filtered_df.to_dict('records')
return df.to_dict('records')
I have defined the dataframe as
df = total_df_clean.pivot_table(
index="Category",
columns="Year_Month",
values="Beløb",
aggfunc="sum",
fill_value=0
)
# Clean up column index name
df.columns.name = None
df = df.reset_index()
Any ideas what should be changed in order to get the actual Category e.g. to show “Food” in the callback rowId?
