Documentation

Large data: columnar rows

By default the PivotGrid reads your rows as objects. Its own share is small: it keeps a reference to your array, and its Web Worker holds only the fields that are placed. But the row objects themselves cost what they cost. With fifty columns that is often 1.5–3 KB per row, so at 1.5 million rows the objects alone come close to a browser tab's limit.

With columnar the grid keeps the rows as typed columns instead. Text is stored once per distinct value, and numbers and dates sit in typed arrays. That comes to about 350–450 bytes per row, which puts 1–2 million rows in reach. Everything works as before: field moves, filters, sorting, row-level calculated fields, custom summaries, drill-down and selection records, exports and saved layouts. Rows are built only when something reads them. Enterprise.

import { EnterprisePivotGrid } from '@kanunilabs/pivotgrid-react-enterprise';

const ref = useRef<PivotGridRef>(null);

<EnterprisePivotGrid ref={ref} licenseKey={key} columnar loading={loading} initialFields={fields} />;

// As the report streams in: column names plus one value array per row. No row object is built.
ref.current!.applyTransactionAsync({ add: { columns: ['Barkod', 'StokKod', 'Adet'], rows: [['869…', 'S12', 4], …] } });
// When the stream ends:
ref.current!.flushAsyncTransactions();
setLoading(false);

In JavaScript, pass columnar: true to createEnterprisePivotGrid.

Giving it rows

  • Chunks: { columns, rows } as data, setData(chunk) or applyTransaction(Async)({ add: chunk }). Each chunk may name its own columns. A row array shorter than columns leaves the rest of that row empty, as a missing key would.
  • Objects: row objects are accepted too. The grid reads each object's own keys plus the dataField of every field you declared, so values behind getters are read as well. The objects are not kept.
  • data follows the usual rule: a new data value replaces the rows, a new empty array (or empty chunk) clears them, and the same value again changes nothing. A chunk counts as the same while its rows and columns arrays are, so data={{ columns, rows }} written inline is fine. Keep data itself stable when you add rows through the ref: leave it out (or use one empty array in state or at module level). A new [] on every render clears the streamed rows on every render, and the grid warns about that once. For a refresh, set data to a new empty array (or give the new rows to setData) and stream again: a new data drops all earlier rows and every add still queued, so the new report is never added to the old one. setData([]) and setData({ columns, rows: [] }) empty the grid.
  • The grid reads the input when it first needs it, not when you pass it. Do not change the array after passing it.
  • Large inputs belong in chunks. A big data or setData input is read in one go, and the grid logs a notice when it is more than 100,000 rows.
  • columnar is read when the grid is created. Changing it later does nothing.

What is different

  • update and remove are not supported yet in this mode and throw an error. Add rows with add, or give the new rows to setData. rowKey is not needed.
  • A row-level calculateExpression gets one read-only row object for every row of a pass. Read values from it and return a result. Do not keep it, and do not write onto it: the object is frozen, so in strict code a write throws an error instead of returning a stale value.
  • getRawData() returns a read-only list. Each element is a plain row built when you read it, so rows[i] !== rows[i]. It cannot be sorted in place or sent with postMessage; copy it first with slice().
  • The records of a cell (cellClick.records, getCellRecords, getRecordsForSelection()) are plain rows. Up to 50,000 rows they come as an ordinary array. Above that they come as the same kind of read-only list, and a notice points you to the row sources below. Building a plain row costs a few microseconds and about 1 KB for fifty columns.
  • A custom export function gets plain rows. Use them before it returns.
  • The reused row of rowAt, forEachRow and a calculated field is valid only until the grid reads another row, which can be the engine or another source: read its values at once. In it every column is present ('x' in row is true even where the value is missing).
  • Row sources and row handles keep the rows they were cut from alive, even after setData or dispose(). Let the panel's rows go when isStale() turns true or a new report starts.
  • A grid rebuilt by React (a new gridId, or a new controller after its element left the page) starts without rows; onReady tells you. Stream the report again.
  • With a serverSource, columnar is ignored (the rows are on the server).
  • A { columns, rows } chunk given to a grid without columnar throws, and so does an add that is neither an array of rows nor a chunk.
  • In a materialised row, keys come in column order, and a Date value is an equal new Date.

Reading rows page by page

Row sources read the rows without building them. The API is the same with or without columnar, so one code path serves both:

import { cellRowSource, rowStoreOf, selectionRowSource } from '@kanunilabs/pivotgrid-react-enterprise';

const source = ref.current!.getSelectionRowSource(); // or cellRowSource(controller, rowPath, colPath), rowStoreOf(controller)
source.rowCount;
source.getRows(0, 50);            // plain rows to keep
source.forEachRow((row) => { … }); // one reused read-only row: read values, keep nothing
source.isStale();                 // the grid's rows changed since; make a new source to see them

The drill-down window takes a source: <PivotDrillDownModal source={source} … />. It builds only the page on screen.

A DataGrid over a selection

To show every row of a selection in a DataGrid, give it source.toRowArray():

