Skip to content

Custom Integrations

Choose one analytical owner. An attached grid already has a PivotPlugin controller; its getAuthoringController() facade lets your application author that same report. A standalone renderer uses createPivotController from @revolist/pivot/headless instead.

IntegrationApplication ownsPublic surface
ViewerRendering policy and permitted interactionsCommitted runtime, exports and optional drill
Custom constructorFour-zone controls and application admissionAttached authoring commands, snapshots, history
Stock panel outside gridHost element, update wiring and cleanupdefinePivotConfigurator
Toolbar or field editorControls, download lifetime and presentationVisible export, stable field/measure commands
Async application APIAuth, tenant scope, response validation and executionClient/server adapter contract
Standalone engineRendering, source replacement and disposalHeadless controller
Interactive example

Custom integrations

Run checked attached constructor/editor/toolbar shell with one analytical owner

The example loads when visible.

Install and connect the RevoGrid element with PivotPlugin once before calling the recipe. The host owns grid destruction. This mount requires an inactive Pivot, supplies the source/config once, and returns cleanup for only the application shell.

import { PivotPlugin } from '@revolist/pivot';
import { mountPivotIntegration } from './public-integration/index';
// In your framework's mounted/effect callback, after the grid is connected:
grid.plugins = [PivotPlugin];
const integration = await mountPivotIntegration({
grid,
constructorHost,
toolbarHost,
editorHost,
onCommitted(snapshot) {
// Ready revisions only. Session descriptors are not automatically portable.
saveAcceptedLayout(snapshot.report?.specification);
},
});
// On framework cleanup:
integration.dispose();

Copy the complete checked modules below into public-integration/, retaining their relative imports. Every library import uses a public package entry. The displayed source is imported directly from the executable recipe files, so the documentation and browser fixture exercise the same code. Run pnpm --filter @revolist/pivot check:recipes in the monorepo after building Pivot to compile against actual installed dist declarations and execute the DOM-free headless example.

The constructor starts with populated Rows, Columns, Values and Filters. Use Add, Remove, Up/Down and cross-zone controls to edit the report. The same Revenue field has distinct SUM and AVG measure IDs. The atomic action swaps axes and relabels one measure in one history entry; Undo, Redo and Reset use the same owner as the grid.

Member filters accept one typed JSON scalar, for example 2025 or "Australia"; Clear removes that selection. Field label/allowed-role controls change metadata, while the measure editor independently changes aggregation, label and numeric formatting. Field IDs and source properties are never edited as captions.

Controls render from pendingReport while loading and committed report otherwise. A pending shelf is intent; the grid retains the last committed values until success. Invalid commands can throw synchronously, and accepted operations can return prevented, superseded, cancelled, noop or failed. The recipe catches both forms and does not call every resolved promise a commit. Inputs stay mounted while typing; grouped controls restore keyboard focus after a shelf change.

Pass mode: 'viewer' to omit constructor/editor controls and report import. This recipe synchronously prevents all subsequent configuration proposals, captures the public row expansion event before Core mutates its grouping view, and disables column collapse controls (including per-level overrides). Column collapse events are post-mutation notifications and are not veto points. Export and supported drill remain available. A viewer that permits expansion needs a narrower explicit policy instead.

There is no Pivot readOnly authoring switch. Core editing restrictions do not freeze analytical layout, and a UI veto is not backend authorization. Apply tenant and field permissions on the application API too.

CSV and XLSX use plugin.exportCsv() and plugin.exportXlsx(); TSV uses plugin.getVisibleExportData(): readable grouped captions, raw numeric aggregates, nested headers and pinned totals. The remote export covers the current logical report/window, not every fact in the backend. Exporting raw grid.source loses renderer-generated group aggregates.

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.

Report JSON describes configuration, not data. Export can reject session-only callbacks or transient linked filters. Supply explicit reportOptions with named runtime Maps when importing bound reports, and reportVersion: 2 only when your application admits V2. The import path retains strict version/runtime admission; the authoring facade does not accept report.replace.

Drill inputs are semantic row/column paths, with a maximum 100-row page in this recipe. loadPivotDrilldown also supports positional dataIndex when selecting a measure. Requests carry an AbortSignal and are fenced to the captured committed revision. Cancelling, changing revisions or disposing the shell prevents stale results from painting the UI. Capability checks require an active runtime first; unsupported drill is disabled and explained.

Optional chart options create an unlinked standalone chart using an explicit application-supplied dataset/model via the public /charts entry. The recipe destroys only the chart it creates, including when initialization finishes after unmount. It does not recompute Pivot aggregates or claim that this unlinked chart follows report edits automatically. Use the existing Pivot Charts integration for linked chart behavior.

createHttpAdapter(baseUrl) posts load, drilldown and filter-values requests to application endpoints, forwards AbortSignal and rejects non-2xx responses. Its advertised capabilities are a contract your endpoints must implement; response validation and authentication remain application responsibilities. Set config.engine to { mode: 'server', adapter }. Only client and server are public engine modes.

createSimulatedAdapter() is explicitly an in-memory simulation over the supplied sample configuration/facts. setDelay(ms), failNext() and requests support testing retained results, failure and latest-wins behavior. It advertises drill/member lookup unavailable and deliberately ignores abort to test stale-result fencing. It is not a production backend test.

