Data display
PivotTable
Multi-dimensional pivot grid with expandable row groups, aggregations, and grand totals.
import '@reactloom/data-grid/styles.css';
import { PivotTable } from '@reactloom/data-grid';Examples
Sales by region, product, and quarter
| Region / Product | Q1 · Revenue | Q2 · Revenue | Total · Revenue |
|---|---|---|---|
| $7,300 | $4,800 | $12,100 | |
| Services | $3,100 | — | $3,100 |
| Widgets | $4,200 | $4,800 | $9,000 |
| $2,900 | $3,600 | $6,500 | |
| Services | — | $3,600 | $3,600 |
| Widgets | $2,900 | — | $2,900 |
| Grand total | $10,200 | $8,400 | $18,600 |
import { PivotTable } from '@reactloom/data-grid';
const sales = [
{ region: 'North', product: 'Widgets', quarter: 'Q1', revenue: 4200 },
{ region: 'North', product: 'Services', quarter: 'Q1', revenue: 3100 },
{ region: 'North', product: 'Widgets', quarter: 'Q2', revenue: 4800 },
{ region: 'South', product: 'Widgets', quarter: 'Q1', revenue: 2900 },
{ region: 'South', product: 'Services', quarter: 'Q2', revenue: 3600 },
];
export default function Example() {
return (
<PivotTable
data={sales}
rows={['region', 'product']}
columns={['quarter']}
values={[{ key: 'revenue', label: 'Revenue', agg: 'sum', format: (n) => `$${n.toLocaleString()}` }]}
labels={{ region: 'Region', product: 'Product' }}
/>
);
}API reference
| Prop | Type | Default |
|---|---|---|
datarequiredSource records. | readonly Row[] | — |
rowsrequiredOrdered row grouping dimensions. | readonly string[] | — |
columnsOptional column pivot dimensions. | readonly string[] | — |
valuesrequiredAggregated value fields (sum, avg, count, min, max). | readonly PivotValueField[] | — |
showGrandTotalsShow row and grand total summaries. | boolean | true |
Keyboard interaction
| Key | Action |
|---|---|
| Enter / Space | Expand or collapse a row group |
Usage guidelines
Do
- Provide human-readable field labels and value formatters for currency or percentages.
Don’t
- Avoid pivoting high-cardinality IDs as column dimensions.