@libregrid/pivot
v1.3.5
Published
Client-side pivoting for AG Grid Community — part of LibreGrid
Maintainers
Readme
@libregrid/pivot
Summarize client-side data in a cross-tab view. Group rows, turn distinct values into result columns, and aggregate measures such as sales or quantity. For example, compare sales by country across years.
Install
npm install "ag-grid-community@^36.2.0" @libregrid/pivotRequires ag-grid-community >=36.1.0 <37 as a peer dependency.
@libregrid/row-grouping is installed automatically. Pivot mode reuses its
grouping and aggregation stages.
Usage
In a browser TypeScript project, add a grid container before running the code:
<div id="grid" style="height: 400px"></div>import { ModuleRegistry, AllCommunityModule, createGrid } from 'ag-grid-community';
import { PivotModule } from '@libregrid/pivot';
ModuleRegistry.registerModules([AllCommunityModule, PivotModule]);
const api = createGrid(document.querySelector<HTMLElement>('#grid')!, {
columnDefs: [
{ field: 'country', rowGroup: true, enableRowGroup: true },
{ field: 'product', rowGroup: true, enableRowGroup: true },
{ field: 'year', pivot: true, enablePivot: true },
{ field: 'quarter', pivot: true, enablePivot: true },
{ field: 'sales', aggFunc: 'sum', enableValue: true },
],
rowData: [
{ country: 'United Kingdom', product: 'Widget', year: '2025', quarter: 'Q1', sales: 120 },
],
pivotMode: true,
});Toggle pivot mode at runtime. @libregrid/columns-tool-panel's Columns
panel includes a Pivot Mode switch and Column Labels drop zone for this:
api.setGridOption('pivotMode', !api.getGridOption('pivotMode'));Retrieve a specific pivot intersection column:
const col = api.getPivotResultColumn(['2025', 'Q1'], 'sales');Cap generated columns when pivot values have high cardinality with
pivotMaxGeneratedColumns.
API
| Export | Purpose |
| ------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------- |
| PivotModule | Registers the feature (moduleName: 'Pivot'). |
| PivotStage | Client-side row model pipeline stage that generates result columns — see docs/reference/api-seams.md §6. |
| PivotColsService | Tracks which columns are in the pivot drop zone. |
| PivotResultColsService, createGeneratedPivotDefs, generatedPivotColumnId | Generated result-column management. |
| PivotColDefService | Builds ColDefs for generated pivot columns. |
Learn more
- LibreGrid README — full package list and quick start
@libregrid/row-grouping— grouping and aggregation this feature builds on@libregrid/server-side-row-model— server-side pivot for large data sets
Angular
Use the same column definitions and grid options with ag-grid-angular.
Register the modules shown above through provideLibreGrid from
@libregrid/angular. See the
Angular setup for a complete component and bootstrap example.
License
MIT — see LICENSE and NOTICE. LibreGrid is an independent project and is not affiliated with, endorsed by, or sponsored by AG Grid Ltd.
