I have an app where I am letting a user edit some data and then insert it into a DB. I would like to capture the changed cell as well as the calculated column that also gets changed (Total in the example below.) Is there any easy way to do this?
import plotly.express as px
from dash import Dash, Input, Output, callback, dcc, html
app = Dash(
__name__,
suppress_callback_exceptions=True,
)
df = px.data.medals_wide()
columnDefs = [
{
"field": i,
}
for i in df.columns
]
total_medals = {
"headerName": "Total",
"colID": "medals_total",
"valueGetter": {
"function": "params.getValue('gold') + params.getValue('silver') + params.getValue('bronze');"
},
}
columnDefs.insert(4, total_medals)
app.layout = html.Div(
[
dcc.Markdown("This grid has string editing enabled on all columns"),
dag.AgGrid(
id="basic-editing-example",
columnDefs=columnDefs,
rowData=df.to_dict("records"),
columnSize="sizeToFit",
defaultColDef={"editable": True},
dashGridOptions={"animateRows": False},
),
html.Div(id="edited-cell"),
]
)
@callback(
Output("edited-cell", "children"),
Input("basic-editing-example", "cellValueChanged"),
)
def cellChange(cell):
return f"{cell}"
if __name__ == "__main__":
app.run_server(debug=True, port=8080)