Pivoting
Preview

Configure analytical Rows, Columns, and Values from a flat record set.

Overview

Pivoting turns a flat record set into an analytical summary. Configure the view with three familiar areas:

AreaPurposeConfigure with
RowsGroup records into expandable categories.grouping
ColumnsSplit Values across each distinct dimension value.pivoting.columnDimensions
ValuesAggregate measures such as amount, hours, or count.pivoting.values

Use DataGrid.PivotControl as the standard user-facing control and compose it into your product toolbar. Its compact icon trigger is the default; use compact={false} when the toolbar should show the Pivot label and active field count. Accessor columns are available under Columns by default and under Rows when they also support grouping. Add pivotAggregationFns to a measure column to make it available under Values.

Filters run before the grid groups and aggregates records. Prefer flat data and low-cardinality Columns fields: each distinct Columns value creates a displayed column. The consumer continues to own the records, toolbar, and persistence. See Shared State when another surface needs to control pivot state and Saved Views when users need to save it with the rest of a grid view.

Examples

Rows, Columns, and Values

Declare the aggregations each measure supports, then set the initial Rows, Columns, and Values configuration.

Summary-only views

Turn off Show source rows in the pivot menu, or set pivoting.showSourceRows: false, to show grouped summaries without their contributing records. Groups can still expand into further summary levels; the final summary level has no expansion arrow. Totals and filters are unchanged. This preference is saved with the view, separately from expansion state.

Source rows are shown by default. The setting also works with grouping alone; ungrouped record views remain unchanged.

Sorting and value display

Sort a Rows or Columns dimension by its own values or by an active aggregate. Values can display their result directly or as a percentage of the row, column, or grand total.

pivoting: {
  columnDimensions: ["costCentre"],
  columnDimensionSortBy: {
    costCentre: { columnId: "amount", aggregationFn: "sum" },
  },
  columnDimensionSorting: { costCentre: "desc" },
  rowDimensionSortBy: {
    phase: { columnId: "amount", aggregationFn: "sum" },
  },
  values: [
    {
      columnId: "amount",
      aggregationFn: "sum",
      showAs: "percentOfRowTotal",
    },
  ],
}

Use sortDimensionValues when a dimension needs a domain-specific order that cannot be expressed by its label or an aggregate.

Overall values

Set columnScope: "overall" when a Value should remain one standalone aggregate instead of being split across the active Columns dimensions.

Overall Values always show their raw aggregate because percentage displays require a Columns breakdown.

Row totals

Set showRowTotals to add one total for each Value that is split across Columns.

Column totals

Set showColumnTotals to add filtered aggregate footers for the active Values.

Multi-value dimensions

Use getDimensionValues when one source record belongs to several values of the same dimension. Return a stable key, display label, and typed value for each occurrence.

Use row.getDimensionValue<Membership>(columnId) to access the occurrence and row.getSourceRowId() when an action targets its source record. Totals count each source record once, even when it belongs to several dimension values.

Occurrence filtering

Use defineDataGridFilterDimension when several filter fields must match the same occurrence in a multi-value dimension.

Do not also put dimension filter fields in fieldColumnMap. With server-side filtering, return only matching occurrences when the grouped result must match the client-side view. See Filters for the full filtering API.

API Reference

DataGrid.PivotControl

PropTypeDefaultDescription
compactbooleantrueShows an icon-only trigger. Set to false to show the label and active field count.
tableDataGridTable<TData, TSelected>-Table whose Rows, Columns, and Values configuration the control edits. Required.

Table options

OptionTypeDefaultDescription
enablePivotingbooleantrueEnables pivot configuration for the table.
initialState.pivotingDataGridPivotingStatenullSets the initial Columns, Values, sorting, and totals configuration.
initialState.pivoting.showSourceRowsbooleantrueShows contributing records beneath summaries. Set to false to expand only between summary levels. Saved with the view.
onPivotingChangeOnChangeFn<DataGridPivotingState>State updaterReceives changes when the consumer controls pivot state.

Column options

OptionTypeDefaultDescription
enablePivotingbooleantrueAllows an accessor column to be used as a Rows or Columns dimension.
pivotAggregationFnsreadonly DataGridPivotAggregation[]-Makes a measure available under Values with the listed aggregations.
getDimensionValues(record, index) => readonly DataGridDimensionValue[]-Returns the occurrences for a multi-value dimension.
filterDimensionValue(dimensionValue, filterValue) => boolean-Tests one occurrence against the column filter value.
sortDimensionValues(left, right) => numberLabel, then keySets the order of generated dimension values.

Pivot types

ExportTypeDefaultDescription
DataGridPivotingState{ columnDimensions, columnDimensionSortBy?, columnDimensionSorting?, rowDimensionSortBy?, values, showColumnTotals?, showRowTotals?, showSourceRows? } | nullnullComplete serializable pivot configuration.
DataGridPivotValue{ columnId, aggregationFn, columnScope?, showAs? }-One active Value and how it is displayed. Overall Values do not accept showAs.
DataGridPivotSortBy{ columnId, aggregationFn }-Active aggregate used to order a Rows or Columns dimension.
DataGridPivotAggregation"count" | "extent" | "first" | "last" | "max" | "mean" | "median" | "min" | "sum" | "unique" | "uniqueCount"-Aggregation accepted by pivotAggregationFns.
DataGridPivotValueColumnScope"columnDimensions" | "overall""columnDimensions"Whether a Value is split across Columns or displayed once overall.
DataGridPivotValueDisplay"value" | "percentOfRowTotal" | "percentOfColumnTotal" | "percentOfGrandTotal""value"Calculation used to display a Value.
DataGridDimensionValue<TValue>{ key, label, value }-One occurrence returned by a multi-value dimension.

Instance methods

APISignatureDescription
table.getIsPivoting() => booleanReturns whether pivot Values are active.
table.getPivotColumnDimensions() => string[]Returns the current Columns field IDs.
table.getPivotValues() => DataGridPivotValue[]Returns the active Values.
table.setPivoting(updater) => voidUpdates the complete pivot configuration.
table.setPivotColumnDimensions(updater) => voidUpdates Columns without replacing Values.
table.setPivotValues(updater) => voidUpdates Values without replacing Columns.
table.resetPivoting(defaultState?) => voidRestores the initial or empty pivot configuration.
column.getCanPivotAsDimension() => booleanReturns whether the column can be used in Rows or Columns.
column.getCanPivotAsValue() => booleanReturns whether the column can be used under Values.
column.getIsPivotColumnDimension() => booleanReturns whether the column is active under Columns.
column.getIsPivotValue() => booleanReturns whether the column is an active Value.
row.getDimensionValue(columnId) => DataGridDimensionValue<TValue> | undefinedReturns the typed occurrence for a multi-value dimension row.
row.getSourceRowId() => string | undefinedReturns the source record ID for a leaf or occurrence row. Group and total rows return undefined.

On this page