Skip to content

Pivot Table Plugin

The Pivot plugin transforms flat data into a pivot table view.

import '@toolbox-web/grid/features/pivot';
import '@toolbox-web/grid';
import '@toolbox-web/grid/features/pivot';
import { queryGrid } from '@toolbox-web/grid';
const grid = queryGrid('tbw-grid');
grid.gridConfig = {
columns: [
{ field: 'region', header: 'Region' },
{ field: 'product', header: 'Product' },
{ field: 'quarter', header: 'Quarter' },
{ field: 'sales', header: 'Sales', type: 'number' },
],
features: {
pivot: {
rowGroupFields: ['region', 'product'],
columnGroupFields: ['quarter'],
valueFields: [{ field: 'sales', aggFunc: 'sum', header: 'Total' }],
},
},
};
grid.rows = salesData;
Active Whether pivot is active
Aggregation Aggregation function
Show totals Show row group totals
Show grand total Show grand total row
Show tool panel Show drag-and-drop tool panel
Default expanded Groups expanded by default
Indent width Indent per depth level (px)
Animation Expand/collapse animation

Use the controls to explore the full pivot configuration — toggle active state, totals, grand total, tool panel, default expansion, indent width, aggregation function, and animation style.

See PivotConfig for the full list of options and defaults.

sum, avg, count, min, max, first, last

To use pivot transformation without exposing the tool panel UI to users:

features: {
pivot: {
showToolPanel: false,
rowGroupFields: ['region'],
columnGroupFields: ['quarter'],
valueFields: [{ field: 'sales', aggFunc: 'sum' }],
},
},

The pivot API methods remain available for programmatic control.

The plugin supports animated expand/collapse transitions. Animation respects the grid-level animation.mode setting and can be customized per-plugin:

features: {
pivot: {
rowGroupFields: ['region'],
valueFields: [{ field: 'sales', aggFunc: 'sum' }],
animation: 'slide', // 'slide' | 'fade' | false
},
},

Animation is automatically disabled when animation.mode is 'off' or when the user prefers reduced motion ('reduced-motion' mode with system preference).

const plugin = grid.getPluginByName('pivot');
plugin.expand('North__Widget A'); // expand a specific group by key
plugin.collapse('North'); // collapse a group
plugin.expandAll();
plugin.collapseAll();

The pivot plugin supports CSS custom properties for theming. Override these on tbw-grid or a parent container:

PropertyDefaultDescription
--tbw-pivot-group-bgvar(--tbw-color-row-alt)Group row background
--tbw-pivot-group-hovervar(--tbw-color-row-hover)Group row hover
--tbw-pivot-leaf-bgvar(--tbw-color-bg)Leaf row background
--tbw-pivot-grand-total-bgvar(--tbw-color-header-bg)Grand total row
--tbw-pivot-toggle-hover-bgvar(--tbw-color-row-hover)Toggle button hover
--tbw-pivot-section-bgvar(--tbw-color-panel-bg)Panel section background
--tbw-toggle-size1.25emToggle button size
--tbw-animation-duration200msExpand/collapse animation
tbw-grid {
/* Custom pivot styling */
--tbw-pivot-group-bg: #fff3e0;
--tbw-pivot-grand-total-bg: #ffcc80;
--tbw-pivot-toggle-hover-bg: #ffe0b2;
}

The pivot plugin uses these class names:

ClassElement
.pivot-group-rowGrouped summary row
.pivot-leaf-rowDetail/leaf row
.pivot-grand-total-rowGrand total row
.pivot-grand-total-footerSticky footer container
.pivot-toggleExpand/collapse button
.pivot-labelGroup name display
.tbw-pivot-slide-inRow slide animation
.tbw-pivot-fade-inRow fade animation
AI assistants: For complete API documentation, implementation guides, and code examples for this library, see https://raw.githubusercontent.com/OysteinAmundsen/toolbox/main/llms-full.txt