Data grid
Configure virtualization, filtering, grouping, editing, server row models, range charts, and export in @composerkit/data-grid.
@composerkit/data-grid exports TableCore and createAlignedGridGroup for dense tabular workspaces. It reuses ComposerKit's Button, Checkbox, Input, and Base UI primitives under one shared CSS token sheet.
Install it into your app with:
npx shadcn add @composerkit/data-grid --overwrite --yesCapabilities at a glance
| Subsystem | Key props, columns, and handle methods | Notes |
|---|---|---|
| Virtualization and pinning | pinnedRows ({ top, bottom }), pinnedColumns, domLayout, autoHeight, wrapText | Windows rows (100k+) and columns (200+) automatically inside .tablecore-viewport. |
| Filtering and sorting | ColumnDef: sortable, filterable, filterType, multiFilterTypes; props: enableAdvancedFilter | Supports text, number, date, set, multi, and expression-based advanced filters. |
| Hierarchy and pivot | ColumnDef: groupable, pivot, aggFunc, showValuesAs; props: treeData, pivotMode, aggFuncs, stickyGroupRows | Tree mode reads nested RowData.children and preserves selection and expansion by row identity. |
| Editing and clipboard | ColumnDef: editable, editor, editorComponent, validate; props: fullRowEdit, undoRedoCellEditing, undoRedoLimit, cellSelection, enableFormulas, enableNotes | Includes rich-select, batch editing (startBatchEdit, commitBatchEdit, cancelBatchEdit), fill handle (cellSelection.handle), and clipboard copy/cut/paste. |
| Remote row models | rowModelType ("serverSide", "infinite", "viewport") with serverSideDatasource or datasource | Supports block caching, server sort/filter/grouping, transactions, and pushed rows. |
| Charts and export | ColumnDef: sparkline; TableCoreHandle: createRangeChart, getChartImageDataURL, exportDataAsCsv, exportDataAsExcel, exportDataAsPdf | Uses isolated chart.js canvases for inline charts and shared @composerkit/excel for .xlsx. |
| AI state integration | TableCoreHandle: getStructuredSchema(), getGridAiState(), setGridAiState() | Exposes structured filter, sort, group, and column state for model tool calls. |
Virtualization and keyboard contracts
TableCore virtualizes both rows and center columns automatically inside .tablecore-viewport, keeping pinned regions and any currently focused or actively edited cell mounted.
- Set the viewport height with
--tablecore-height(defaults to65vh) and default column width with--tablecore-column-width. - Pin rows with
pinnedRows={{ top, bottom }}(orsetRowPinnedonTableCoreHandle) and pin left columns withpinnedColumns. - Focus uses a single roving
tabIndex={0}stop inside the grid body. Arrow keys,Home,End,Ctrl+Home,Ctrl+End,PageUp, andPageDownnavigate across virtualized and pinned boundaries. - Active editors keep their draft and remain mounted during both-axis scrolling.
TabandShift+Tabcommit and advance across unmounted row and column windows. aria-rowcountandaria-colcountreport logical dimensions including header and pinned regions.
Filtering, grouping, and pagination
- Typed column filters: set
filterable: trueandfilterType("text","number","date","set","multi") onColumnDef, plusmultiFilterTypeswhen combining filters on one column. Text filters debounce automatically while number and date drafts wait for Apply. - Advanced filter bar: enable
enableAdvancedFilterfor an interactive expression bar (Amount > 15 AND Region = "North"), controlled programmatically viasetAdvancedFilterModel()andgetAdvancedFilterModel(). - Grouping and tree data: mark flat columns
groupable: trueor passtreeDatawith nestedRowData.children. Synthetic group rows carryaggFuncrollups (sum,avg,min,max,count,first,last, or customaggFuncs),groupTotalRow/grandTotalRow, andshowValuesAspercentages. - Pagination: set
pageSizeon client-side or server-side grids to bound logical rows before virtualization. In grouped or tree grids, pagination counts root groups or root parents while keeping expanded descendants on their root page.
Server-side, infinite, and viewport row models
Select a remote row model with rowModelType instead of passing rows:
rowModelType | Required datasource props | Behavior |
|---|---|---|
"serverSide" | serverSideDatasource, pageSize, cacheBlockSize | Requests typed blocks (ServerSideRequest), caches blocks, and supports refreshServerSide() and applyServerSideTransaction(). |
"infinite" | datasource (InfiniteDatasource), cacheBlockSize | Loads fixed-size row blocks on demand as the viewport scrolls; inspect or clear with getInfiniteState() and purgeInfiniteCache(). |
"viewport" | datasource (ViewportDatasource) | Subscribes to the visible row range and accepts server-pushed row updates via setRowCount and setRowData. |
Inline charts, sparklines, and export
- Chart boundary:
TableCorekeepschart.jsisolated insidecomponents/data-grid/chart-renderer.tsandcomponents/data-grid/sparkline.tsx. Canvas rendering preserves synchronousgetChartImageDataURL()snapshots for Excel PNG embedding and high-density cell sparklines. For standalone dashboard charts outside the grid, use @composerkit/charts. - Range charts: create and manage charts from
TableCoreHandlewithcreateRangeChart(),getChartModels(),updateChart(),restoreChart(), anddownloadChartImage(). - Excel export:
getDataAsExcel(),exportDataAsExcel(),getMultipleSheetsAsExcel(), andexportMultipleSheetsAsExcel()use ComposerKit's unified@composerkit/excelhelper (write-excel-file/universal) with styled cells, formulas, multi-sheet workbooks, and embedded images. - CSV and PDF export:
getDataAsCsv()/exportDataAsCsv()write CSV, andgetDataAsPdf()/exportDataAsPdf()write standalone binary PDF documents without requiring a browser print dialog.
Styling tokens
Override these CSS custom properties on any container wrapping TableCore:
| Token | Purpose |
|---|---|
--tablecore-height | Scroll viewport max-height (default 65vh). |
--tablecore-column-width | Default virtualized column width. |
--tablecore-pinned-background | Override pinned row and column background (defaults to --grid-pinned). |
--grid-selected | Selected row background fill. |
--grid-range | Cell range selection outline and highlight accent. |
Continue to the Data grid component reference for live demos and generated TypeScript props.