Skip to main content

DataMatrix

DataMatrix pivots a flat list of records into a cross-tab: one field becomes the rows, another becomes the columns, and each cell aggregates the matching records by count or sum. Row, column, and grand totals are shown by default.

When to use

  • Summarize records across two dimensions (e.g. Status × Region, Category × Month).
  • Quick pivot/aggregation without a full BI tool.

Import

import { DataMatrix, AggregationType } from '@spartanfx/react';

Count example

Cross-tabulate items by xField (rows) and yField (columns), counting matches.

<DataMatrix
items={records}
xField="status"
yField="region"
aggregationType={AggregationType.count}
/>

Sum example

To sum a numeric field, set the aggregation type and point aggregationField at it.

<DataMatrix
items={sales}
xField="product"
yField="quarter"
aggregationType={AggregationType.sum}
aggregationField="amount"
xFieldLabel="Product"
yFieldLabel="Quarter"
/>

Key props

PropTypeNotes
items (required)Record<string, unknown>[]Records to pivot.
xField (required)stringField for row headers.
yField (required)stringField for column headers.
aggregationType (required)AggregationTypeCount or Sum.
aggregationFieldstringNumeric field to sum (ignored for count).
showTotalsbooleanRow/column/grand totals (default true).
xFieldLabel / yFieldLabelstringAxis display labels.
blankLabelstringLabel for blank values (default (Blank)).

See the full generated reference: DataMatrix API ↗.

See also