diff --git a/webapp/src/components/common/MatrixGrid/useMatrix.ts b/webapp/src/components/common/MatrixGrid/useMatrix.ts index 33cdda1c7f..104dd6551b 100644 --- a/webapp/src/components/common/MatrixGrid/useMatrix.ts +++ b/webapp/src/components/common/MatrixGrid/useMatrix.ts @@ -212,16 +212,27 @@ export function useMatrix( (update): update is NonNullable => update !== null, ); + // Recalculate aggregates with the updated data + const newAggregates = enableAggregateColumns + ? calculateMatrixAggregates(updatedData) + : { min: [], max: [], avg: [], total: [] }; + setState({ data: updatedData, - aggregates: currentState.aggregates, + aggregates: newAggregates, pendingUpdates: [...currentState.pendingUpdates, ...newUpdates], updateCount: currentState.updateCount ? currentState.updateCount + 1 : 1, }); }, - [currentState, setState], + [ + currentState.data, + currentState.pendingUpdates, + currentState.updateCount, + enableAggregateColumns, + setState, + ], ); const handleCellEdit = function (update: GridUpdate) {