• Pivots rows: groups them by the row fields and by the column fields and aggregates the values of every combination, with subtotals and totals – the engine behind PivotFactory (DOM-free, also usable without a table). One pass over the rows; empty combinations are undefined, averages are computed from sum and count.

    Type Parameters

    • T = any

    Parameters

    • rows: ArrayLike<T>

      the rows (not changed)

    • config: PivotConfigIf<T>

      row fields, column fields, values (see PivotConfigIf)

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

      a filter: only rows it accepts count (index into rows)

        • (sourceIndex): boolean
        • Parameters

          • sourceIndex: number

          Returns boolean

    Returns PivotResult<T>

    the hierarchies and the values

    Example

    // case 1: regions × months, sum of umsatz
    const result = pivotRows(sales, { rowFields: ["region"], columnFields: ["monat"], values: ["umsatz"] });
    result.rowGroups.map(r => `${r.label}: ${result.getValue(r)}`); // ["Nord: 270", "Süd: 180"]
    result.getValue(); // 450

    Example

    // case 3: the average of a column total is the average of its rows
    const avg = pivotRows(sales, { rowFields: ["region"], columnFields: ["monat"],
    values: [{ value: "umsatz", aggregator: "avg" }] });
    const jan = avg.columnLeaves.find(c => c.key === "Jan");
    avg.getValue(undefined, jan); // 76.666… (230 / 3) – not 77.5, the mean of 75 and 80

    Since

    1.1.94