Dash Ag Grid's rowData Property does not include fields generated with valueGetters?

I have a functional dash app with a dash_ag_grid on it.
On the latest request for change, I’ve been asked to include some editable fields. From the inputs on those editable fields, there are some additional columns calculated using valueGetters, example:

`

 {'headerName': 'Quarter 2',
             'children': [
                 {'headerName': 'Budget','field': 'budget'},
                 {'headerName': 'Sales','field': 'sales'},
                 {
                     'headerName': 'performance',
                     'field':'performance',
                     'valueGetter':{"function": "Number(params.data.budget) === 0 ? 1 : 1- 
                                 (Number(params.data.sales) / Number(params.data.budget))"},
                 }

Everything is working properly, the grid itself displays proper values, and calculations are accurate.
The issue is when I try and catch the grid’s data on a callback using

State('dash-ag-grid','rowData')
or
Input('dash-ag-grid','rowData')

The field performance does not exist at all - even if I attempt to reference it directly, it will trigger a "KeyError: 'performance'" error.

Hello @GONZJ243,

Welcome to the community!

It’s because the data doesnt exist in the rowData.

You can replicate the function on the callback side that you are utilizing in the grid and set it as the performance column in your df.

Another thing to point out, but you shouldnt use the input from rowData as often time this is mutated in place by the grid. Using the cellValueChanged as a trigger and pulling in the state is a better way. :slight_smile:

Hope this helps.

:upside_down_face:

Is there any other option?
Would having a placeholder column for the field on the initial dataframe help?
The example I gave was pretty basic, but the real cases are complex nested calculations, so I wouldn’t want to replicate the calculations on the callback.

As for your second point, I agree - I’m actually not using the rowData as the trigger, but a button confirmation.

Yes, you could take the data and have it placed into another column.

You can use the valueSetter and update the data accordingly.

1 Like

@GONZJ243

See example #2 here:

1 Like