Skip to content

Export And State

Use the installed PivotPlugin instance to capture the current visible logical result. getVisibleExportData() supplies readable grouped captions and semantic raw aggregates, nested column headers and pinned totals. Reading grid.source directly misses values in synthetic group rows. Exporting the original facts misses the entire Pivot layout.

import { PivotPlugin, buildPivotCopyTsv } from '@revolist/pivot';
const pivotPlugin = (await grid.getPlugins()).find(
(plugin): plugin is PivotPlugin => plugin instanceof PivotPlugin,
);
if (!pivotPlugin) throw new Error('Pivot is not installed');
const csv = pivotPlugin.exportCsv({ bom: true }); // string
const xlsx = pivotPlugin.exportXlsx(); // Uint8Array
const table = pivotPlugin.buildPrintTable(); // escaped HTML table
const tsv = buildPivotCopyTsv(pivotPlugin.getVisibleExportData());
await navigator.clipboard.writeText(tsv);

These methods capture the current visible logical result automatically, including group captions and aggregates, subtotals, grouped headers, and pinned totals. CSV options support delimiters, a UTF-8 BOM, and a grouped-header separator. XLSX retains numeric cells and nested headers. Exported numbers retain raw precision.

XLSX also carries standard measure number, currency and percent formats, including inferred percentage calculations, duplicate measures and values on rows. Formatting changes the workbook’s display without rounding or converting numeric cells to text. Excel uses the viewer’s decimal and grouping separators; currency labels and their position come from the configured locale. Required and optional decimal places, standard three-digit grouping, signs and accounting parentheses are retained.

Advanced Intl formats that cannot be represented faithfully use Excel General while keeping the raw numeric value: compact/scientific/engineering notation, significant-digit or nondefault rounding rules, padded integer digits, signDisplay: 'exceptZero', unit formats, currency names, non-Latin digits, and nonstandard grouping. Date/datetime measure formats, custom cell renderers, conditional colors/classes and custom blank/invalid display text are not translated into XLSX styles. Use the printable table for configured display strings. Unformatted standalone-helper inputs retain their existing default numeric style.

buildPrintTable() applies the configured measure display formats (including inferred percentage calculations), while CSV/XLSX retain raw numeric precision. Declare a measure format such as { preset: 'currency', currency: 'USD', locale: 'en-US' } to share its grid and print presentation. It returns a table with nested header spans and pinned-total rows marked with class="total". The application supplies surrounding HTML, print styles, titles, and the browser print dialog; users can choose Save as PDF there. Pivot does not create PDF bytes or open windows automatically. Treat the returned markup as generated output; cell and header values are HTML-escaped.

For a detached or headless result, use the standalone exportVisiblePivotToCsv, exportVisiblePivotToXlsx, and buildPivotPrintTable helpers from @revolist/pivot or @revolist/pivot/headless. Pass resolved rows and nested columns, such as the output of getVisibleExportData(). The helpers do not resolve Core grouping carriers themselves.

The XLSX helper accepts PivotXlsxExportInput. Its optional cellNumberFormats matrix holds native Excel format codes in flattened leaf-column order, with body rows followed by pinned-bottom rows. getVisibleExportData() captures this matrix automatically from semantic measure identities. Keep it aligned if you reorder detached rows or columns. CSV ignores this presentation metadata.

The complete download, copy, report import/export and drill implementation is the checked toolbar.ts in Custom Integrations. Applications own filenames, downloads, clipboard access, print dialogs, and branding.

Interactive example

Exports and saved state

Export CSV/XLSX/TSV from semantic visible result incl grouped headers/aggregates/totals

The example loads when visible.

Use V2 portable reports for the recommended explicit aggregation policies. An execution pin survives portable V1/V2 report roundtrip; it does not guarantee matching local/server results. Configuration JSON is lossy for callbacks, not a substitute for report/runtime bindings. Preserve calculation meaning when configuring saved reports.

Visible export captures the logical current result, including virtualized visible report rows and applicable totals; it is not just DOM pixels. In server mode it exports the returned report/window. It does not fetch every backend record. Full-dataset exports require an explicit server export operation with the same scope and permissions.

CSV, XLSX and TSV require a settled result. The checked toolbar disables data exports while an analytical request is loading and explains when they become available again. Retained grid pixels during loading do not promise that visible-export capture is available. Report JSON is a separate configuration operation.

pivotPlugin.exportPivotReportJson() saves authored report configuration. importPivotReport(json, options) validates and executes a candidate through normal preventable admission. Supply named runtime bindings separately for callbacks, sources and adapters; explicitly opt in with reportVersion: 2 for V2 documents. Live transient filters or unbound session callbacks can prevent portable export. JSON report documents do not contain the result facts.

serializePivotStateJson(config) and parsePivotStateJson(json) transport JSON-safe PivotConfig state, including axes, values, filters, expansion and formatting. This remains distinct from portable semantic report documents and runtime registries. JSON-only fieldPanel.texts entries, including nested label maps such as aggregationNames, are preserved. Function-valued locale messages remain runtime callbacks and require explicit report bindings rather than state JSON.

import { serializePivotStateJson, parsePivotStateJson } from '@revolist/pivot';
const state = serializePivotStateJson(currentAcceptedConfig);
localStorage.setItem('sales:pivot-state', state);
const saved = localStorage.getItem('sales:pivot-state');
if (saved) {
try {
const accepted = await pivotPlugin.updatePivotConfig(parsePivotStateJson(saved));
if (!accepted) showMessage('Saved layout was not committed');
} catch (error) {
showMessage(String(error));
}
}

Persist committed state after successful execution, not every pivot-config-update proposal. Neither report JSON nor state JSON serializes source records or callback functions. Keep application bindings outside JSON and handle parse/import errors.

The Vue, React, Angular, and Vanilla TypeScript export/state examples use these resolved export APIs.

The attached Save views menu supports scoped durable storage through PivotPlugin.setSavedViewStorage. See Persistent saved views for browser storage, application adapters, conflict handling and recovery.

CSV, XLSX, print and complete exports.