TX Sheet Control

PivotTable

Class

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

MemberDescription
snapshotReturns current persisted settings, including the materialized output range.
nameCurrent workbook-unique name. Rename through update({name}).
getFieldsAvailable source and calculated fields; table growth is resolved each time.
getItemsDistinct typed/grouped members in source order, including blanks.
updateReplace supplied settings and refresh atomically. Invalid settings, overlap or protection leave the workbook intact.
refreshRe-read live source values and rewrite the output in one undoable transaction.
getResultCompute detached output without modifying cells or undo history.
setFiltersReplace report/member/value filters; supplying [] clears all filters.
setFieldsConfigure one axis, including order, sorting and grouping, using the same validation as the field panel.
setExpandedExpand/collapse a grouped member path. Paths contain grouped item values, not display indentation.
drillThroughReturns filtered source records contributing to an axis intersection, at most limit (default 1,000; maximum 100,000).
getDataRead an aggregate by its value caption and row/column paths. Paths may identify parent totals.
createChartCreates a worksheet chart whose data range follows this pivot after refresh or relocation.
removeRemove 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.