View as Markdown

API reference: @salmonui/pivot-table

PivotControllerclass

import { PivotController } from '@salmonui/pivot-table';
class PivotController<Row = unknown> {
    handlers: Handlers<Row>;
    private options;
    private state;
    private readonly listeners;
    private engine;
    private unsubscribeEngine;
    windowed: WindowedPivot | null;
    private memberCache;
    private data;
    private initial;
    private mounted;
    private appliedPropKey;
    private pending;
    constructor(options: UsePivotOptions<Row>);
    readonly subscribe: (listener: Listener) => (() => void);
    readonly getSnapshot: () => PivotState;
    get result(): PivotResult | null;
    get status(): PivotState['status'];
    get model(): PivotModel;
    getData(): readonly Row[];
    private set;
    private engineOptions;
    private createEngine;
    private readonly syncFromEngine;
    mount(): () => void;
    private isLarge;
    private whenReady;
    updateOptions(options: UsePivotOptions<Row>): void;
    applyModelProp(input: PivotModelInput | undefined): void;
    applyDataProp(data: readonly Row[] | undefined): void;
    private event;
    private allowed;
    private emitCompute;
    private emitError;
    private run;
    setModel(input: PivotModelInput | ((model: PivotModel) => PivotModelInput), options?: PivotCommandOptions & {
        readonly action?: PivotAction;
        readonly field?: string | null;
    }): boolean;
    private commit;
    applyDraft(source?: PivotEventSource): boolean;
    cancelDraft(): void;
    beginDraft(): void;
    moveField(field: string, to: PivotAxis | null, index?: number, options?: PivotCommandOptions): boolean;
    stepField(field: string, axis: PivotAxis, step: -1 | 1, options?: PivotCommandOptions): boolean;
    setFilter(field: string, filter: PivotFilter | null, options?: PivotCommandOptions): boolean;
    setSort(field: string, sort: PivotMemberSort, options?: PivotCommandOptions): boolean;
    setValueSort(valueSort: PivotValueSort | null, options?: PivotCommandOptions): boolean;
    setAggregate(index: number, aggregate: PivotAggregate, options?: PivotCommandOptions): boolean;
    aggregateMenuItems(field: string, index: number, items: PivotAggregate[], source?: PivotEventSource): PivotAggregate[] | null;
    setCalculatedField(name: string, calculatedField: PivotCalculatedField | null, options?: PivotCommandOptions & {
        readonly addToValues?: boolean;
    }): boolean;
    setFormat(field: string, format: PivotFormat | null, options?: PivotCommandOptions): boolean;
    setConditionalFormats(conditionalFormats: readonly PivotConditionalFormat[], options?: PivotCommandOptions): boolean;
    setGrouping(field: string, grouping: PivotGrouping | null, options?: PivotCommandOptions): boolean;
    setTotals(totals: Partial<PivotTotals>, options?: PivotCommandOptions): boolean;
    private isExpanded;
    expand(path: PivotMemberPath, options?: PivotCommandOptions): boolean;
    collapse(path: PivotMemberPath, options?: PivotCommandOptions): boolean;
    toggle(node: PivotHeaderNode, options?: PivotCommandOptions): boolean;
    private drill;
    private expandedPathsFromResult;
    expandAll(axis?: 'rows' | 'columns', options?: PivotCommandOptions): boolean;
    collapseAll(axis?: 'rows' | 'columns', options?: PivotCommandOptions): boolean;
    private drillAll;
    setSelection(cells: readonly PivotCellKey[], options?: PivotCommandOptions & {
        readonly confirmed?: boolean;
    }): boolean;
    getMembers(field: string, options?: {
        search?: string;
        limit?: number;
    }): readonly PivotMember[];
    getMembersAsync(field: string, options?: {
        search?: string;
        limit?: number;
    }): Promise<readonly PivotMember[]>;
    getLoadedMembers(field: string): readonly PivotMember[] | null;
    getCellRows(rowIndex: number, columnIndex: number): readonly Row[];
    getCellRowsAsync(rowIndex: number, columnIndex: number): Promise<readonly Row[]>;
    getCellRowIndexes(rowIndex: number, columnIndex: number): readonly number[];
    drillThrough(rowIndex: number, columnIndex: number, options?: PivotCommandOptions & {
        readonly openDialog?: boolean;
    }): boolean;
    updateRows(changes: readonly {
        readonly index: number;
        readonly row: Row | null;
    }[], action?: PivotDataChangeEvent<Row>['action']): void;
    refresh(): void;
    openDialog(dialog: PivotDialogState, source?: PivotEventSource): boolean;
    closeDialog(): void;
    getState(extra?: Omit<PivotTableState, 'version' | 'pivotModel'>): PivotTableState;
    restoreState(state: PivotTableState | string, source?: PivotEventSource): boolean;
    get isMounted(): boolean;
}

