Pivot Tables: Matrix Aggregation in Your Data Grid

Build matrix pivot tables with Simple Table: row fields stay on the left, column fields become dynamic headers, and values are aggregated into each cell. Works in React, Vue, Angular, Svelte, Solid, and vanilla TypeScript. Configure with a pivot prop or TableAPI.setPivot—a practical AG Grid Enterprise pivot alternative for declarative analytics. An interactive drag-and-drop Pivot Panel is coming for Enterprise; until then, drive dimensions from your own UI or presets.

Try the presets below to see nested rows, multiple measures, and value-only layouts. For a step-by-step React walkthrough, see the React pivot table tutorial.

192 fact rows · Active: rows: ["region"] columns: ["quarter"]

Basic pivot table usage

Pass flat rows and a field catalog in defaultHeaders. Headers supply labels, types, widths, and formatters for source fields. When pivot is active, the grid does not show that catalog as columns — it shows generated row-dimension columns plus dynamic value columns.

<SimpleTable
  defaultHeaders={headers} // field catalog
  rows={flatRows}
  pivot={{
    rows: ["region"],
    columns: ["quarter"],
    values: [{ accessor: "sales", aggregation: { type: "sum" } }],
  }}
/>

Props

Pivot props

PropertyRequiredDescriptionExample
pivot
PivotConfig | null
Optional
Declarative matrix pivot. When set, flat source rows are reshaped into a matrix with dynamic columns. Pass null to disable. While active, consumer rowGrouping is ignored.
onPivotChange
(pivot: PivotConfig | null) => void
Optional
Fired when pivot config changes through TableAPI.setPivot (not on every prop sync from your app).

PivotConfig

PivotConfig

PropertyRequiredDescriptionExample
PivotConfig.rows
Accessor[]
Required
Row dimension accessors (0+). One field → flat rows. Multiple fields → expandable tree (region → product).
PivotConfig.columns
Accessor[]
Required
Column dimension accessors (0+). Distinct values become dynamic headers. Empty array → value columns only (group + aggregate, no matrix).
PivotConfig.values
PivotValueConfig[]
Required
Measures to aggregate (at least one). Uses AggregationConfig: sum, average, count, min, max, or custom. Optional label overrides the header text.
PivotConfig.showRowTotals
boolean
Optional
When true (default), adds a Total column that aggregates across column dimensions. Only applies when columns is non-empty.
PivotConfig.showColumnTotals
boolean
Optional
When true (default), appends a Total row that aggregates across row dimensions.
PivotConfig.showGrandTotal
boolean
Optional
When true (default), fills the intersection of row totals and the column-totals row (grand total cells).

TableAPI

Pivot TableAPI methods

PropertyRequiredDescriptionExample
setPivot(config)
(config: PivotConfig | null) => void
Optional
Enable, update, or clear pivot at runtime. Pass null to return to the source grid.
getPivot()
() => PivotConfig | null
Optional
Returns the active pivot config, or null when pivot is off.
getPivotHeaders()
() => HeaderObject[]
Optional
Generated headers while pivot is active; otherwise the current headers.
getPivotedRows()
() => Row[]
Optional
Post-pivot rows (before flatten/expand). Source rows when pivot is off.

Pivot behavior notes

  • Filters run on source rows (before pivot). Row-dimension columns keep their source accessors, so filtering by region still works. Generated measure columns are not filterable.
  • Sort and quick filter apply to the pivoted view.
  • rowGrouping from the consumer is ignored while pivot is on. Multi-level pivot.rows builds its own expand/collapse tree instead.
  • CSV export exports the pivoted matrix (visible headers and rows), not the original fact table.
  • Pivoted measure cells are not meant for editing — they are aggregated summaries.
  • High column cardinality (many distinct column-field values) creates many leaf columns. Keep that in mind for performance and horizontal scrolling.

Related