Quick start (React)
Define your data, describe the fields, and render BasePivotGrid.
import { BasePivotGrid, type PivotField } from '@kanunilabs/pivotgrid-react';
import '@kanunilabs/pivotgrid-react/styles.css';
const data = [
{ region: 'EMEA', quarter: 'Q1', revenue: 1200 },
{ region: 'EMEA', quarter: 'Q2', revenue: 980 },
{ region: 'APAC', quarter: 'Q1', revenue: 1500 },
];
const fields: PivotField<(typeof data)[number]>[] = [
{ id: 'region', dataField: 'region', caption: 'Region', dataType: 'string', area: 'row' },
{ id: 'quarter', dataField: 'quarter', caption: 'Quarter', dataType: 'string', area: 'column' },
{ id: 'revenue', dataField: 'revenue', caption: 'Revenue', dataType: 'number', area: 'data', summaryType: 'sum' },
];
export function MyGrid() {
return <BasePivotGrid gridId="demo" data={data} initialFields={fields} />;
}
The grid fills the element you put it in. Give that element a height (say
500px, or a flex slot) to get a fixed-size grid that scrolls inside; without
one, the grid is as tall as its content. It never draws outside its container.
Fields
Each field declares where it lives (area: 'row' | 'column' | 'data' | 'filter'),
its dataType, and — for measures — a summaryType (sum, count, avg, min,
max). Numbers accept an Intl format:
{
id: 'revenue',
dataField: 'revenue',
caption: 'Revenue',
dataType: 'number',
area: 'data',
summaryType: 'sum',
format: { style: 'currency', currency: 'USD', maximumFractionDigits: 0 },
}
Localization
Pass a locale (one of 12) and the grid translates its chrome; ar switches to RTL.
<BasePivotGrid gridId="demo" data={data} initialFields={fields} locale="tr" />
Tabs and <Activity>
A pivot inside React's <Activity mode="hidden"> (a tab kept alive in the background) is suspended, not
disposed. While hidden it lets go of its engine worker and keeps everything else: the rows, the layout, the open
branches, the last result, queued transactions and your event listeners. When it is shown again and nothing changed,
the last result is shown at once and nothing is recomputed; the engine starts again with the first change that needs
it. A change made while it was hidden is computed with the last result on screen, without the loading overlay.
-
Hold the controller, not the ref. React sets
ref.currenttonullwhile the grid is hidden, so a feed that runs in the background must keep the controller fromonReady(called once per controller) or fromref.current.getController():const controller = useRef<PivotController<Row> | null>(null); <BasePivotGrid gridId="sales-tab-1" data={rows} initialFields={fields} onReady={(c) => { controller.current = c; }} /> // later, even while the tab is hidden: controller.current?.applyTransactionAsync({ add: batch }); -
Changes while hidden are computed on show.
applyTransactionAsync,flushAsyncTransactions,setDataor a newdataprop,setExpandedPaths: none is lost. MeanwhilegetState().isComputingistrue— a hidden grid never reports a partial result as done. -
Exports reject while hidden with an
AbortError(nothing computes until the grid is shown). -
Unmount. When React removes the grid from the page, its controller is disposed, as before. A controller you still hold then does nothing and logs a warning once. A grid unmounted while it was hidden is disposed after two missed checks (about 10 s).
-
A tab host that takes hidden panels out of the page (not React's
<Activity>) looks like an unmount: the controller is disposed, and when the panel comes back the grid starts again with its layout but without rows added through the API. -
One gridId per tab. Give each live pivot its own
gridId: saved reports and the stored layout are kept per gridId. Two live grids never share an engine worker either way. -
Popups and the field chooser hide with the grid.
The controller methods behind this are suspend(), resume(), isSuspended(), isDisposed() and
getEngineKey() (the id the header-filter lists are kept under). The React component calls them for you.
Using Next.js? See Next.js setup for the one extra step the bundler needs.
For the complete prop and type list, see the API Reference.