The store of one pivot report. Create it with usePivot(); pass it to the pivot parts as pivot.

PivotController members (75)
NameSignatureDescription
handlershandlers: Handlers<Row>;

Latest event handlers (replaced on every usePivot() render, read when an event fires).

optionsprivate options;
stateprivate state;
listenersprivate readonly listeners;
engineprivate engine;
unsubscribeEngineprivate unsubscribeEngine;
windowedwindowed: WindowedPivot | null;

Window adapter of an asynchronous (Worker) engine; null for the local engine.

memberCacheprivate memberCache;
dataprivate data;
initialprivate initial;
mountedprivate mounted;
appliedPropKeyprivate appliedPropKey;
pendingprivate pending;
subscribereadonly subscribe: (listener: Listener) => (() => void);
getSnapshotreadonly getSnapshot: () => PivotState;
resultget result(): PivotResult | null;

Current result (null before the first compute).

statusget status(): PivotState['status'];
modelget model(): PivotModel;
getDatagetData(): readonly Row[];

Raw rows the engine aggregates (after drill-through edits).

setprivate set;
engineOptionsprivate engineOptions;
createEngineprivate createEngine;
syncFromEngineprivate readonly syncFromEngine;

Reads the engine snapshot into the store (also the engine listener).

mountmount(): () => void;

Called from an effect: subscribes to the engine, starts a deferred compute, reports the initial compute.

isLargeprivate isLarge;
whenReadyprivate whenReady;
updateOptionsupdateOptions(options: UsePivotOptions<Row>): void;

Latest options (from usePivot() renders): handlers and creation-only fields.

applyModelPropapplyModelProp(input: PivotModelInput | undefined): void;

Applies the reactive pivotModel prop when it changed structurally.

applyDataPropapplyDataProp(data: readonly Row[] | undefined): void;

Applies a new data prop (identity change).

eventprivate event;
allowedprivate allowed;

Fires a before-event; true when it was not cancelled.

emitComputeprivate emitCompute;
emitErrorprivate emitError;
runprivate run;

Runs an engine command with the compute events, the status, and error reporting.

setModelsetModel(input: PivotModelInput | ((model: PivotModel) => PivotModelInput), options?: PivotCommandOptions & { readonly action?: PivotAction; readonly field?: string | null; }): boolean;

Applies a model (cancellable through onBeforePivotModelChange). Returns false when the change was cancelled or changed nothing.

commitprivate commit;

Shared commit path: model before-event, the engine command, the after-event. apply runs a specialized engine command (expand, collapse) instead of setModel.

applyDraftapplyDraft(source?: PivotEventSource): boolean;

Commits the draft model of a deferred field list (Apply).

cancelDraftcancelDraft(): void;

Drops the draft model (Cancel).

beginDraftbeginDraft(): void;

Starts a draft from the applied model (a deferred field list opening).

moveFieldmoveField(field: string, to: PivotAxis | null, index?: number, options?: PivotCommandOptions): boolean;

Moves a field between axes or inside one; to: null removes it (cancellable through onBeforeFieldMove).

stepFieldstepField(field: string, axis: PivotAxis, step: -1 | 1, options?: PivotCommandOptions): boolean;

Moves a field one step inside its axis (Alt+ArrowUp / ArrowDown).

setFiltersetFilter(field: string, filter: PivotFilter | null, options?: PivotCommandOptions): boolean;

Member, label or value filter of a field; null clears it (cancellable through onBeforeFilterChange).

setSortsetSort(field: string, sort: PivotMemberSort, options?: PivotCommandOptions): boolean;

Member sort of a field (cancellable through onBeforeSortChange).

setValueSortsetValueSort(valueSort: PivotValueSort | null, options?: PivotCommandOptions): boolean;

Value sort; null clears it.

setAggregatesetAggregate(index: number, aggregate: PivotAggregate, options?: PivotCommandOptions): boolean;

