aggFunc
With row grouping: what a group shows in this column.
| Type | AggFuncName | AggFn<V> |
|---|---|
| Default | not set |
Live update (update()) | Yes — give the columns again (update({ columns })) |
| Declared in | packages/core/src/columns/defs.ts |
What it does
Section titled “What it does”A built-in name — 'sum', 'avg', 'min', 'max', 'count', 'first', 'last' — or your function
of the group’s values. count counts the group’s rows; the others skip empty values. A function is told the values in
the group’s order (empty ones as null) and { column, level } (level null for the grand total); what it returns is
shown. It must be pure.
It needs the grouping() feature. The grouping’s own aggFuncs option wins over it. For the totals row of a flat
grid, see total.
Example
Section titled “Example”import { createGrid, type GridMessages } from '@dzgrid/dom';import { grouping } from '@dzgrid/dom/grouping';import { EN_GROUP } from '@dzgrid/dom/locales/en-group';import { EN } from '@dzgrid/dom/locales/en';
type Sale = { id: string; market: string; fruit: string; crates: number };
const messages: GridMessages = { ...EN, text: { ...EN.text, ...EN_GROUP.text } };
createGrid<Sale>(document.getElementById('sales')!, { rows: [{ id: 's1', market: 'Harbour', fruit: 'Plums', crates: 12 }], columns: [ { id: 'market', header: 'Market' }, { id: 'fruit', header: 'Fruit', aggFunc: 'count' }, { id: 'crates', header: 'Crates', type: 'number', aggFunc: 'sum' }, ], getRowId: (r) => r.id, messages, features: [grouping({ by: ['market'] })],});