Class PivotResult<T>

The result of a pivot (pivotRows, AreaModelPivot.getResult): the row and column hierarchies and the aggregated value of every combination – cells, subtotals and totals. DOM-free; the table reads its cells from here.

  • getValue(row, column) – a cell; leave out row for the column total, column for the row total, both for the grand total. Groups of higher levels give subtotals.
  • A combination without rows is undefined (not 0).
  • Every cell is computed from the rows (leaf cells) or by merging aggregation states – an average of a region is the average of its rows, never the average of the product averages. Order of the merges: first along the columns (column groups), then along the rows (row groups, total row) – children in key order. This matters for first/last only: a row total adds its rows in source order, a column group merges its keys in key order, so the two may differ. Keys cut off by maxColumns still count in subtotals and totals.

Example

const result = pivotRows(sales, { rowFields: ["region"], columnFields: ["monat"], values: ["umsatz"] });
const nord = result.rowGroups[0]; // Nord
const jan = result.columnLeaves.find(c => c.key === "Jan");
result.getValue(nord, jan); // 150
result.getValue(nord); // 270 – the row total
result.getValue(undefined, jan); // 230 – the column total
result.getValue(); // 450

Since

1.1.94

Type Parameters

  • T = any

    the row type

Hierarchy

  • PivotResult

Constructors

  • Groups the rows by the row and column fields and aggregates the values. Use pivotRows.

    Type Parameters

    • T = any

    Parameters

    • config: PivotConfigIf<T>

      fields and values

    • Optional accept: ((sourceIndex) => boolean)

      a filter: only rows it accepts count

        • (sourceIndex): boolean
        • Parameters

          • sourceIndex: number

          Returns boolean

    Returns PivotResult<T>

Properties

columnGroups: RowGroup<T>[]

The column groups of the top level (with sub-groups); empty without column fields.

columnLeaves: RowGroup<T>[]

The shown column keys of the lowest level in display order – at most PivotConfigIf.maxColumns.

rowGroups: RowGroup<T>[]

The row groups of the top level (with sub-groups); empty without row fields.

truncated: boolean

True if there were more column keys than PivotConfigIf.maxColumns (the rest is not shown as columns).

values: readonly PivotValueInfoIf[]

The values (name, label, aggregator, format).

Methods

  • Computes all cells again (same keys) – after a filter change or changed values.

    Parameters

    • Optional accept: ((sourceIndex) => boolean)

      a filter: only rows it accepts count

        • (sourceIndex): boolean
        • Parameters

          • sourceIndex: number

          Returns boolean

    Returns void

    Example

    result.compute(i => sales[i].monat === "Jan");
    result.getValue(); // 230
  • The number of rows of a cell, a subtotal or a total (after the filter).

    Parameters

    • Optional row: RowGroupIf<T>

      a row group; undefined = all rows

    • Optional column: RowGroupIf<T>

      a column key or group; undefined = all columns

    Returns number

    the row count, 0 for a combination without rows

    Example

    result.getCount(result.rowGroups[0]);   // 3 – the rows of Nord
    
  • The rows behind a cell (drill-down), after the filter, in source order.

    Parameters

    • Optional row: RowGroupIf<T>

      a row group; undefined = all rows

    • Optional column: RowGroupIf<T>

      a column key or group; undefined = all columns

    Returns T[]

    a new array

    Example

    result.getSourceRows(nord, jan).map(s => s.umsatz);   // [100, 50]
    
  • The aggregated value of a cell, a subtotal or a total.

    Parameters

    • Optional row: RowGroupIf<T>

      a row group (any level); undefined = all rows (column totals)

    • Optional column: RowGroupIf<T>

      a column key or column group (any level); undefined = all columns (row totals)

    • Optional value: string | number = 0

      the index or name of the value

    Returns unknown

    the result, undefined if no row has this combination

    Example

    result.getValue(result.rowGroups[0], undefined, "sum(umsatz)");   // the total of the first row group
    
  • True if a column group is shown – false for groups whose keys were all cut off by maxColumns.

    Parameters

    Returns boolean

    true if it has at least one shown column key