rowData not updating after I use callback to update it

Hi team,
@jinnyzor

I am using AG Grid Plotly enterprise version where I am utilising the treeData component.
i am facing this issue where I am trying to update the rowData through callback but when the callback is triggered it goes in pending state and the page is loading/stuck.
The callback is not updating my aggrid and goes to a pending state making the page stuck.
I used an alternative way of rowTransaction which also didnt apply to my case and did not give me any result. Below is the callback:

from dash import no_update
import pandas as pd
from dash.dependencies import Input, Output, State

def calc_shouldcost_callback(app):
    @app.callback(
        Output("cost-table", "rowData", allow_duplicate=True),
        [Input("cost-table", "cellValueChanged")],
        State("cost-table", "rowData"),
        prevent_initial_call=True
    )
    def calc_shouldcost(updated_row_data, current_row_data):
        if updated_row_data and (updated_row_data[0]["colId"] == "cost" or updated_row_data[0]["colId"] == "quantity2"):
            df = pd.DataFrame(current_row_data)
            row = updated_row_data[0]
            rowIndex = row["rowIndex"]
            rowdata = row["data"]
            na = ["Not available", "None", "-", "Not Available", "N/A", "n/a", "none", ""]
            
            if rowdata["cost"] in na or rowdata["quantity"] in na:
                return no_update
            else:
                prevTotal = df.at[rowIndex, "total"]
                df.at[rowIndex, "total"] = round(float(rowdata["cost"]) * float(rowdata["quantity"]), 3)
                diff = prevTotal - df.at[rowIndex, "total"]
                parent_list = rowdata["name"][:-1]
                while isinstance(rowdata["name"], list) and len(parent_list) > 0:
                    parent_row = df.loc[df.apply(lambda row: parent_list == row["name"] and row["type"] in ["Type1", "type1", "type 1"], axis=1)]
                    if not parent_row.empty:
                        parent_row_index = parent_row.index[0]
                        df.at[parent_row_index, "total"] = round(float(df.at[parent_row_index, "total"]) - diff, 3)
                        parent_list = parent_list[:-1]
            return df.to_dict("records")
                
        return no_update

Hello @rachanaa,

It’s really hard to say what is happening without seeing the rest of the app.

I noticed that you are allowing duplicates. Is there a chance that it is entering a circle of updates?

1 Like