I would like to include in my grid an extra column to reflect the up to date sum of two other columns:
const columnDef = [
{headerName: 'x', field: 'x', type: 'numericColumn'},
{headerName: 'y', field: 'y', type: 'numericColumn'},
{headerName: 'z', function: (data) => data.x+data.y}
];
How can I do that?
2
Answers
Afaik you cannot set the value directly in the useState of your values. But you can edit the values in the useEffect after loading and insert the values you need. I set the total value to 0 by default. In the useEffect I update the values of the total field. Here is a modified example from the ag-gird documentation (https://www.ag-grid.com/react-data-grid/getting-started/)
Let me know if that helps.
All you need is a simple valueGetter to add the 2 values of your x and y fields.
Change your
columnDefs
to:Demo.