OperationClientServer
Commands/historyAttached facadeSame facade; async outcomes
Member lookup/drillPublic methods, committed scopeAdapter support required
ExportCurrent visible logical resultCurrent returned window
Isolated analytical queryExact-source capability checkUnsupported
Source/runtime replacementHost/report importHost/report import

For synchronous application admission, prevent pivot-config-update before execution. Persist a newly committed authoring snapshot afterwards. Do not save proposals as successful results or build a second headless controller to mirror the grid.

Source code
import {
type PivotAuthoringSnapshot,
type PivotConfig,
type PivotReportPluginOptions,
} from '@revolist/pivot';
import { GROUP_EXPAND_EVENT, type DataType } from '@revolist/revogrid';
import {
findPivot,
mountConstructor,
sampleConfig,
sampleFacts,
} from './attached';
import { mountFieldEditor } from './field-editor';
import { mountToolbar, type ToolbarOptions } from './toolbar';
export interface PivotIntegrationOptions {
grid: HTMLRevoGridElement;
constructorHost: HTMLElement;
toolbarHost: HTMLElement;
editorHost: HTMLElement;
mode?: 'editor' | 'viewer';
config?: Partial<PivotConfig>;
source?: DataType[];
reportOptions?: PivotReportPluginOptions;
chart?: ToolbarOptions['chart'];
/** Called only for a newly committed revision, never for a pending/failed proposal. */
onCommitted?: (snapshot: PivotAuthoringSnapshot) => void;
}
/** Host installs Core/Pivot once and owns grid teardown. This mount owns only its shell. */
export async function mountPivotIntegration(options: PivotIntegrationOptions) {
const { grid } = options;
const plugin = await findPivot(grid);
if (plugin.getRuntimeSnapshot())
throw new Error(
'Mount initialization requires an inactive Pivot; dispose/clear the old integration first.',
);
grid.source = (options.source ?? sampleFacts).map((row) => ({ ...row }));
grid.columns = Object.keys(grid.source[0] ?? {}).map((prop) => ({
prop,
name: prop,
}));
if (options.reportOptions)
plugin.setPivotReportRuntime(options.reportOptions);
const config: Partial<PivotConfig> = {
...sampleConfig,
...options.config,
contextMenu: false,
hasConfigurator: false,
};
if (options.mode === 'viewer') {
// Column collapse events are post-mutation notifications, not veto points.
config.columnCollapse = false;
config.columnLevels = Object.fromEntries(
Object.entries(config.columnLevels ?? {}).map(([level, settings]) => [
level,
{ ...settings, collapsible: false },
]),
);
}
const accepted = await plugin.updatePivotConfig(config);
if (!accepted || !plugin.getRuntimeSnapshot())
throw new Error('Initial Pivot was not committed.');
const authoring = plugin.getAuthoringController();
const cleanup: (() => void)[] = [];
let disposed = false;
let committedRevision = -1;
const persist = () => {
const snapshot = authoring.getSnapshot();
if (
!disposed &&
snapshot.status === 'ready' &&
snapshot.report &&
snapshot.revision !== committedRevision
) {
committedRevision = snapshot.revision;
options.onCommitted?.(snapshot);
}
};
try {
if (options.mode === 'viewer') {
// This example forbids every report proposal, including row/column expansion.
// It is application UI policy, not backend authorization.
const veto = (event: Event) => event.preventDefault();
grid.addEventListener('pivot-config-update', veto);
cleanup.push(() => grid.removeEventListener('pivot-config-update', veto));
// Core grouping mutates its view independently of the later config proposal.
// Capture the public event before its bubble-phase grouping handler runs.
const fixedExpansion = (event: Event) => {
event.preventDefault();
event.stopImmediatePropagation();
};
grid.addEventListener(GROUP_EXPAND_EVENT, fixedExpansion, true);
cleanup.push(() =>
grid.removeEventListener(GROUP_EXPAND_EVENT, fixedExpansion, true),
);
const notice = document.createElement('p');
notice.textContent = 'Viewer: layout and expansion are fixed';
options.constructorHost.append(notice);
cleanup.push(() => notice.remove());
} else {
cleanup.push(
mountConstructor(options.constructorHost, authoring),
mountFieldEditor(options.editorHost, authoring),
);
}
cleanup.push(authoring.subscribe(persist));
persist();
cleanup.push(
mountToolbar(options.toolbarHost, plugin, {
reportOptions: options.reportOptions,
chart: options.chart,
viewer: options.mode === 'viewer',
}),
);
} catch (error) {
disposed = true;
cleanup.reverse().forEach((dispose) => dispose());
throw error;
}
return {
plugin,
authoring,
dispose() {
if (disposed) return;
disposed = true;
cleanup.reverse().forEach((dispose) => dispose());
},
};
}

Dispose the returned shell before removing its hosts. This unsubscribes constructors/editors/persistence, aborts drill, removes viewer veto and releases its chart. It does not destroy the grid or erase its report. Clear the existing Pivot explicitly before mounting a new integration that initializes source/config. Captured authoring facades survive clear/re-enable; after plugin destroy they remain terminal. Pending adapter work belongs to the plugin and can be cancelled explicitly when the grid owner tears down.

The compile-only authority.type-test.ts additionally rejects private controller access, attached disposal/source replacement, report.replace, invented hybrid mode and cross-entry authority imports. These negative assertions are never executed in the application.

Explore built-in controls · Undo and Redo · Save reports.