const rows = useMemo(() => ref.current!.getSelectionRowSource().toRowArray(), [selection]);
<DataGrid data={rows} columns={columns} selection={{ mode: 'multiple' }} />;

In a columnar grid each element is a small row handle, about 40 bytes. Its properties read the pivot's columns, so the DataGrid works exactly as over plain rows: header sort, the header filter and its value list, Excel export of all or of the filtered rows in the on-screen column order, column moves and widths, range selection totals, copy. The DataGrid's own per-row cost (about 70 bytes) is the same as with plain rows.

Measured with 500,000 rows (eight columns): the array is built in 6 ms (19 MB), a header sort takes 0.1 s (0.5 s on a column where every value is different), the header filter list opens in 31 ms, and a filter applies in 60 ms. We set no limit on the number of rows. The DataGrid's own limits apply as they do for any data: its value list shows up to 1,000 values, and selection totals are computed up to a cell limit.

A handle is not a plain object. Object.keys(handle) and { ...handle } are empty, so use JSON.stringify(handle) or getRows for a plain row. structuredClone of a handle gives an empty object. Handles are for reading: a write (an edit) stays on that handle. The DataGrid infers its columns from handles as from plain rows; you can also pass columns, and source.columns lists the names.

Memory

  • About 350 bytes per row for a typical fifty-column report: text columns at one byte per row when they have up to 250 distinct values, numbers and dates at eight. Columns where every row has its own text (a barcode, say) cost about 60 more bytes per row each.
  • The worker keeps its own copy of the placed fields' columns, as before: 4–8 bytes per placed field per row.
  • Opening every group of a large tree still costs what it costs (about 260 bytes per visible node). With a per-row field such as a barcode among the row fields, expanding everything is the most expensive step.

Optional: a limit for a saved open state

By default the grid restores a saved open state (stateStoring, reports, applyPersistedState) exactly as it was saved, however large the tree. If a very large report can be saved fully expanded and you would rather open it collapsed than risk the tab running out of memory at every visit, set maxRestoredOpenNodes:

  • It is the most row nodes the grid may hold for a state that was put back. The worker counts them before anything is built. This is what the tab keeps in memory, not what is on screen: after "Expand all" ('*') the grid keeps every node, the members of closed branches too, so that opening one again is instant. A state saved after a big "Collapse all" therefore still counts the whole tree.
  • Over the limit, the saved open state is dropped because the tree would not fit in memory: the grid opens with every row group closed, saves that state instead, and calls onRestoredExpansionCollapsed({ nodes, limit }) once, so you can tell the reader why.
  • It applies to the state the grid started with (stateStoring, the default report) and to applyPersistedState or a loaded report, at every compute until the reader or your code expands or collapses something. So rows streaming in, a wider filter or an added row field that grow the tree past the limit also drop a restored state (once; the rows keep coming). The reader's own "Expand all" is never limited.
  • Unset, 0 or Infinity (the default) turns it off, and nothing is counted. A serverSource grid is not checked.
  • In development, React StrictMode creates the controller twice, so the callback can fire twice there.
<EnterprisePivotGrid
  maxRestoredOpenNodes={1_000_000}
  onRestoredExpansionCollapsed={() =>
    toast('This report was too large to reopen the way it was saved, so it opened collapsed.')}
  {...props}
/>

In JavaScript the same two options go to createPivotGrid / createEnterprisePivotGrid.

Large live computes during a feed are held back

While rows stream in (applyTransactionAsync) into a report that is fully expanded ('*', for example a saved "Expand all"), every live compute builds the whole open tree again, and the last one starts while the previous whole tree is still on screen. On a very large report that means two large trees in memory at once, so the grid holds those computes back (maxLiveOpenNodes, on by default):

  • It is the most row nodes a live-update compute may build while the feed runs. It counts the same way as maxRestoredOpenNodes: every row node the grid would keep, the members of closed branches included. The default is 500,000.
  • Over it, the worker answers before anything is built: the screen keeps its last result, isComputing stays true and engineCompleted is not fired for that compute. A row count you show from your own feed keeps moving; the new rows appear in the table together.
  • The full result is computed at once when the feed ends (flushAsyncTransactions(), setLoading(false)), for an export, after a synchronous applyTransaction, for anything the reader or your code changes (a toggle, a filter, a field), and when no new rows have arrived for about 2 seconds since the last compute was held back.
  • A feed that never pauses for 2 seconds does not keep the old screen for good: once the result on screen is 5 minutes old (or, for a very costly result, older than the grid's own spacing between live computes for it), the next live compute is built and shown, and the clock starts again.
  • Only live computes under expand-all are held back. A serverSource grid is not affected.
  • To move the limit, pass another number. To turn it off (every live compute is built and shown, as before 1.11.16), pass 0 or Infinity:
<EnterprisePivotGrid maxLiveOpenNodes={0} {...props} />

In JavaScript the option goes to createPivotGrid / createEnterprisePivotGrid.