Aggregate of the value field at index.

aggregateMenuItemsaggregateMenuItems(field: string, index: number, items: PivotAggregate[], source?: PivotEventSource): PivotAggregate[] | null;

Aggregates the menu offers; onBeforeAggregateMenuOpen may cancel or edit items. Null when cancelled.

setCalculatedFieldsetCalculatedField(name: string, calculatedField: PivotCalculatedField | null, options?: PivotCommandOptions & { readonly addToValues?: boolean; }): boolean;

Adds or replaces a calculated field (by name), or removes it (calculatedField: null).

setFormatsetFormat(field: string, format: PivotFormat | null, options?: PivotCommandOptions): boolean;

Number or date format of a value field or a member field (null clears it).

setConditionalFormatssetConditionalFormats(conditionalFormats: readonly PivotConditionalFormat[], options?: PivotCommandOptions): boolean;
setGroupingsetGrouping(field: string, grouping: PivotGrouping | null, options?: PivotCommandOptions): boolean;

Number range, date or custom grouping of a field; null ungroups it.

setTotalssetTotals(totals: Partial<PivotTotals>, options?: PivotCommandOptions): boolean;
isExpandedprivate isExpanded;
expandexpand(path: PivotMemberPath, options?: PivotCommandOptions): boolean;

Expands a member (incremental in the engine).

collapsecollapse(path: PivotMemberPath, options?: PivotCommandOptions): boolean;
toggletoggle(node: PivotHeaderNode, options?: PivotCommandOptions): boolean;

Expands or collapses a header node.

drillprivate drill;
expandedPathsFromResultprivate expandedPathsFromResult;

Paths of every expanded node of the current result (to turn expanded: 'all' into a list).

expandAllexpandAll(axis?: 'rows' | 'columns', options?: PivotCommandOptions): boolean;

Expands every member of one axis or both (Ctrl+ArrowDown).

collapseAllcollapseAll(axis?: 'rows' | 'columns', options?: PivotCommandOptions): boolean;
drillAllprivate drillAll;
setSelectionsetSelection(cells: readonly PivotCellKey[], options?: PivotCommandOptions & { readonly confirmed?: boolean; }): boolean;

Replaces the selected cells (cancellable through onBeforeSelectionChange).

getMembersgetMembers(field: string, options?: { search?: string; limit?: number; }): readonly PivotMember[];

Members of a field for the member editor: every member, searchable, no node limit.

getMembersAsyncgetMembersAsync(field: string, options?: { search?: string; limit?: number; }): Promise<readonly PivotMember[]>;

Members, waiting for an asynchronous engine.

getLoadedMembersgetLoadedMembers(field: string): readonly PivotMember[] | null;

Members already loaded by getMembersAsync() (null when not loaded yet).

getCellRowsgetCellRows(rowIndex: number, columnIndex: number): readonly Row[];

Raw rows behind a value cell.

getCellRowsAsyncgetCellRowsAsync(rowIndex: number, columnIndex: number): Promise<readonly Row[]>;

Raw rows behind a value cell, waiting for an asynchronous engine.

getCellRowIndexesgetCellRowIndexes(rowIndex: number, columnIndex: number): readonly number[];

Raw row indexes behind a value cell.

drillThroughdrillThrough(rowIndex: number, columnIndex: number, options?: PivotCommandOptions & { readonly openDialog?: boolean; }): boolean;

Opens drill through for a value cell (cancellable through onBeforeDrillThrough). openDialog: false only fires the events (an app with its own UI).

updateRowsupdateRows(changes: readonly { readonly index: number; readonly row: Row | null; }[], action?: PivotDataChangeEvent<Row>['action']): void;

Writes edited raw rows (drill-through editing): replaces the rows at index, appends index: -1 rows, removes row: null rows, then re-aggregates incrementally and fires onDataChange.

refreshrefresh(): void;

Re-reads the data and recomputes.

openDialogopenDialog(dialog: PivotDialogState, source?: PivotEventSource): boolean;
closeDialogcloseDialog(): void;
getStategetState(extra?: Omit<PivotTableState, 'version' | 'pivotModel'>): PivotTableState;
restoreStaterestoreState(state: PivotTableState | string, source?: PivotEventSource): boolean;

Applies a saved state; false (with onError) when it is not a pivot state of a known version.

isMountedget isMounted(): boolean;

True while mounted (effects ran).