PivotTable
An operational PivotTable. Handles are invalid after removal or document replacement; snapshots are detached.
Package: @txtextcontrol/tx-sheet-control-server. Obtain operational handles through workbook.pivotTables; settings and results are detached values.
Members
| Member | Description |
|---|---|
| snapshot | Returns current persisted settings, including the materialized output range. |
| name | Current workbook-unique name. Rename through update({name}). |
| getFields | Available source and calculated fields; table growth is resolved each time. |
| getItems | Distinct typed/grouped members in source order, including blanks. |
| update | Replace supplied settings and refresh atomically. Invalid settings, overlap or protection leave the workbook intact. |
| refresh | Re-read live source values and rewrite the output in one undoable transaction. |
| getResult | Compute detached output without modifying cells or undo history. |
| setFilters | Replace report/member/value filters; supplying [] clears all filters. |
| setFields | Configure one axis, including order, sorting and grouping, using the same validation as the field panel. |
| setExpanded | Expand/collapse a grouped member path. Paths contain grouped item values, not display indentation. |
| drillThrough | Returns filtered source records contributing to an axis intersection, at most limit (default 1,000; maximum 100,000). |
| getData | Read an aggregate by its value caption and row/column paths. Paths may identify parent totals. |
| createChart | Creates a worksheet chart whose data range follows this pivot after refresh or relocation. |
| remove | Remove this pivot and optionally preserve its rendered cells as a static report. |
Example
In a browser use const workbook = editor.workbook. In Node.js use your server control workbook.
import { ServerSheetControl as ExampleServer } from '@txtextcontrol/tx-sheet-control-server';
const exampleControl = new ExampleServer();
const workbook = exampleControl.workbook;
const source = workbook.sheets.at(0);
source.range('A1:D5').setValues([
['Region', 'Category', 'Revenue', 'Cost'],
['Europe', 'Software', 1250, 500],
['Europe', 'Services', 700, 350],
['Americas', 'Software', 1800, 900],
['Americas', 'Services', 950, 400]
]);
const report = workbook.sheets.add('Sales Summary');
const pivot = report.pivotTables.add({
name: 'RegionalSales',
source: { sheetId: source.id, range: 'A1:D5' },
destination: { sheetId: report.id, cell: 'B3' },
rows: [{ field: 'Region' }],
columns: [{ field: 'Category' }],
values: [{ field: 'Revenue', caption: 'Sales', numberFormatCode: '$#,##0.00' }],
layout: 'tabular', style: { rowBanding: true }
});
exampleControl.destroy();
See Pivot Tables for filtering, calculated values and output.
- id — Stable report or collection scope identity.