TanStackT
TanStack3y ago
1 reply
ordinary-sapphire

Calculate aggregated cell value based on parent row and child rows

Good day everyone, i have a problem to migrate my aggregation function from v7 column definition to v8 column definition.

My main problem is, that if the aggregationFn runs I need to know about my position (row) to decide if it makes sens to calculate a cell value or return a default value. In addition, if I decide to calculate the cell value, I need to get values from my direct parent row.

Example:
colA | colB | colC | quantity | percent_colB

If it was grouped by this cols in this order:
colA,colB,colC

and i would expand a row at the colA level and a sub row at colB level, I want percent_colB to look like this:
- colA level row: default value ("")
- colB level row: default value ("")
- colC level row: sum(leafRow.quantity)/parentRow.quantity

Column Definition:
...{
  header: "percent_colB",
  id: "percent_colB"
  aggregationFn: (columnid, leafRows, childRows) => percentAgg(columnid, leafRows, childRows)
},...
Was this page helpful?