View as Markdown

Fields and filters

Editors

The calculated field editor with live formula validation, the number format and conditional format dialogs, and the grouping dialog for number ranges, date parts and custom groups, opened from menus, the toolbar or the instance API.

Each editor is a modal dialog with form fields that writes one part of the report model through a cancellable command. The dialogs load on first open, return focus on close and become full-screen sheets below 640 px.

Editor Opened from Writes Instance API
Calculated field toolbar Formatting menu or calculatedField item, value field menu of a calculated field pivotModel.calculatedFields api.openCalculatedFieldEditor(name?)
Number format toolbar Formatting menu or numberFormat item, value field menu pivotModel.formats[measure].number api.openNumberFormatEditor(measure?)
Conditional format toolbar Formatting menu or conditionalFormat item pivotModel.conditionalFormats api.openConditionalFormatEditor()
Grouping "Group…" in the menu of a row or column field pivotModel.groups[field] pivot.openDialog({ kind: 'grouping', field })

api is the PivotTable ref (PivotTableApi); with a shared store, pivot.openDialog({ kind: 'calculatedField', name: null }) (and numberFormat, conditionalFormat, grouping) does the same. The dialogs render inside the mounted PivotTable that uses the store.

The engine side of each (formula language, format options, rule matching, group semantics) is in Calculated fields, Aggregation and Grouping.

Where an editor or a rule takes a measure, it is the value field's measure id: its field, or field#aggregate when the same field is summarized twice (amount#sum, amount#average; measureId() in @salmonui/pivot-table/engine). A calculated field's measure id is its name.

Calculated field

The editor has a name, an optional caption and a formula textbox:

"Sum(revenue)" - "Sum(cost)"
IF("Sum(units)" > 0, "Sum(revenue)" / "Sum(units)", 0)

The formula is compiled on every keystroke by the engine's parser (no eval, no new Function, so it runs under a strict CSP); an error shows under the field with its message (aria-invalid, role="alert") and disables OK. Opening it for an existing field edits that field, with a Remove button; a new field is added to the values. From code:

pivot.setCalculatedField('margin', { name: 'margin', caption: 'Margin', formula: '"Sum(revenue)" - "Sum(cost)"' }, { addToValues: true });
pivot.setCalculatedField('margin', null); // remove

onBeforeCalculatedFieldChange (cancellable) and onCalculatedFieldChange receive { name, calculatedField, previous }.

Number format

Pick a measure, a style (decimal, currency, percent), decimals, digit grouping and a currency code. OK writes Intl.NumberFormat options:

pivot.setFormat('revenue', { number: { style: 'currency', currency: 'EUR', maximumFractionDigits: 0 } });

Date member formats are formats[field].date (Intl.DateTimeFormat options), set in the model.

Conditional format

A list of rules, each with a measure (or every value field), an operator, one or two values and a tone (accent, success, warning, danger, neutral); Add condition and Remove condition edit the list, OK writes it. Tones are colored from the five theme seeds; rules written in code may instead set a className or a style:

pivot.setConditionalFormats([
  { measure: 'revenue', operator: 'lessThan', value: 0, tone: 'danger' },
  { measure: 'revenue', operator: 'greaterThan', value: 50_000, className: 'top-seller', applyGrandTotals: false },
]);

The same rules color the cells of an XLSX export (Export).

Grouping

"Group…" opens the grouping dialog for the field's type:

  • Number fields: start, end and interval ({ kind: 'number', start, end, interval }).
  • Date fields: start, end and the date parts: years, quarters, quarter and year, months, days, hours, minutes, seconds ({ kind: 'date', parts }).
  • Other fields: check members, name the group and add it ({ kind: 'custom', groups }).

"Ungroup" in the field menu removes the grouping. From code:

pivot.setGrouping('orderDate', { kind: 'date', parts: ['years', 'quarters'] });
pivot.setGrouping('age', { kind: 'number', start: 0, end: 100, interval: 10 });
pivot.setGrouping('age', null);

Every editor's change also fires onBeforePivotModelChange / onPivotModelChange with action calculatedField, format, conditionalFormat or group (State and events).

Field list popup and editors

Open demo

The built-in popup field list with its field menus, and the calculated field, number format and conditional format dialogs, opened from the toolbar and from the instance API.

Region / Country
2025
2026
Grand total
Amount
Average price
Amount
Average price
Amount
Average price
Americas
$4,099
$70.67
$4,320
$96.00
$8,419
$81.74
Asia
$4,095
$91.00
$4,206
$84.12
$8,301
$87.38
Europe
$5,445
$83.77
$3,154
$92.76
$8,599
$86.86
Grand total
$13,639
$81.18
$11,680
$90.54
$25,319
$85.25
Open the field list or an editor from the toolbar, or from the buttons above.