Pivot table
Summarises flat rows by the fields set on rows and columns, with subtotals, totals, sorting, a heatmap and a field list.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
data | unknown[] | [] | The rows to summarise. |
rows | string[] | [] | The fields grouped down the side, outermost first. |
columns | string[] | [] | The fields grouped across the top, outermost first. |
values | PivotValue[] | [] | The measures: { field, aggregate, label, format }. |
invert-signs | Record<string, string[]> | {} | Row groups whose numbers count with the opposite sign, by field: { "section": ["Expenses", "Taxes"] }. They show
negative and subtract in every subtotal and total above them, as costs do under revenue in an income statement. |
field-labels | Record<string, string> | {} | Labels for fields, by field name, used in headers and the field list. |
expand-depth | number | 1 | How many row levels start open. |
subtotals | 'bottom' | 'top' | 'none' | bottom | Where an open group's subtotal goes: bottom, top or none. |
totals | 'both' | 'rows' | 'columns' | 'none' | both | Which grand totals to show: both, rows, columns or none. |
heatmap | boolean | false | Tints each cell by its value within its measure. |
configurable | boolean | false | Shows the field list, so the reader can change the layout. |
label | string | — | The grid's accessible name. |
locale | string | — | The locale for numbers; the nearest lang when empty. |
Events
| Name | Type | Description |
|---|---|---|
cell-click | CustomEvent<PivotCellClickEventDetail> | A value cell was clicked, or Enter was pressed on it. |
pivot-change | CustomEvent<PivotConfig> | The reader changed the layout from the field list. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
field-list | The field list beside the grid. |
chip | A field in the field list. |
scroll | The box the grid scrolls in. |
table | The grid. |
header | A column header. |
row-header | A row header. |
cell | A value cell. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-pivot-table--max-height | length | none | The grid scrolls past this height, its headers sticky. |
--c2-pivot-table--font-size | font-size | 13px | |
--c2-pivot-table--color | color | #18181b | |
--c2-pivot-table--background-color | color | #ffffff | |
--c2-pivot-table--border-radius | border-radius | 8px | |
--c2-pivot-table__border--color | color | #e4e4e7 | |
--c2-pivot-table__cell--padding | padding | 6px 12px | |
--c2-pivot-table__header--background-color | color | #fafafa | |
--c2-pivot-table__header--color | color | #18181b | |
--c2-pivot-table__subtotal--background-color | color | #fafafa | |
--c2-pivot-table__total--background-color | color | #f4f4f5 | |
--c2-pivot-table__total--font-weight | font-weight | 600 | |
--c2-pivot-table__muted--color | color | #71717a | Empty cells and the corner header. |
--c2-pivot-table__focus--outline-color | color | rgb(2, 101, 220) | |
--c2-pivot-table__heat--color | color | rgb(2, 101, 220) | The darkest heatmap tint. |
--c2-pivot-table__heat--on-color | color | #ffffff | Text on the darker heatmap tints. |
--c2-pivot-table__indent--width | length | 20px | The indent of each row level. |
--c2-pivot-table__field-list--width | pixel | 220px | |
--c2-pivot-table__chip--background-color | color | #ffffff | |
--c2-pivot-table__chip--border | border | 1px solid #e4e4e7 | |
--c2-pivot-table__zone__over--background-color | color | rgba(2, 101, 220, 0.06) | |
--c2-pivot-table__computed__negative--color | color | inherit | A computed value below zero, such as an unfavourable variance. |
--c2-pivot-table__computed__positive--color | color | inherit | A computed value above zero. |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under pivot-table, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
table | Pivot table | — |
total | Total | — |
grandTotal | Grand total | — |
groupTotal | {0} total | {0} group |
valueOf | {0} of {1} | {0} aggregate {1} field |
sum | Sum | — |
count | Count | — |
avg | Average | — |
min | Min | — |
max | Max | — |
distinct | Distinct count | — |
computedOf | {0}: {1} vs {2} | {0} compute {1} a {2} b |
difference | Difference | — |
percent-difference | % difference | — |
ratio | Ratio | — |
fields | Fields | — |
rows | Rows | — |
columns | Columns | — |
values | Values | — |
fieldList | Pivot fields | — |
moveToRows | Move to rows | — |
moveToColumns | Move to columns | — |
moveToValues | Move to values | — |
remove | Remove | — |
fieldOptions | Options for {0} | {0} field |
layout | Rows: {0}. Columns: {1}. Values: {2}. | {0} rows {1} columns {2} values |
none | none | — |
empty | No data | — |
sortBy | Sort by {0} | {0} column |