DocEngine

Field types · Pivot table

Pivot table pivotTable

Auto-pivot / cross-tab field: at mapping time DocEngine reads a source array, groups by row/column properties, aggregates values, and stores a structured matrix — read-only in fill mode.

At a glance

  • Schema type: pivotTable
  • Value: { columns, rows, columnTotals?, grandTotal? }
  • Use when: Cross-tabs from line items (region × product totals, matrix reports).

Type properties

Options that appear only for Pivot table fields. Shared options (Label, Field Name, Required, …) are on Field types → Common properties.

Row property
Path on each source-array element used for row labels (e.g. Region or Item__r.Name). Bind the array in Field Mapping.
Column property
Path on each element used for column headers (e.g. Product).
Value property
Path of the numeric (or aggregatable) value on each element (e.g. Amount).
Aggregation
How values combine in each cell: Sum, Count, Average, Min, Max, or First.
Sort rows
Order of row labels: Ascending, Descending, or None.
Sort columns
Order of column headers: Ascending, Descending, or None.
Empty cell
Placeholder shown when a matrix cell has no aggregated value (blank by default).
Value align
Horizontal alignment for aggregation and total cells only — column headers stay left-aligned (Left / Center / Right).
Show row totals
When on, adds a total column for each row.
Show column totals
When on, adds a totals row across columns.
Show grand total
When on, shows the bottom-right grand total — intersection of row totals and column totals.
Display format
How the value appears in the document, preview, and PDF: Plain, Number, or Currency. The stored value stays a plain number.
Currency
ISO currency code (e.g. EUR) when Display format is Currency.
Fraction digits
Decimal places for Number / Currency display. Leave blank for auto.
Suffix
Text appended after the formatted value (e.g. mmHg). Hidden when Display format is Currency.

Details

  • Inserted as a table block (insertion: "table", palette label "Pivot Table").
  • editableInFill is false — users do not edit cells; the matrix is produced by Mapping from a source array.
  • Configure rowProperty, columnProperty, valueProperty, and aggregation on the schema; bind the array with a Mapping rule that uses sourceArrayPath (no columnKey).
  • Rendered as a read-only table.vision-table.pivot-table inside .document-table--pivot; PDF uses the existing vision-table converter.
  • Display format / currency / fraction digits / suffix format aggregation and total cells only — stored pivot numbers stay unformatted.

Schema

TypeScript (editor package)

type PivotAggregation = 'sum' | 'count' | 'avg' | 'min' | 'max' | 'first';
type PivotSort = 'asc' | 'desc' | 'none';

interface PivotTableFieldSchema extends FieldSchemaBase {
  type: 'pivotTable';
  rowProperty?: string;
  columnProperty?: string;
  valueProperty?: string;
  aggregation?: PivotAggregation;   // default 'sum'
  showRowTotals?: boolean;
  showColumnTotals?: boolean;
  showGrandTotal?: boolean;
  emptyCell?: string;
  sortRows?: PivotSort;             // default 'asc'
  sortColumns?: PivotSort;          // default 'asc'
  displayFormat?: 'plain' | 'number' | 'currency';
  currencyCode?: string;            // default 'EUR'
  fractionDigits?: number;
  suffix?: string;
  valueAlign?: 'left' | 'center' | 'right';  // default 'right'
  rowLabelWidth?: string;           // e.g. '8em' or '120px'
}

interface PivotTableValue {
  columns: Array<{ key: string; label: string }>;
  rows: Array<{
    key: string;
    label: string;
    cells: Record<string, number | string | null>;
    rowTotal?: number | string | null;
  }>;
  columnTotals?: Record<string, number | string | null>;
  grandTotal?: number | string | null;
}

Value example

{
  "columns": [
    { "key": "widget", "label": "Widget" },
    { "key": "gadget", "label": "Gadget" }
  ],
  "rows": [
    {
      "key": "north",
      "label": "North",
      "cells": { "widget": 120, "gadget": 80 },
      "rowTotal": 200
    }
  ],
  "columnTotals": { "widget": 120, "gadget": 80 },
  "grandTotal": 200
}

How mapping fills the pivot

One Mapping rule per pivot field. Point sourceArrayPath at the array of line items (or any list of objects). DocEngine walks each element, reads the configured row/column/value property paths, aggregates into the matrix, and writes a PivotTableValue.

Mapping rule

{
  "section": "Main",
  "field": "salesPivot",
  "sourceArrayPath": "$payload.OrderItems"
}

Property paths on array elements

Row, column, and value properties are paths relative to each array element — not full $payload paths. Flat keys (Region, Product, Amount) or nested CRM paths (Item__r.Name) both work.

  • rowProperty — becomes row labels (e.g. Region).
  • columnProperty — becomes column headers (e.g. Product).
  • valueProperty — numeric (or aggregatable) cell input (e.g. Amount).
  • aggregation — sum | count | avg | min | max | first (default sum).

Totals and empty cells

  • Show row totals — optional total column per row.
  • Show column totals — optional totals row across columns.
  • Show grand total — bottom-right cell at the intersection of row and column totals (aggregate of every value).
  • Empty cell — placeholder string when a matrix intersection has no data (blank by default).
  • Value align — Left / Center / Right for aggregation and total cells only; headers stay left-aligned.

Related

Other field types

← All field types