Aggregation

Calculate summary values for grouped rows. Aggregation functions run on each group's leaf rows.

Built-in Aggregation Functions

NameDescription
sumSum of numeric values
minMinimum numeric value
maxMaximum numeric value
extent[min, max] tuple
meanAverage of numeric values
medianMedian of numeric values
uniqueArray of unique values
uniqueCountCount of unique values
countNumber of rows

How to Use

columnHelper.accessor('salary', {
  header: 'Salary',
  aggregationFn: 'sum',
  aggregatedCell: ({ getValue }) => `Total: $${getValue().toLocaleString()}`,
})

Custom Aggregation

columnHelper.accessor('salary', {
  header: 'Salary',
  aggregationFn: (columnId, leafRows, childRows) => {
    const values = leafRows.map((row) => row.getValue<number>(columnId))
    return values.reduce((sum, val) => sum + val, 0) / values.length
  },
  aggregatedCell: ({ getValue }) => `Avg: $${getValue().toLocaleString()}`,
})