@opencorestack/opengridx 2.0.4 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +408 -3
- package/README.md +93 -72
- package/dist/index.d.ts +611 -121
- package/dist/opengridx.css +1 -1
- package/dist/opengridx.es.js +7992 -5650
- package/dist/opengridx.es.js.map +1 -1
- package/dist/opengridx.umd.js +17 -23
- package/dist/opengridx.umd.js.map +1 -1
- package/docs/API_REFERENCE.md +348 -161
- package/docs/README.md +6 -1
- package/docs/architecture/datagrid-orchestration.md +81 -0
- package/docs/architecture/grid-row-meta.md +102 -0
- package/docs/architecture/use-grid-columns.md +128 -0
- package/docs/architecture/use-grid-controlled-state.md +157 -0
- package/docs/architecture/use-grid-row-pipeline.md +120 -0
- package/docs/architecture/use-grid-scroll-sync.md +111 -0
- package/docs/architecture/use-grid-state-snapshot.md +90 -0
- package/docs/architecture/use-grid-virtualization.md +115 -0
- package/docs/architecture/use-grid-visible-rows.md +85 -0
- package/docs/assets/banner-alt.png +0 -0
- package/docs/assets/banner.png +0 -0
- package/docs/assets/hero.png +0 -0
- package/docs/assets/logo.png +0 -0
- package/docs/components/aggregation-footer.md +15 -10
- package/docs/components/cell.md +16 -6
- package/docs/components/column-group-header.md +55 -28
- package/docs/components/column-resize.md +17 -13
- package/docs/components/column-visibility.md +45 -22
- package/docs/components/datagrid.md +14 -12
- package/docs/components/empty-state.md +2 -1
- package/docs/components/error-overlay.md +12 -7
- package/docs/components/filter-panel.md +28 -8
- package/docs/components/header.md +28 -9
- package/docs/components/pagination.md +14 -8
- package/docs/components/row.md +21 -5
- package/docs/components/toolbar.md +27 -9
- package/docs/components/tooltip.md +16 -7
- package/docs/customization/slots-api.md +100 -36
- package/docs/customization/theming.md +66 -18
- package/docs/features/aggregation-pivot.md +75 -9
- package/docs/features/cell-spanning.md +80 -125
- package/docs/features/clipboard.md +41 -16
- package/docs/features/custom-pagination.md +38 -18
- package/docs/features/data-source.md +36 -13
- package/docs/features/editing-reordering.md +125 -16
- package/docs/features/export-guide.md +147 -41
- package/docs/features/filtering.md +44 -6
- package/docs/features/infinite-scroll.md +54 -46
- package/docs/features/keyboard-navigation.md +83 -0
- package/docs/features/list-view.md +58 -5
- package/docs/features/loading-states.md +18 -20
- package/docs/features/master-detail.md +18 -5
- package/docs/features/pdf-export.md +56 -19
- package/docs/features/pinning.md +23 -5
- package/docs/features/selection.md +50 -10
- package/docs/features/sorting-pagination.md +66 -14
- package/docs/features/state-persistence.md +78 -10
- package/docs/features/toolbar-customization.md +26 -17
- package/docs/features/tree-data-grouping.md +44 -9
- package/docs/features/virtualization.md +64 -15
- package/docs/migration/v1-to-v2.md +115 -0
- package/docs/migration/v2-to-v3.md +1222 -0
- package/docs/performance.md +124 -0
- package/docs/roadmap.md +16 -10
- package/lib/components/Cell/Cell.css +13 -1
- package/lib/components/Cell/Cell.tsx +130 -57
- package/lib/components/Cell/CellErrorBoundary.tsx +12 -6
- package/lib/components/Cell/GridEditInputCell.tsx +114 -41
- package/lib/components/ColumnGroupHeader/ColumnGroupHeader.css +7 -1
- package/lib/components/ColumnResizeHandle/ColumnResizeHandle.css +11 -0
- package/lib/components/ColumnResizeHandle/ColumnResizeHandle.tsx +104 -38
- package/lib/components/ColumnResizeHandle/clampResizeWidth.ts +13 -0
- package/lib/components/ColumnVisibilityPanel/ColumnVisibilityPanel.css +6 -0
- package/lib/components/ColumnVisibilityPanel/ColumnVisibilityPanel.tsx +21 -13
- package/lib/components/DataGrid/DataGrid.css +84 -12
- package/lib/components/DataGrid/DataGrid.tsx +606 -872
- package/lib/components/DataGrid/GridAggregationFooter.tsx +53 -17
- package/lib/components/DataGrid/GridEmptyState.tsx +7 -1
- package/lib/components/DataGrid/GridErrorOverlay.tsx +15 -12
- package/lib/components/DataGrid/GridListView.tsx +166 -23
- package/lib/components/DataGrid/GridLiveRegion.tsx +31 -0
- package/lib/components/DataGrid/GridLoadingOverlay.tsx +27 -0
- package/lib/components/DataGrid/GridPaginationArea.tsx +44 -0
- package/lib/components/DataGrid/GridPinnedRows.tsx +65 -11
- package/lib/components/DataGrid/GridStandaloneColumnPanel.tsx +40 -38
- package/lib/components/DataGrid/GridToolbarSlot.tsx +51 -0
- package/lib/components/DataGrid/GridVirtualRows.tsx +48 -25
- package/lib/components/DetailPanel/DetailPanel.css +0 -6
- package/lib/components/DetailPanel/DetailPanel.tsx +34 -5
- package/lib/components/DetailPanel/DetailPanelContent.tsx +17 -0
- package/lib/components/FilterPanel/FilterPanel.css +13 -2
- package/lib/components/FilterPanel/FilterPanel.tsx +272 -99
- package/lib/components/Header/ColumnMenu.tsx +91 -39
- package/lib/components/Header/Header.css +3 -3
- package/lib/components/Header/Header.tsx +179 -160
- package/lib/components/ListView/ListView.css +25 -0
- package/lib/components/ListView/ListViewRow.tsx +79 -10
- package/lib/components/Pagination/Pagination.tsx +15 -7
- package/lib/components/Row/Row.tsx +185 -75
- package/lib/components/Toolbar/GlobalSearch.css +6 -3
- package/lib/components/Toolbar/GlobalSearch.tsx +26 -27
- package/lib/components/Toolbar/GridToolbar.css +12 -11
- package/lib/components/Toolbar/GridToolbar.tsx +133 -89
- package/lib/components/Toolbar/PivotPanel.tsx +89 -49
- package/lib/components/Tooltip/Tooltip.css +20 -0
- package/lib/components/Tooltip/Tooltip.tsx +68 -35
- package/lib/components/ui/Button.tsx +3 -0
- package/lib/components/ui/Checkbox.tsx +2 -1
- package/lib/components/ui/ExpandIcon.css +0 -9
- package/lib/components/ui/ExpandIcon.tsx +4 -1
- package/lib/hooks/core/gridApiPlaceholder.ts +34 -0
- package/lib/hooks/core/gridToolbarHostContext.ts +14 -0
- package/lib/hooks/core/useDataGrid.ts +115 -173
- package/lib/hooks/core/useGridAggregationApi.ts +72 -0
- package/lib/hooks/core/useGridApiMethods.ts +115 -0
- package/lib/hooks/core/useGridApiRef.ts +15 -3
- package/lib/hooks/core/useGridApiRefBinding.ts +18 -0
- package/lib/hooks/core/useGridAriaRows.ts +38 -0
- package/lib/hooks/core/useGridClipboardApi.ts +38 -0
- package/lib/hooks/core/useGridColumnLookup.ts +30 -0
- package/lib/hooks/core/useGridColumns.tsx +284 -76
- package/lib/hooks/core/useGridColumnsPanel.ts +77 -0
- package/lib/hooks/core/useGridControlledState.ts +99 -6
- package/lib/hooks/core/useGridDetailPanel.ts +51 -0
- package/lib/hooks/core/useGridDevWarnings.ts +123 -0
- package/lib/hooks/core/useGridFocusHandlers.ts +50 -0
- package/lib/hooks/core/useGridGroupingColumn.ts +62 -0
- package/lib/hooks/core/useGridHeaderHandlers.ts +92 -0
- package/lib/hooks/core/useGridHierarchy.ts +81 -0
- package/lib/hooks/core/useGridKeyboardNavigation.ts +452 -250
- package/lib/hooks/core/useGridLiveRowSelection.ts +67 -0
- package/lib/hooks/core/useGridPageCorrection.ts +55 -0
- package/lib/hooks/core/useGridRowIdOf.ts +32 -0
- package/lib/hooks/core/useGridRowInteractions.ts +81 -0
- package/lib/hooks/core/useGridRowPipeline.ts +69 -39
- package/lib/hooks/core/useGridRowSelection.ts +91 -0
- package/lib/hooks/core/useGridScrollSync.ts +80 -32
- package/lib/hooks/core/useGridScrollToIndexesApi.ts +45 -0
- package/lib/hooks/core/useGridStateSnapshot.ts +40 -5
- package/lib/hooks/core/useGridThemeDimensions.ts +49 -0
- package/lib/hooks/core/useGridToolbarProps.ts +97 -0
- package/lib/hooks/core/useGridViewport.ts +38 -0
- package/lib/hooks/core/useGridViewportSize.ts +26 -0
- package/lib/hooks/core/useGridVisibleRows.ts +20 -7
- package/lib/hooks/core/useLayout.ts +215 -195
- package/lib/hooks/core/useRowsScrollEndLatch.ts +41 -0
- package/lib/hooks/core/useStableColumns.ts +34 -0
- package/lib/hooks/features/useAggregation.ts +86 -90
- package/lib/hooks/features/useColumnGroupReorderGuard.ts +34 -0
- package/lib/hooks/features/useDetailPanelHeights.ts +29 -0
- package/lib/hooks/features/useGridClipboard.ts +133 -73
- package/lib/hooks/features/useGridDataSource.ts +354 -128
- package/lib/hooks/features/useGridEditing.ts +211 -51
- package/lib/hooks/features/useGridPivot.ts +92 -0
- package/lib/hooks/features/useGridSpanRenderWindow.ts +104 -0
- package/lib/hooks/features/useGridSpanning.ts +410 -306
- package/lib/hooks/features/usePivot.ts +0 -0
- package/lib/hooks/features/useServerTreeChildren.ts +50 -0
- package/lib/hooks/useColumnReorder.ts +38 -44
- package/lib/hooks/useRowGrouping.ts +335 -214
- package/lib/hooks/useRowReorder.ts +62 -31
- package/lib/hooks/useTreeData.ts +330 -262
- package/lib/index.ts +30 -2
- package/lib/state/index.ts +1 -0
- package/lib/state/types.ts +7 -1
- package/lib/state/useGridStateStorage.ts +88 -29
- package/lib/theme/DataGridThemeProvider.tsx +143 -38
- package/lib/theme/gridThemeContext.ts +5 -0
- package/lib/theme/index.ts +5 -0
- package/lib/theme/presets.ts +5 -4
- package/lib/theme/types.ts +40 -2
- package/lib/types/index.ts +311 -108
- package/lib/utils/aggregation/index.ts +157 -0
- package/lib/utils/aria/index.ts +40 -0
- package/lib/utils/columnGroups.ts +110 -0
- package/lib/utils/columnLookup.ts +33 -0
- package/lib/utils/columnWidth.ts +22 -0
- package/lib/utils/dataSource/index.ts +46 -0
- package/lib/utils/detailPanel.ts +66 -0
- package/lib/utils/dragData.ts +44 -0
- package/lib/utils/editing/index.ts +30 -0
- package/lib/utils/export/exportShared.ts +197 -0
- package/lib/utils/export/exportToExcelAdvanced.ts +344 -121
- package/lib/utils/export/exportToPdf.ts +143 -92
- package/lib/utils/export/groupLabel.ts +14 -0
- package/lib/utils/export/index.ts +278 -272
- package/lib/utils/export/pdfText.ts +50 -0
- package/lib/utils/filtering/index.ts +277 -148
- package/lib/utils/focus/index.ts +115 -0
- package/lib/utils/gridApiRows.ts +35 -0
- package/lib/utils/gridModes.ts +77 -0
- package/lib/utils/grouping/groupedExportRows.ts +91 -0
- package/lib/utils/pagination/index.ts +56 -0
- package/lib/utils/pinning/index.ts +77 -33
- package/lib/utils/pivot/index.ts +368 -0
- package/lib/utils/scroll/index.ts +78 -0
- package/lib/utils/scroll/scrollEnd.ts +18 -0
- package/lib/utils/sorting/index.ts +154 -30
- package/lib/utils/syntheticRows.ts +12 -0
- package/lib/utils/values.ts +206 -0
- package/lib/utils/viewport.ts +14 -0
- package/llms.txt +272 -166
- package/package.json +18 -6
- package/lib/components/ColumnGroupHeader/ColumnGroupHeader.tsx +0 -220
- package/lib/components/ColumnVisibilityPanel/ColumnVisibilityPanel.test.tsx +0 -85
- package/lib/components/DataGrid/DataGrid.regression.test.tsx +0 -132
- package/lib/components/DataGrid/DataGrid.smoke.test.tsx +0 -58
- package/lib/components/DataGrid/DataGrid.v2.test.tsx +0 -127
- package/lib/components/Header/Header.test.tsx +0 -135
- package/lib/components/Pagination/Pagination.test.tsx +0 -64
- package/lib/hooks/core/useDataGrid.regression.test.ts +0 -66
- package/lib/hooks/core/useGridControlledState.test.ts +0 -86
- package/lib/hooks/core/useGridKeyboardNavigation.test.ts +0 -176
- package/lib/hooks/core/useGridRowPipeline.test.ts +0 -117
- package/lib/hooks/features/useAggregation.test.ts +0 -175
- package/lib/hooks/features/usePivot.test.ts +0 -202
- package/lib/hooks/useRowGrouping.test.ts +0 -137
- package/lib/utils/export/exportToPdf.test.ts +0 -120
- package/lib/utils/export/groupedExport.test.ts +0 -144
- package/lib/utils/filtering/filtering.test.ts +0 -178
- package/lib/utils/sorting/sorting.test.ts +0 -88
package/docs/API_REFERENCE.md
CHANGED
|
@@ -12,40 +12,41 @@ The main component for displaying and interacting with data.
|
|
|
12
12
|
#### Props
|
|
13
13
|
| Prop | Type | Default | Description |
|
|
14
14
|
| :--- | :--- | :--- | :--- |
|
|
15
|
-
| `rows` | `
|
|
16
|
-
| `columns` | `GridColDef[]`
|
|
17
|
-
| `getRowId` | `(row:
|
|
18
|
-
| `rowHeight` | `number` | `52` | Height of each row in pixels. |
|
|
19
|
-
| `headerHeight` | `number` | `56` | Height of the header row. |
|
|
15
|
+
| `rows` | `R[]` | — | **Required.** Array of data objects. `R` is your row type: any object type, interfaces included (see [Typing your rows](#typing-your-rows)). Pass `[]` when a `dataSource` supplies the rows. |
|
|
16
|
+
| `columns` | `GridColDef<R>[]` or `GridColDef[]` | — | **Required.** Definitions for the columns: typed for your rows, or untyped. An inline array is fine (v3.0+): while every column is shallowly equal to the previous render's (same properties, callbacks compared by identity) the grid keeps its filter, sort and grouping results. A new inline callback (`valueGetter: (p) => …` written in the render) counts as a change. |
|
|
17
|
+
| `getRowId` | `(row: R) => GridRowId` | `row.id` | Returns a unique identifier for each row. It only keys the grid's internal store: rows reach `renderCell`, events, `apiRef` and `processRowUpdate` unchanged, and the id is never written to `row.id` (v3.0+). Pass it to export functions as `getRowId` when you export `selectedRows`. It must not throw: an id is a programming contract, so a throw is not contained (for a `dataSource` row it fails that request with the error overlay). |
|
|
18
|
+
| `rowHeight` | `number` | `52` | Height of each row in pixels. Without it, an enclosing `DataGridThemeProvider`'s `grid.rowHeightStandard` applies (v3.0+). |
|
|
19
|
+
| `headerHeight` | `number` | `56` | Height of the header row. Without it, the theme's `grid.headerHeight` applies (v3.0+). |
|
|
20
20
|
| `autoHeight` | `boolean` | `false` | Adjust grid height to match row total. |
|
|
21
21
|
| `overscanRowCount` | `number` | `3` | Minimum rows rendered outside the visible viewport. The grid adapts this upward automatically based on scroll velocity — this prop sets the floor. |
|
|
22
|
-
| `loading` | `boolean` | `false` |
|
|
22
|
+
| `loading` | `boolean` | `false` | With no rows, the body shows skeleton rows (or `slots.loadingOverlay`). With rows already shown, they stay and a progress bar runs along the top of the grid (or `slots.loadingOverlay` is shown over them). Works in list view too. |
|
|
23
23
|
| `checkboxSelection` | `boolean` | `false` | Enable row selection via checkboxes. |
|
|
24
|
-
| `pagination` | `boolean` | `false` | Enable the bottom pagination bar. |
|
|
25
|
-
| `paginationMode` | `'client' \| 'server' \| 'infinite'` | `'client'` | How to handle paging. |
|
|
24
|
+
| `pagination` | `boolean` | `false` | Enable the bottom pagination bar. Ignored while `rowGroupingModel` is active (dev-mode warning) and with `paginationMode="infinite"`. |
|
|
25
|
+
| `paginationMode` | `'client' \| 'server' \| 'infinite'` | `'client'` | How to handle paging. `'infinite'` appends rows from the `dataSource` as `paginationModel.page` grows and never shows a pager or slices rows (see [Infinite Scroll](features/infinite-scroll.md)). |
|
|
26
26
|
| `paginationModel` | `GridPaginationModel` | — | Controlled pagination state (`{ page, pageSize }`). |
|
|
27
27
|
| `onPaginationModelChange` | `(model: GridPaginationModel) => void` | — | Fired when page or page size changes. |
|
|
28
|
-
| `pageSizeOptions` | `number[]` | `[10, 25, 50, 100]` | Available page size options. |
|
|
29
|
-
| `rowCount` | `number` | — |
|
|
28
|
+
| `pageSizeOptions` | `number[]` | `[10, 25, 50, 100]` | Available page size options. The uncontrolled default page size is 100 when offered, else the first option. |
|
|
29
|
+
| `rowCount` | `number` | — | Server total for `paginationMode="server"` when you fetch pages yourself (read on every render). With a `dataSource`, the response's `rowCount` is used and this is only the fallback before the first response. |
|
|
30
30
|
| `height` | `number \| string` | `undefined` | Total height of the grid container. |
|
|
31
|
-
| `density` | `'compact' \| 'standard' \| 'comfortable'` | `'standard'` | Visual row density. |
|
|
32
|
-
| `initialState` | `GridInitialState` | `undefined` | Starting state
|
|
33
|
-
| `slots` | `GridSlots` |
|
|
34
|
-
| `slotProps` | `
|
|
35
|
-
| `filterModel` | `GridFilterModel` | `undefined` | Active filters. |
|
|
31
|
+
| `density` | `'compact' \| 'standard' \| 'comfortable'` | `'standard'` | Visual row density: compact = the theme's `grid.rowHeightCompact` or 32 px, standard = `rowHeight`, comfortable = the theme's `grid.rowHeightComfortable` or 72 px. |
|
|
32
|
+
| `initialState` | `GridInitialState` | `undefined` | Starting state (sort, filter, pagination, columns, density), read on mount. Seeds the grid's uncontrolled state; see [State Persistence](features/state-persistence.md). |
|
|
33
|
+
| `slots` | `GridSlots` | — | Custom component overrides: `toolbar`, `pagination`, `noRowsOverlay`, `loadingOverlay`, `footer`. See [`GridSlots`](#gridslots-and-gridslotprops) and the [Slots API](customization/slots-api.md). |
|
|
34
|
+
| `slotProps` | `GridSlotProps` | — | Props passed to the slots, keyed like `slots`. `slotProps.toolbar` is typed as `Partial<GridToolbarProps>` (plus any extra keys your own toolbar reads), so `GridToolbar` render props are type-checked (v3.0+). |
|
|
35
|
+
| `filterModel` | `GridFilterModel` | `undefined` | Active filters (controlled). Omit it to let the grid keep its own filter state, seeded from `initialState.filter` and changed by the toolbar or `apiRef.setFilterModel` (v3.0+). |
|
|
36
36
|
| `sortModel` | `GridSortItem[]` | `undefined` | Active sorting. |
|
|
37
|
-
| `onRowClick` | `(params: GridRowParams) => void` | — | Fired when a row is clicked. |
|
|
38
|
-
| `
|
|
39
|
-
| `
|
|
40
|
-
| `
|
|
37
|
+
| `onRowClick` | `(params: GridRowParams) => void` | — | Fired when a row is clicked. Tree-data parent rows are real rows: a click fires this and selects them (their chevron expands them). Not fired for synthetic rows (row-grouping group rows, subtotal rows, auto-created tree parents): clicking a group row toggles it. |
|
|
38
|
+
| `onRowDoubleClick` | `(params: GridRowParams) => void` | — | Fired when a row is double-clicked (v2.1+). Also fires for group rows, and (v3.0+) for the double-click that opens an editor on an editable cell; not fired on the checkbox, expand icon, drag handle or inside an open editor. |
|
|
39
|
+
| `onCellClick` | `(params: GridCellParams) => void` | — | Fired when a cell is clicked. Not fired for clicks inside an open editor (v3.0+). |
|
|
40
|
+
| `onStateChange` | `(state: GridState) => void` | — | Fired on mount and whenever the value of the sort, filter, pagination, column or density state changes (not on re-renders with equal props). |
|
|
41
|
+
| `processRowUpdate` | `(new, old) => R \| Promise<R>` | — | Called once per committed cell edit (Enter, Tab, blur, or the editor's cell leaving the grid). Return the row to store, or a Promise of it; the editor stays open until the Promise settles. Returning nothing is reported through `onProcessRowUpdateError`. See [Editing](features/editing-reordering.md#commit-and-cancel). |
|
|
41
42
|
| `dataSource` | `GridDataSource` | — | Remote data provider interface. |
|
|
42
43
|
|
|
43
44
|
#### Sorting, Filtering & Pagination
|
|
44
45
|
|
|
45
46
|
| Prop | Type | Default | Description |
|
|
46
47
|
| :--- | :--- | :--- | :--- |
|
|
47
|
-
| `sortingMode` | `'client' \| 'server'` | `'client'` | Set to `'server'` when your backend handles sorting. The grid calls `onSortModelChange` but does not re-sort rows locally. |
|
|
48
|
-
| `filterMode` | `'client' \| 'server'` | `'client'` | Set to `'server'` when your backend handles filtering. The grid calls `onFilterModelChange` but does not re-filter rows locally. |
|
|
48
|
+
| `sortingMode` | `'client' \| 'server'` | `'client'` | Set to `'server'` when your backend handles sorting. The grid calls `onSortModelChange` but does not re-sort rows locally, with or without a `dataSource` (v3.0+). |
|
|
49
|
+
| `filterMode` | `'client' \| 'server'` | `'client'` | Set to `'server'` when your backend handles filtering. The grid calls `onFilterModelChange` but does not re-filter rows locally, with or without a `dataSource` (v3.0+). |
|
|
49
50
|
| `multiSort` | `boolean` | `false` | When `true`, clicking any sortable column header appends/cycles it in the sort model instead of replacing it — no Shift key required. Shift+click always appends regardless of this prop. |
|
|
50
51
|
| `onSortModelChange` | `(model: GridSortItem[]) => void` | — | Fired when the active sort model changes. |
|
|
51
52
|
| `onFilterModelChange` | `(model: GridFilterModel) => void` | — | Fired when the active filter model changes. |
|
|
@@ -57,7 +58,8 @@ The main component for displaying and interacting with data.
|
|
|
57
58
|
| `rowSelectionModel` | `GridRowSelectionModel` | `[]` | Controlled selection state — array of selected row IDs. |
|
|
58
59
|
| `onRowSelectionModelChange` | `(model: GridRowSelectionModel) => void` | — | Fired when the selection changes. |
|
|
59
60
|
| `disableRowSelectionOnClick` | `boolean` | `false` | When `true`, clicking a row does not toggle its selection. |
|
|
60
|
-
| `disableMultipleRowSelection` | `boolean` | `false` | When `true`, at most one row can be selected at a time. |
|
|
61
|
+
| `disableMultipleRowSelection` | `boolean` | `false` | When `true`, at most one row can be selected at a time — by click, checkbox, Space or `apiRef` — and the header select-all checkbox is not shown. |
|
|
62
|
+
| `disableClipboardCopy` | `boolean` | `false` | When `true`, Ctrl+C / Cmd+C does not copy the selected rows, so the page or your own handler owns the shortcut. `apiRef.current.copySelectedRows()` still works. See [Clipboard](features/clipboard.md). |
|
|
61
63
|
|
|
62
64
|
#### Column Visibility
|
|
63
65
|
|
|
@@ -70,11 +72,12 @@ The main component for displaying and interacting with data.
|
|
|
70
72
|
|
|
71
73
|
| Prop | Type | Default | Description |
|
|
72
74
|
| :--- | :--- | :--- | :--- |
|
|
73
|
-
| `disableColumnReorder` | `boolean` | `false` | Disables drag-and-drop
|
|
75
|
+
| `disableColumnReorder` | `boolean` | `false` | Disables drag-and-drop and Columns-panel reordering. A controlled `columnOrder` or `initialState.columns.columnOrder` still applies. |
|
|
74
76
|
| `columnOrder` | `GridColumnOrder` | — | Controlled ordered array of column field names. |
|
|
75
|
-
| `onColumnOrderChange` | `(params: GridColumnOrderChangeParams) => void` | — | Fired after
|
|
77
|
+
| `onColumnOrderChange` | `(params: GridColumnOrderChangeParams) => void` | — | Fired after the user moves one column (header drag or Columns panel drag). Indices are positions in the grid's full column order. |
|
|
78
|
+
| `onColumnOrderModelChange` | `(columnOrder: GridColumnOrder) => void` | — | Fired with the whole new column order after every change, including the Columns panel's **Reset**. Use it to keep a controlled `columnOrder` in sync (v3.0+). Not fired for generated pivot columns. |
|
|
76
79
|
| `rowReordering` | `boolean` | `false` | Enables drag-and-drop row reordering. |
|
|
77
|
-
| `onRowOrderChange` | `(params: GridRowOrderChangeParams) => void` | — | Fired after a row is dragged
|
|
80
|
+
| `onRowOrderChange` | `(params: GridRowOrderChangeParams) => void` | — | Fired after a row is dragged onto another row. Indices are positions in your `rows` prop. |
|
|
78
81
|
|
|
79
82
|
#### Pinning
|
|
80
83
|
|
|
@@ -82,7 +85,7 @@ The main component for displaying and interacting with data.
|
|
|
82
85
|
| :--- | :--- | :--- | :--- |
|
|
83
86
|
| `pinnedColumns` | `GridColumnPinning` | — | Columns pinned to the left or right viewport edges. See [Column & Row Pinning](#-column--row-pinning). |
|
|
84
87
|
| `onPinnedColumnsChange` | `(model: GridColumnPinning) => void` | — | Fired when column pinning changes. |
|
|
85
|
-
| `pinnedRows` | `GridRowPinning` | — | Row IDs pinned to the top or bottom of the viewport. |
|
|
88
|
+
| `pinnedRows` | `GridRowPinning` | — | Row IDs pinned to the top or bottom of the viewport. Pinned rows still have to pass the filter. Ignored (with a development warning) under tree data and row grouping, where the rows stay in the hierarchy. |
|
|
86
89
|
| `pinCheckboxColumn` | `boolean` | `true` | Keeps the checkbox column visible during horizontal scrolling. |
|
|
87
90
|
| `pinExpandColumn` | `boolean` | `true` | Keeps the Master-Detail expansion column visible during horizontal scrolling. |
|
|
88
91
|
|
|
@@ -90,15 +93,15 @@ The main component for displaying and interacting with data.
|
|
|
90
93
|
|
|
91
94
|
| Prop | Type | Default | Description |
|
|
92
95
|
| :--- | :--- | :--- | :--- |
|
|
93
|
-
| `isCellEditable` | `(params: GridCellParams) => boolean` | — | Per-cell predicate. Return `false` to make a specific cell read-only even when the column has `editable: true`. |
|
|
94
|
-
| `onProcessRowUpdateError` | `(error: unknown) => void` | — | Fired if `processRowUpdate` throws
|
|
96
|
+
| `isCellEditable` | `(params: GridCellParams) => boolean` | — | Per-cell predicate. Return `false` to make a specific cell read-only even when the column has `editable: true`. Applies to double-click, Enter, Tab stops and `aria-readonly` (v3.0+). It can only restrict: a column without `editable: true` is never editable. A predicate that throws counts as `false`. |
|
|
97
|
+
| `onProcessRowUpdateError` | `(error: unknown) => void` | — | Fired if `processRowUpdate` (or `valueSetter`) throws, returns a rejected Promise, or returns something that is not a row. The editor stays open with the pending value. Use to display validation errors. |
|
|
95
98
|
|
|
96
99
|
#### Master-Detail
|
|
97
100
|
|
|
98
101
|
| Prop | Type | Default | Description |
|
|
99
102
|
| :--- | :--- | :--- | :--- |
|
|
100
103
|
| `getDetailPanelContent` | `(params: GridDetailPanelParams) => ReactNode` | — | Returns the JSX content rendered inside the expandable detail panel. |
|
|
101
|
-
| `getDetailPanelHeight` | `(params: GridDetailPanelParams) =>
|
|
104
|
+
| `getDetailPanelHeight` | `(params: GridDetailPanelParams) => GridDetailPanelHeight` | `200` | Panel height in pixels (`0` is a 0px panel), or `'auto'` to fit the content. An `'auto'` panel is measured when it renders and whenever its size changes, and the rows below it are laid out at that height. Without this prop every panel is a fixed 200px scroll box. A callback that throws gets the 200px default (v3.0+, with a one-time development warning). |
|
|
102
105
|
| `detailPanelExpandedRowIds` | `Set<GridRowId>` | — | Controlled set of currently-expanded detail panel row IDs. |
|
|
103
106
|
| `onDetailPanelExpandedRowIdsChange` | `(ids: Set<GridRowId>) => void` | — | Fired when detail panels expand or collapse. |
|
|
104
107
|
|
|
@@ -107,8 +110,8 @@ The main component for displaying and interacting with data.
|
|
|
107
110
|
| Prop | Type | Default | Description |
|
|
108
111
|
| :--- | :--- | :--- | :--- |
|
|
109
112
|
| `treeData` | `boolean` | `false` | Enables hierarchical tree data display. |
|
|
110
|
-
| `getTreeDataPath` | `(row: R) => string[]` | — | Returns the hierarchy path for a row (e.g. `['Engineering', 'Frontend']`). |
|
|
111
|
-
| `groupingColDef` | `Partial<GridColDef
|
|
113
|
+
| `getTreeDataPath` | `(row: R) => string[]` | — | Returns the hierarchy path for a row (e.g. `['Engineering', 'Frontend']`). Required with `treeData`: without it the rows are shown flat. Keep its identity stable (module scope or `useCallback`); a new function rebuilds the tree. It must not throw (a throw is not contained). |
|
|
114
|
+
| `groupingColDef` | `Partial<GridColDef<R>>` | — | Configures the dedicated `__group__` column prepended at position 0 (auto-pinned left) when row grouping or tree data is active. Under tree data its cells show the last segment of each row's `getTreeDataPath` (override with `groupingColDef.valueGetter`). Accepts `headerName`, `width`, `renderCell`, and any non-system `GridColDef` field. Its `renderCell` is called for group rows too (check `params.rowMeta?.isGroupRow`); its output replaces the default group label next to the toggle, and returning `undefined` for a group row keeps the default label. The column's `field` is always `'__group__'` (no `field` is needed; one you pass is ignored); it is never sorted, filtered, pinned by the user, exported, hidden, or re-ordered. Defaults: `headerName: 'Group'`, `width: 220`. |
|
|
112
115
|
| `defaultGroupingExpansionDepth` | `number` | `0` | Number of tree levels expanded on initial render (`-1` = all). |
|
|
113
116
|
|
|
114
117
|
#### Row Grouping & Aggregation
|
|
@@ -118,13 +121,13 @@ The main component for displaying and interacting with data.
|
|
|
118
121
|
| `rowGroupingModel` | `GridRowGroupingModel` | `[]` | Array of field names to group rows by (e.g. `['department', 'team']`). See [Row Grouping](#️-row-grouping). |
|
|
119
122
|
| `aggregationModel` | `GridAggregationModel` | — | Map of `field → aggFn` (e.g. `{ salary: 'sum', age: 'avg' }`). See [Aggregation Reference](#-aggregation-reference). |
|
|
120
123
|
| `onAggregationModelChange` | `(model: GridAggregationModel) => void` | — | Fired when the aggregation model changes. |
|
|
121
|
-
| `getAggregationPosition` | `(groupNode: GridTreeNode \| null) => 'inline' \| 'footer' \| null` | — | Controls where aggregation results appear. `'inline'` =
|
|
124
|
+
| `getAggregationPosition` | `(groupNode: GridTreeNode \| null) => 'inline' \| 'footer' \| null` | — | Controls where aggregation results appear. Called for every group node (with its current `isExpanded`) and once with `null` for the grand total. `'inline'` (group default) = on the group row, `'footer'` = on a subtotal row after the group's children while it is expanded (on the group row while collapsed), `null` = hidden. For the grand total, `null` hides the footer row. A callback that throws gets the default (`'inline'` for a group, `'footer'` for the grand total; v3.0+). See [the callback](#getaggregationposition-callback). |
|
|
122
125
|
|
|
123
126
|
#### Pivot
|
|
124
127
|
|
|
125
128
|
| Prop | Type | Default | Description |
|
|
126
129
|
| :--- | :--- | :--- | :--- |
|
|
127
|
-
| `pivotMode` | `boolean` | `false` | Switches the grid to multidimensional Pivot Mode. |
|
|
130
|
+
| `pivotMode` | `boolean` | `false` | Switches the grid to multidimensional Pivot Mode (client-side: ignored when a `dataSource` is set; tree data and row grouping are turned off while pivoting). See [Aggregation & Pivot](features/aggregation-pivot.md#-pivot-mode). |
|
|
128
131
|
| `pivotModel` | `GridPivotModel` | — | Controlled pivot configuration (row fields, column fields, value fields). |
|
|
129
132
|
| `onPivotModelChange` | `(model: GridPivotModel) => void` | — | Fired when the pivot model changes. |
|
|
130
133
|
|
|
@@ -132,7 +135,7 @@ The main component for displaying and interacting with data.
|
|
|
132
135
|
|
|
133
136
|
| Prop | Type | Default | Description |
|
|
134
137
|
| :--- | :--- | :--- | :--- |
|
|
135
|
-
| `onRowsScrollEnd` | `(params: GridRowScrollEndParams) => void` | — | Fired
|
|
138
|
+
| `onRowsScrollEnd` | `(params: GridRowScrollEndParams) => void` | — | Fired once each time the viewport comes within 100px of the bottom of the rows: after a vertical scroll, and also when the rows change while the end is in view (including rows that do not fill the viewport). It fires again only after the viewport leaves that zone or the row count changes; horizontal scrolling never fires it. `listView` follows the same once-per-arrival rule for its list (it re-arms when the list leaves the zone or the row count changes). Use it to load the next page in infinite-scroll mode. |
|
|
136
139
|
|
|
137
140
|
#### Accessibility & Appearance
|
|
138
141
|
|
|
@@ -147,7 +150,7 @@ The main component for displaying and interacting with data.
|
|
|
147
150
|
|
|
148
151
|
| Prop | Type | Default | Description |
|
|
149
152
|
| :--- | :--- | :--- | :--- |
|
|
150
|
-
| `localeText` | `GridLocaleText` | — | Override user-visible strings
|
|
153
|
+
| `localeText` | `GridLocaleText` | — | Override user-visible strings: the Pagination labels and the empty-state label (`noRowsLabel`, which wins over the `noRowsLabel` prop). See [`GridLocaleText`](#gridlocaletext). |
|
|
151
154
|
|
|
152
155
|
#### Imperative Ref
|
|
153
156
|
|
|
@@ -159,7 +162,7 @@ The main component for displaying and interacting with data.
|
|
|
159
162
|
|
|
160
163
|
| Prop | Type | Default | Description |
|
|
161
164
|
| :--- | :--- | :--- | :--- |
|
|
162
|
-
| `listView` | `boolean` | `false` | Renders the grid as a single-column list of cards. Designed for mobile and responsive layouts. |
|
|
165
|
+
| `listView` | `boolean` | `false` | Renders the grid as a single-column list of cards. Designed for mobile and responsive layouts. Requires `listViewColumn`; without it the grid view is shown and a dev warning is logged. |
|
|
163
166
|
| `listViewColumn` | `GridListViewColDef` | — | Column definition for list view mode. Must provide a `renderCell` function. The `field` value is used as a key. |
|
|
164
167
|
|
|
165
168
|
#### Column Group Headers
|
|
@@ -168,11 +171,57 @@ The main component for displaying and interacting with data.
|
|
|
168
171
|
| :--- | :--- | :--- | :--- |
|
|
169
172
|
| `columnGroupingModel` | `GridColumnGroupingModel` | — | Defines spanning header rows above the regular column headers. See [Column Group Headers](#️-column-group-headers). |
|
|
170
173
|
|
|
174
|
+
### Typing your rows
|
|
175
|
+
|
|
176
|
+
`DataGrid` and every generic type (`GridColDef<R>`, `GridRenderCellParams<R>`, `GridRowParams<R>` …) take your row type `R`. Since v3.0 `R` can be any object type (`GridValidRowModel`), so your own interfaces work directly: they need no index signature and do not have to extend `GridRowModel`. `R` is inferred from `rows`.
|
|
177
|
+
|
|
178
|
+
```tsx
|
|
179
|
+
import { DataGrid } from '@opencorestack/opengridx';
|
|
180
|
+
import type { GridColDef } from '@opencorestack/opengridx';
|
|
181
|
+
|
|
182
|
+
interface Employee { id: number; name: string; salary: number }
|
|
183
|
+
|
|
184
|
+
// Typed columns: callbacks see `params.row` as Employee.
|
|
185
|
+
const columns: GridColDef<Employee>[] = [
|
|
186
|
+
{ field: 'name', renderCell: ({ row }) => row.name.toUpperCase() },
|
|
187
|
+
{ field: 'salary', valueGetter: ({ row }) => row.salary * 12,
|
|
188
|
+
valueSetter: ({ row, value }) => ({ ...row, salary: Number(value) / 12 }) },
|
|
189
|
+
];
|
|
190
|
+
|
|
191
|
+
<DataGrid rows={employees} columns={columns} onRowClick={({ row }) => console.log(row.name)} />;
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
- **Untyped columns** (`GridColDef[]`, as in the README) work with rows of any type. Their callbacks see `params.row` as `GridRowModel` (any key, read as `unknown`). The `DataGridUntypedColumnsProps<R>` type describes these props.
|
|
195
|
+
- **Inline column arrays** (`columns={[{ field: 'name', renderCell: ({ row }) => … }]}`) get `R` from `rows`.
|
|
196
|
+
- **Rows without an `id`** need `getRowId`, e.g. `getRowId={(row) => row.code}`.
|
|
197
|
+
- A `GridColDef<Row>` for a type-alias row (or an interface that extends `GridRowModel`) can be used where a `GridColDef` is expected: the row callbacks are declared as methods, so they are checked bivariantly.
|
|
198
|
+
- `params.value` stays `unknown`; read typed values from `params.row`, or render `params.formattedValue`.
|
|
199
|
+
- The export functions, `usePivot` and `useAggregation` accept the same typed or untyped columns, and their options' `getRowId` takes your row type.
|
|
200
|
+
- `apiRef` methods (`getRow`, `getAllRows` …) return `GridRowModel`: the API object is not generic.
|
|
201
|
+
- For the component's props type, use `DataGridProps<R>`. `React.ComponentProps<typeof DataGrid>` resolves to the untyped-columns overload.
|
|
202
|
+
|
|
203
|
+
### `GridSlots` and `GridSlotProps`
|
|
204
|
+
|
|
205
|
+
The types of the `slots` and `slotProps` props (v3.0+ exports). Each slot is typed with the props the grid passes it, so a slot component with its own typed props (e.g. `function Footer({ rowCount }: { rowCount: number })`) is checked, and an inline slot (`footer: (props) => …`) gets its parameter typed. A function component typed `(props: Record<string, unknown>)` is still accepted; a class, `memo` or `forwardRef` component needs the slot's props type (e.g. `GridToolbarSlotProps`). A prop the grid does not pass (one you supply through `slotProps`) must be optional in your component, or close over it in an inline slot.
|
|
206
|
+
|
|
207
|
+
| Slot | Replaces | Receives |
|
|
208
|
+
| :--- | :--- | :--- |
|
|
209
|
+
| `toolbar` | Nothing by default: renders a toolbar above the grid. Use `GridToolbar` or your own component. | `GridToolbarSlotProps`: the toolbar props the grid owns (see [`GridToolbarProps`](#gridtoolbarprops)) plus `apiRef`, then `slotProps.toolbar`. |
|
|
210
|
+
| `pagination` | The built-in `Pagination` bar (shown with `pagination`). | `GridPaginationSlotProps` (= `PaginationProps`: `page`, `pageSize`, `rowCount`, `pageSizeOptions`, `onPageChange`, `onPageSizeChange`, `localeText`), then `slotProps.pagination`. |
|
|
211
|
+
| `noRowsOverlay` | The empty-state icon and label (shown when there are no rows and the grid is not loading). | `slotProps.noRowsOverlay` only (`GridOverlaySlotProps`). |
|
|
212
|
+
| `loadingOverlay` | The loading indicator: the skeleton rows while loading with no rows, the progress bar while loading with rows shown (the slot is then shown over them). | `slotProps.loadingOverlay` only (`GridOverlaySlotProps`). |
|
|
213
|
+
| `footer` | The pagination area. | `GridFooterSlotProps`: `apiRef`, `aggregationModel`, `aggregationResult`, `rowCount`, `pagination`, `paginationModel`, `pageSizeOptions`, `onPaginationModelChange`, then `slotProps.footer`. `rowCount` is the built-in pager's count (pinned rows excluded, v3.0+); under tree data or row grouping, the filtered data rows. |
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
type GridSlots = NonNullable<DataGridProps['slots']>;
|
|
217
|
+
type GridSlotProps = NonNullable<DataGridProps['slotProps']>;
|
|
218
|
+
```
|
|
219
|
+
|
|
171
220
|
---
|
|
172
221
|
|
|
173
222
|
## 🛠️ `GridToolbar`
|
|
174
223
|
|
|
175
|
-
The built-in toolbar component. Mount it via `slots={{ toolbar: GridToolbar }}`.
|
|
224
|
+
The built-in toolbar component. Mount it via `slots={{ toolbar: GridToolbar }}`. The grid passes the models and change handlers it owns (plus `apiRef`), then spreads `slotProps.toolbar` over them, so any prop below can be set or overridden there (or directly when rendering `GridToolbar` yourself).
|
|
176
225
|
|
|
177
226
|
### `GridToolbarProps`
|
|
178
227
|
|
|
@@ -181,17 +230,18 @@ The built-in toolbar component. Mount it via `slots={{ toolbar: GridToolbar }}`.
|
|
|
181
230
|
| `columns` | `GridColDef[]` | `[]` | Column definitions — injected automatically when used via `slots`. |
|
|
182
231
|
| `baseColumns` | `GridColDef[]` | — | Pre-pivot columns shown in the Pivot panel instead of synthetic pivot columns. |
|
|
183
232
|
| `aggregationModel` | `GridAggregationModel` | `{}` | Current aggregation configuration. |
|
|
184
|
-
| `onAggregationModelChange` | `(model: GridAggregationModel) => void` | — | Called when the user changes aggregation settings. |
|
|
185
|
-
| `pivotModel` | `GridPivotModel` | — | Current pivot configuration.
|
|
186
|
-
| `onPivotModelChange` | `(model: GridPivotModel) => void` | — | Called when the user changes pivot settings. |
|
|
187
|
-
| `filterModel` | `GridFilterModel` | — | Current filter model.
|
|
188
|
-
| `onFilterModelChange` | `(model: GridFilterModel) => void` | — | Called when the user changes filters or the quick-search value. |
|
|
233
|
+
| `onAggregationModelChange` | `(model: GridAggregationModel) => void` | — | Called when the user changes aggregation settings. Presence of this prop renders the Summaries button; the grid always injects it when the toolbar is mounted via `slots`. |
|
|
234
|
+
| `pivotModel` | `GridPivotModel` | — | Current pivot configuration. |
|
|
235
|
+
| `onPivotModelChange` | `(model: GridPivotModel) => void` | — | Called when the user changes pivot settings. Presence of this prop renders the Pivot button; the grid injects it when `pivotMode`, `pivotModel` or `onPivotModelChange` is set. |
|
|
236
|
+
| `filterModel` | `GridFilterModel` | — | Current filter model. |
|
|
237
|
+
| `onFilterModelChange` | `(model: GridFilterModel) => void` | — | Called when the user changes filters or the quick-search value. Its presence renders the search bar and Filter button; the grid always injects it when the toolbar is mounted via `slots` (v3.0+). |
|
|
189
238
|
| `columnVisibilityModel` | `Record<string, boolean>` | `{}` | Current column visibility map. |
|
|
190
|
-
| `onColumnVisibilityModelChange` | `(model: Record<string, boolean>) => void` | — | Called when the user shows or hides a column. Presence renders the Columns button
|
|
239
|
+
| `onColumnVisibilityModelChange` | `(model: Record<string, boolean>) => void` | — | Called when the user shows or hides a column. Presence renders the Columns button; the grid always injects it when the toolbar is mounted via `slots`. |
|
|
240
|
+
| `showNonHideableColumns` | `boolean` | `false` | Show `hideable: false` columns in the Columns panel as disabled rows. |
|
|
191
241
|
| `onColumnReorder` | `(from: string, to: string) => void` | — | Called when the user drags a column in the Columns panel. |
|
|
192
242
|
| `onColumnOrderReset` | `() => void` | — | Called when the user clicks "Reset order" in the Columns panel. |
|
|
193
|
-
| `forceColumnsOpen` | `boolean` | — |
|
|
194
|
-
| `onColumnsPanelClose` | `() => void` | — | Called
|
|
243
|
+
| `forceColumnsOpen` | `boolean` | — | Opens the Columns panel when it becomes `true` (set by `DataGrid` for the column menu's **Manage columns**). If the toolbar slot does not render a `GridToolbar` that receives it, the grid opens its standalone Columns panel instead. |
|
|
244
|
+
| `onColumnsPanelClose` | `() => void` | — | Called whenever the Columns panel closes (its button, a custom button, another panel opening, click-outside or Escape). |
|
|
195
245
|
| `children` | `ReactNode` | — | Content rendered on the **left** side of the toolbar, before the spacer. |
|
|
196
246
|
| `rightContent` | `ReactNode` | — | Content rendered on the **right** side, after all built-in buttons. |
|
|
197
247
|
| `className` | `string` | — | Additional CSS class on the toolbar root `<div>`. Use for visual theme overrides. |
|
|
@@ -218,8 +268,8 @@ Passed to `renderQuickFilter`.
|
|
|
218
268
|
|
|
219
269
|
| Property | Type | Description |
|
|
220
270
|
| :--- | :--- | :--- |
|
|
221
|
-
| `value` | `string` | Current search string. |
|
|
222
|
-
| `onChange` | `(value: string) => void` | Call with the updated string when the input changes. |
|
|
271
|
+
| `value` | `string` | Current search string: `filterModel.quickFilterValues` joined with spaces. |
|
|
272
|
+
| `onChange` | `(value: string) => void` | Call with the updated string when the input changes. The toolbar splits it on whitespace into `quickFilterValues` terms. |
|
|
223
273
|
|
|
224
274
|
---
|
|
225
275
|
|
|
@@ -229,44 +279,50 @@ Access these methods via the `apiRef` prop.
|
|
|
229
279
|
|
|
230
280
|
| Method | Return | Description |
|
|
231
281
|
| :--- | :--- | :--- |
|
|
232
|
-
| `getRow(id)` | `GridRowModel \| null` | Get row data by ID. |
|
|
282
|
+
| `getRow(id)` | `GridRowModel \| null` | Get row data by ID (your row object, unchanged). |
|
|
233
283
|
| `getAllRows()` | `GridRowModel[]` | Get all loaded rows. |
|
|
234
|
-
| `getVisibleRows()` | `GridRowModel[]` | Get rows after filtering/sorting. |
|
|
284
|
+
| `getVisibleRows()` | `GridRowModel[]` | Get the rows on screen after filtering/sorting: pinned-top rows, the current page (or all rows without pagination), pinned-bottom rows. Under row grouping and tree data this is the visible hierarchy, group rows included. |
|
|
235
285
|
| `getColumn(field)` | `GridColDef \| null` | Get column definition by field. |
|
|
236
|
-
| `getVisibleColumns()` | `GridColDef[]` | Get
|
|
237
|
-
| `selectRow(id, isSelected)` | `void` | Set selection for a single row. |
|
|
238
|
-
| `selectRows(ids, isSelected)`| `void` | Set selection for multiple rows. |
|
|
286
|
+
| `getVisibleColumns()` | `GridColDef[]` | Get the columns on screen, in render order (hidden columns excluded): left-pinned, unpinned, right-pinned, as the header shows them (v3.0+; before, pinned columns kept their unpinned position). |
|
|
287
|
+
| `selectRow(id, isSelected = true)` | `void` | Set selection for a single row. Fires `onRowSelectionModelChange`, unless nothing changes (selecting a selected row, deselecting an unselected one; v3.0+). Ids of rows the grid made (group headers, subtotals, auto-created tree parents, the pivot Grand Total) are ignored, as they are for the checkbox, click and keyboard (v3.0+). |
|
|
288
|
+
| `selectRows(ids, isSelected = true)`| `void` | Set selection for multiple rows. With `disableMultipleRowSelection`, selecting keeps only the last id. Same no-op and synthetic-id rules as `selectRow`. |
|
|
239
289
|
| `getSelectedRows()` | `GridRowId[]` | Get IDs of all selected rows. |
|
|
240
|
-
| `sortColumn(field, dir)` | `void` |
|
|
241
|
-
| `getSortModel()` | `GridSortItem[]` | Get
|
|
242
|
-
| `setFilterModel(model)` | `void` |
|
|
243
|
-
| `getFilterModel()` | `GridFilterModel` | Get the
|
|
244
|
-
| `setPage(page)` | `void` | Change current page (0-indexed). |
|
|
245
|
-
| `setPageSize(pageSize)` | `void` | Change the
|
|
246
|
-
| `scrollToIndexes(params)` | `void` | Scroll to specific row/column index. |
|
|
290
|
+
| `sortColumn(field, dir)` | `void` | Sort like a header click: replaces the sort model (or, with `multiSort`, updates/appends that field); `null` removes the field. Fires `onSortModelChange`. |
|
|
291
|
+
| `getSortModel()` | `GridSortItem[]` | Get the sort model the grid is using (controlled or not). |
|
|
292
|
+
| `setFilterModel(model)` | `void` | Set filters. Fires `onFilterModelChange`; with a controlled `filterModel`, update the prop from it. |
|
|
293
|
+
| `getFilterModel()` | `GridFilterModel` | Get the filter model the grid is using (controlled or not). |
|
|
294
|
+
| `setPage(page)` | `void` | Change current page (0-indexed). Fires `onPaginationModelChange`. |
|
|
295
|
+
| `setPageSize(pageSize)` | `void` | Change the page size and go to page 0. Fires `onPaginationModelChange`. |
|
|
296
|
+
| `scrollToIndexes(params)` | `void` | Scroll to specific row/column index. Uses the current layout, also when called from a layout effect right after an update (v3.0+). |
|
|
247
297
|
| `getAllColumns()` | `GridColDef[]` | Get all defined columns. |
|
|
248
|
-
| `getAggregationResult()` | `Record<string, unknown> \| null` | Get current aggregation results. |
|
|
298
|
+
| `getAggregationResult()` | `Record<string, unknown> \| null` | Get current aggregation results (`null` without an `aggregationModel`, and in pivot mode). Live in a parent's `useLayoutEffect` on mount and current after every update (v3.0+; before, it was installed in a passive effect). The same holds for `getAggregationModel()` and `getGroupedExportRows()`. |
|
|
249
299
|
| `getAggregationModel()` | `GridAggregationModel \| null` | Get the active aggregation configuration. |
|
|
250
|
-
| `getAllFilteredRows()` | `GridRowModel[]` | Get
|
|
251
|
-
| `getGroupedExportRows()` | `GridGroupedExportRow[] \| null` | Get a flat ordered list reflecting the active row-grouping tree (group-header, leaf, subtotal, grand-total). Returns `null` when row grouping is not active. |
|
|
252
|
-
| `copySelectedRows()` | `Promise<void>` | Copy selected rows
|
|
300
|
+
| `getAllFilteredRows()` | `GridRowModel[]` | Get every row that passes the filter, sorted, regardless of pagination, including pinned rows. Under row grouping and tree data it returns the data rows (no group rows) in hierarchy order with every group expanded, ordered like the screen (also when sorting by the hierarchy column; v3.0+). With tree data and a filter, ancestors shown only to give a match its context are left out: the result is the set select-all and the aggregation footer act on (v3.0+). Use for full-dataset exports. |
|
|
301
|
+
| `getGroupedExportRows()` | `GridGroupedExportRow[] \| null` | Get a flat ordered list reflecting the active row-grouping tree (group-header, leaf, subtotal, grand-total), sorted and filtered like the screen. Collapsed groups are included with their rows, and subtotals are computed over each group's exported rows. Group-header and subtotal entries carry `groupLabel`, the label the grid shows (v3.0+). Returns `null` when row grouping is not active. |
|
|
302
|
+
| `copySelectedRows()` | `Promise<void>` | Copy every selected row that passes the filter (other pages, collapsed groups and pinned rows included) as TSV, with the visible columns in screen order. Resolves without writing when no selected row is found; rejects when the clipboard write fails. |
|
|
253
303
|
|
|
254
304
|
---
|
|
255
305
|
|
|
256
306
|
## 🌳 Internal Data Structures
|
|
257
307
|
|
|
258
308
|
### `GridTreeNode`
|
|
259
|
-
Used in Tree Data and Row Grouping hierarchies.
|
|
309
|
+
Used in Tree Data and Row Grouping hierarchies. This is what `getAggregationPosition` receives.
|
|
260
310
|
|
|
261
311
|
| Property | Type | Description |
|
|
262
312
|
| :--- | :--- | :--- |
|
|
263
313
|
| `id` | `GridRowId` | Unique ID of the row. |
|
|
264
|
-
| `parentId` | `GridRowId \| null` | ID of the parent node. |
|
|
314
|
+
| `parentId` | `GridRowId \| null` | ID of the parent node (`null` at the root). |
|
|
265
315
|
| `depth` | `number` | Nesting level (0 for root). |
|
|
316
|
+
| `groupingKey` | `string` | The key identifying this node within its parent. |
|
|
317
|
+
| `groupingField` | `string` (optional) | Row grouping: the field this node groups by. |
|
|
318
|
+
| `groupingValue` | `unknown` (optional) | The value this node is grouping by. |
|
|
266
319
|
| `isExpanded` | `boolean` | Current expansion state. |
|
|
267
|
-
| `children` | `GridRowId[]` | IDs of child nodes. |
|
|
268
|
-
| `
|
|
269
|
-
| `aggregatedValues` | `
|
|
320
|
+
| `children` | `GridRowId[]` (optional) | IDs of the direct child nodes. |
|
|
321
|
+
| `label` | `string` (optional) | Display label of the group. |
|
|
322
|
+
| `aggregatedValues` | `Record<string, unknown>` (optional) | Aggregates computed for this group, keyed by field. |
|
|
323
|
+
| `aggregationPosition` | `'inline' \| 'footer' \| null` (optional) | Where this group's aggregates are shown. |
|
|
324
|
+
| `descendantCount` | `number` (optional) | Row grouping: leaf rows in the group that pass the filter (recursive). |
|
|
325
|
+
| `serverChildrenCount` | `number` (optional) | Server-side tree data: the child count the server reported. |
|
|
270
326
|
|
|
271
327
|
---
|
|
272
328
|
|
|
@@ -282,42 +338,46 @@ Defines the behavior and appearance of a single column.
|
|
|
282
338
|
| `field` | `string` | — | **Required.** Unique identifier matching the row object key. |
|
|
283
339
|
| `headerName` | `string` | — | Text shown in the column header cell. |
|
|
284
340
|
| `description` | `string` | — | Tooltip shown on column header hover (rendered as the HTML `title` attribute — improves accessibility). |
|
|
285
|
-
| `width` | `number \| string` |
|
|
286
|
-
| `minWidth` | `number` | — | Minimum width in pixels (enforced during resize). |
|
|
287
|
-
| `maxWidth` | `number` | — | Maximum width in pixels (enforced during resize). |
|
|
288
|
-
| `flex` | `number` | — | Flex grow factor — distributes remaining space proportionally.
|
|
341
|
+
| `width` | `number \| string` | unset: flexes | Fixed width in pixels, or a percentage string (`'30%'`): a share of the width left after the fixed-width columns, the same base for every percentage column. Unset (or `'auto'`), the column behaves like `flex: 1` and shares the free space with the flex columns (at least `minWidth`, 50px by default). Pinned and unpinned columns are sized the same way. Every width, including a manual resize, is clamped to `minWidth` / `maxWidth`. |
|
|
342
|
+
| `minWidth` | `number` | — | Minimum width in pixels (enforced during resize; 50 when omitted, or the column's own width if that is smaller). |
|
|
343
|
+
| `maxWidth` | `number` | — | Maximum width in pixels (enforced during resize; no limit when omitted). |
|
|
344
|
+
| `flex` | `number` | — | Flex grow factor — distributes remaining space proportionally. When both are set, `flex` wins over `width` until the user resizes the column. |
|
|
289
345
|
| `align` | `'left' \| 'center' \| 'right'` | `'left'` | Horizontal alignment of cell content. |
|
|
290
|
-
| `headerAlign` | `'left' \| 'center' \| 'right'` | `
|
|
346
|
+
| `headerAlign` | `'left' \| 'center' \| 'right'` | `align` | Horizontal alignment of the header cell content. Falls back to the column's `align`, then `'left'`. |
|
|
347
|
+
| `zIndex` | `number` | — | CSS `z-index` for the column's cells and header cell (pinned cells default to 3). |
|
|
291
348
|
|
|
292
349
|
#### Data & Type
|
|
293
350
|
|
|
294
351
|
| Property | Type | Default | Description |
|
|
295
352
|
| :--- | :--- | :--- | :--- |
|
|
296
|
-
| `type` | `'string' \| 'number' \| 'date' \| 'boolean' \| 'singleSelect' \| 'image'` | `'string'` | Data type
|
|
297
|
-
| `valueOptions` | `Array<string \| number \| { value: unknown; label: string }>` | — | Allowed values for `type: 'singleSelect'` —
|
|
298
|
-
| `valueGetter` | `(params: GridValueGetterParams) => unknown` | — | Derive a computed value from the row object. Runs before `valueFormatter` and `renderCell`. |
|
|
299
|
-
| `
|
|
353
|
+
| `type` | `'string' \| 'number' \| 'date' \| 'boolean' \| 'singleSelect' \| 'image'` | `'string'` | Data type: sets the default filter operators and, when the column has no `valueFormatter`, the default cell text: `date` shows the local calendar date (`toLocaleDateString()`), `boolean` shows Yes / No, `singleSelect` shows the `valueOptions` label, `image` renders an `<img>` of the URL. `number` and `string` show `String(value)`. The text exporters (CSV, Excel HTML, print, PDF) and list view use the same text. |
|
|
354
|
+
| `valueOptions` | `Array<string \| number \| { value: unknown; label: string }>` | — | Allowed values for `type: 'singleSelect'` — the filter panel offers them as a (multi-)select, and the edit cell uses them; cells and exports show the option's label. |
|
|
355
|
+
| `valueGetter` | `(params: GridValueGetterParams) => unknown` | — | Derive a computed value from the row object. Runs before `valueFormatter` and `renderCell`. Client-side sorting, column filters and the quick filter use this value, and editors start from it (double-click and Enter alike). Keep it pure: the quick filter caches each row's search text per row object and column set. A getter that throws for a row shows an error in that cell and reads as `undefined` for sorting, filtering, aggregation, grouping, pivot and list view (v3.0+, with a one-time development warning per column); before, it crashed the grid once the column was sorted, filtered or aggregated. |
|
|
356
|
+
| `valueSetter` | `(params: GridValueSetterParams) => R` | — | v3.0+. Maps an edited value back onto the row (`{ value, row, field }` → updated row) when an edit is committed. Needed for editable `valueGetter` columns; without it the commit writes `row[field]` and a development warning is logged. |
|
|
357
|
+
| `valueFormatter` | `(params: GridValueFormatterParams) => string` | — | Format the value into a display string (e.g. currency, dates). Does not affect editing, sorting or column filters; the quick filter also searches the formatted text. A formatter that throws leaves the value unformatted (the quick filter searches the raw value; v3.0+). |
|
|
300
358
|
|
|
301
359
|
#### Rendering
|
|
302
360
|
|
|
303
361
|
| Property | Type | Description |
|
|
304
362
|
| :--- | :--- | :--- |
|
|
305
|
-
| `renderCell` | `(params: GridRenderCellParams) => ReactNode` | Fully custom cell renderer. Receives `value`, `row`, `field`, `rowIndex`, `colIndex`. |
|
|
363
|
+
| `renderCell` | `(params: GridRenderCellParams) => ReactNode` | Fully custom cell renderer. Receives `value`, `formattedValue` (v2.1+, the `valueFormatter` output), `row`, `field`, `colDef`, `rowIndex`, `colIndex`, `rowMeta`. |
|
|
306
364
|
| `renderHeader` | `(params: GridRenderHeaderParams) => ReactNode` | Custom header cell renderer. Use for icons, sort indicators, or rich headers. |
|
|
307
|
-
| `renderEditCell` | `(params:
|
|
365
|
+
| `renderEditCell` | `(params: GridRenderEditCellParams) => ReactNode` | Custom editor rendered when the cell enters edit mode. Requires `editable: true`. Receives the `renderCell` params (with `value` = the pending value) plus `onValueChange(value)`, `onCommit()` and `onCancel()` (v3.0+). Errors it throws are contained to the cell. |
|
|
308
366
|
|
|
309
367
|
#### Editing
|
|
310
368
|
|
|
311
369
|
| Property | Type | Default | Description |
|
|
312
370
|
| :--- | :--- | :--- | :--- |
|
|
313
|
-
| `editable` | `boolean` | `false` | Enables inline cell editing. Commit is handled by `DataGrid.processRowUpdate`. |
|
|
371
|
+
| `editable` | `boolean` | `false` | Enables inline cell editing (double-click or Enter). Commit is handled by `DataGrid.processRowUpdate`. Row-grouping group rows and auto-generated tree ancestors are never editable; tree-data parent rows are. |
|
|
314
372
|
|
|
315
373
|
#### Spanning
|
|
316
374
|
|
|
317
375
|
| Property | Type | Description |
|
|
318
376
|
| :--- | :--- | :--- |
|
|
319
|
-
| `colSpan` | `number \| ((params: GridRenderCellParams) => number)` | Number of columns this cell merges horizontally. |
|
|
320
|
-
| `rowSpan` | `number \| ((params: GridRenderCellParams) => number)` | Number of rows this cell merges vertically. |
|
|
377
|
+
| `colSpan` | `number \| ((params: GridRenderCellParams) => number)` | Number of columns this cell merges horizontally: the origin plus the next visible columns in render order, clamped to the end of its pinned section. `params.value` is the `valueGetter` result. |
|
|
378
|
+
| `rowSpan` | `number \| ((params: GridRenderCellParams) => number)` | Number of rows this cell merges vertically, clamped to the end of its row section (top-pinned, scrolling or bottom-pinned rows) and to the first row with an expanded detail panel. |
|
|
379
|
+
|
|
380
|
+
Span values are floored; `Infinity` means "to the end"; `NaN`, `0` and negative values mean no span. A span function that throws is treated as `1` (with a development warning). With both set, the origin covers the whole `colSpan × rowSpan` rectangle. See [Cell Spanning](features/cell-spanning.md).
|
|
321
381
|
|
|
322
382
|
#### Styling
|
|
323
383
|
|
|
@@ -331,16 +391,16 @@ Defines the behavior and appearance of a single column.
|
|
|
331
391
|
| Property | Type | Default | Description |
|
|
332
392
|
| :--- | :--- | :--- | :--- |
|
|
333
393
|
| `sortable` | `boolean` | `true` | Enable/disable sorting for this column. |
|
|
334
|
-
| `filterable` | `boolean` | `true` | Enable/disable filtering for this column. |
|
|
394
|
+
| `filterable` | `boolean` | `true` | Enable/disable filtering for this column. `false` also removes it from the quick-filter search. |
|
|
335
395
|
| `resizable` | `boolean` | `true` | Allow the user to drag-resize this column. |
|
|
336
|
-
| `hideable` | `boolean` | `true` | Allow the user to hide this column
|
|
337
|
-
| `pinnable` | `boolean` | `true` | Allow this column to be pinned via the UI. |
|
|
396
|
+
| `hideable` | `boolean` | `true` | Allow the user to hide this column from the UI. `false` removes it from the Columns panel (unless `showNonHideableColumns`) and removes **Hide Column** from its column menu. |
|
|
397
|
+
| `pinnable` | `boolean` | `true` | Allow this column to be pinned via the UI. `false` removes the pin actions from its column menu. Does not affect drag-reordering (v3.0+). |
|
|
338
398
|
| `disableColumnMenu` | `boolean` | `false` | Hide the column header kebab/context menu. |
|
|
339
|
-
| `exportable` | `boolean` | `true` | Set to `false` to exclude from CSV, Excel, JSON, and Print exports. |
|
|
340
|
-
| `groupable` | `boolean` | `true` | Allow this column to be used as a row grouping dimension. Set to `false` to prevent this field from being grouped, even when it appears in `rowGroupingModel
|
|
341
|
-
| `groupingValueFormatter` | `(params: { field: string; value: unknown }) => string` | — | Custom formatter for group-header labels when this column is the active grouping field. Falls back to `"field: value"` when omitted. |
|
|
342
|
-
| `aggregable` | `boolean` |
|
|
343
|
-
| `availableAggregationFunctions` | `string[]` | all built-ins | Restrict which aggregation functions are computed and available for this column (e.g. `['sum', 'avg']`). Functions outside this list are skipped even if set in `aggregationModel
|
|
399
|
+
| `exportable` | `boolean` | `true` | Set to `false` to exclude from CSV, Excel, JSON, PDF and Print exports (including their subtotals and totals). |
|
|
400
|
+
| `groupable` | `boolean` | `true` | Allow this column to be used as a row grouping dimension. Set to `false` to prevent this field from being grouped, even when it appears in `rowGroupingModel`, or used as a pivot row or column field (the pivot panel does not offer it). |
|
|
401
|
+
| `groupingValueFormatter` | `(params: { field: string; value: unknown }) => string` | — | Custom formatter for group-header labels when this column is the active grouping field. Falls back to `"field: value"` when omitted or when it throws (v3.0+). |
|
|
402
|
+
| `aggregable` | `boolean` | — | Whether this column can be aggregated. Unset, the toolbar's Summaries panel and the pivot panel's value fields offer it only for `type: 'number'` columns; `true` offers it for any type. `false` keeps it out of both panels, and an `aggregationModel` or `pivotModel` entry naming it is ignored (no footer total, group aggregate, pivot value or export total). |
|
|
403
|
+
| `availableAggregationFunctions` | `string[]` | all built-ins | Restrict which aggregation functions are computed and available for this column (e.g. `['sum', 'avg']`). Functions outside this list are skipped even if set in `aggregationModel` or a pivot value field, the toolbar's Summaries panel and the pivot panel offer only these. |
|
|
344
404
|
|
|
345
405
|
---
|
|
346
406
|
|
|
@@ -348,11 +408,35 @@ Defines the behavior and appearance of a single column.
|
|
|
348
408
|
|
|
349
409
|
| Function | Return | Description |
|
|
350
410
|
| :--- | :--- | :--- |
|
|
351
|
-
| `exportToCsv(rows, cols, options?)` | `void` | Triggers download of CSV file. |
|
|
352
|
-
| `exportToJson(rows, cols, options?)` | `void` | Triggers download of JSON file. |
|
|
353
|
-
| `exportToExcel(rows, cols, options?)` | `void` | Basic `.xls` export (zero-dep). |
|
|
354
|
-
| `exportToExcelAdvanced(rows, cols, options?)` | `Promise<void>` | Real `.xlsx` export (styled, multi-sheet, lazy-loaded). |
|
|
355
|
-
| `
|
|
411
|
+
| `exportToCsv(rows, cols, options?)` | `void` | Triggers download of a UTF-8 CSV file (with a byte-order mark and formula escaping by default, v3.0+). |
|
|
412
|
+
| `exportToJson(rows, cols, options?)` | `void` | Triggers download of JSON file. Values, including aggregation values, are raw. |
|
|
413
|
+
| `exportToExcel(rows, cols, options?)` | `void` | Basic `.xls` export (zero-dep HTML table). A `.xlsx` file name is renamed to `.xls` (v3.0+). |
|
|
414
|
+
| `exportToExcelAdvanced(rows, cols, options?)` | `Promise<void>` | Real `.xlsx` export (styled, multi-sheet, lazy-loaded). Accepts `groupedRows` for outlined grouped reports (v2.1+). |
|
|
415
|
+
| `exportToPdf(rows, cols, options?)` | `Promise<void>` | PDF report via the optional `jspdf` + `jspdf-autotable` peers. `font` registers a Unicode font (v3.0+). See [PDF Export](features/pdf-export.md). |
|
|
416
|
+
| `printGrid(rows, cols, titleOrOptions?)` | `Promise<void>` | Opens the browser print dialog. The third argument is a title string or `PrintOptions`. |
|
|
417
|
+
|
|
418
|
+
In every exporter, a non-empty `selectedRows` takes precedence over `groupedRows` (the selected rows are exported flat) and the totals are recomputed over the selected rows (v3.0+). See the [Export Guide](features/export-guide.md#selection-grouping-and-totals).
|
|
419
|
+
|
|
420
|
+
Every exporter takes `columns` typed for your rows (`GridColDef<R>[]`) or untyped (`GridColDef[]`), and its options also accept `getRowId?: (row: R) => GridRowId`. Pass the grid's `getRowId` when you use one: `selectedRows` holds those ids, and since v3.0 the grid no longer copies them onto `row.id`.
|
|
421
|
+
|
|
422
|
+
---
|
|
423
|
+
|
|
424
|
+
## 🧩 Standalone Components
|
|
425
|
+
|
|
426
|
+
The grid's building blocks are exported with their props types (the props types since v3.0). `DataGrid` renders all of them itself; import them to build your own layout or slot.
|
|
427
|
+
|
|
428
|
+
| Component | Props type | Description |
|
|
429
|
+
| :--- | :--- | :--- |
|
|
430
|
+
| `ColumnVisibilityPanel` | `ColumnVisibilityPanelProps` | Controlled column show/hide (and optional reorder) list, for use outside the grid (v2.1+). See [Column Visibility](components/column-visibility.md). |
|
|
431
|
+
| `GridToolbar` | `GridToolbarProps` | The built-in toolbar. See [`GridToolbar`](#️-gridtoolbar). |
|
|
432
|
+
| `Pagination` | `PaginationProps` | The built-in pagination bar (v3.0+ export), e.g. to wrap in a `pagination` slot. See [Pagination](components/pagination.md). |
|
|
433
|
+
| `FilterPanel` | `FilterPanelProps` | The filter rule editor (`filterModel`, `columns`, `onFilterModelChange`). See [Filter Panel](components/filter-panel.md). |
|
|
434
|
+
| `GridTooltip` | `GridTooltipProps` | Tooltip wrapper. See [Tooltip](components/tooltip.md). |
|
|
435
|
+
| `Header` | `HeaderProps` | The column header rows. See [Header](components/header.md). |
|
|
436
|
+
| `Row` | `RowProps` | One body row. See [Row](components/row.md). |
|
|
437
|
+
| `Cell` | `CellProps` | One body cell. See [Cell](components/cell.md). |
|
|
438
|
+
| `Skeleton` | `SkeletonProps` | Loading placeholder (`rows`, `columns`, both default 5). |
|
|
439
|
+
| `Button`, `Input`, `Checkbox` | `ButtonProps`, `InputProps`, `CheckboxProps` | The grid's form controls. `Button` defaults to `type="button"`. |
|
|
356
440
|
|
|
357
441
|
---
|
|
358
442
|
|
|
@@ -362,9 +446,14 @@ Defines the behavior and appearance of a single column.
|
|
|
362
446
|
Context provider for overriding the grid's visual system.
|
|
363
447
|
|
|
364
448
|
#### `GridTheme` Object
|
|
365
|
-
-
|
|
366
|
-
-
|
|
367
|
-
-
|
|
449
|
+
- **`mode`**: `'light'` (default) or `'dark'`: the complete base palette the provider pins before applying the other keys (v3.0+).
|
|
450
|
+
- **`colors`**: `primary`, `primaryDark`, `primaryLight`, `primaryFocus`, `secondary*`, `success`, `warning`, `error`, `info`, `white`, `black`, `gray` (`{ 50 … 900 }`). Toolbar, menu, selection and focus accents derive from `primary*` unless set directly.
|
|
451
|
+
- **`typography`**: `fontFamily`, `fontFamilyMono`, `fontSizeXs` … `fontSizeXl`.
|
|
452
|
+
- **`spacing`**: `xs` … `xxl`. **`borders`**: `widthThin/Medium/Thick`, `radiusSm` … `radiusXl`, `color`, `colorHover`. **`shadows`**: `sm` … `xl`.
|
|
453
|
+
- **`grid`**: surfaces (`background`, `borderColor`, `headerBackground`, `headerText`, `headerHoverBackground`, `headerSortedBackground`, `rowText`, `rowHoverBackground`, `rowAlternateBackground`, `rowSelectedBackground`, `rowSelectedHoverBackground`, `cellFocusBorder`, `pinnedLeftShadow`, `pinnedRightShadow`, `checkboxBg`, `checkboxBorder`), sizing (`rowHeightCompact`, `rowHeightStandard`, `rowHeightComfortable`, `headerHeight` in px, read by the grid's layout; the `rowHeight` / `headerHeight` props win), `cellPaddingX`, `cellPaddingY`, `cellFontSize`, `headerFontSize`.
|
|
454
|
+
- **`toolbar`**, **`overlays`**, **`scrollbar`** (`thumbColor`, `trackColor`, `size`), **`skeleton`** (`baseColor`, `highlightColor`), **`transitions`**.
|
|
455
|
+
|
|
456
|
+
Presets: `darkTheme`, `roseTheme`, `emeraldTheme`, `amberTheme`, `compactTheme`. See [Theming](customization/theming.md).
|
|
368
457
|
|
|
369
458
|
---
|
|
370
459
|
|
|
@@ -374,6 +463,8 @@ Context provider for overriding the grid's visual system.
|
|
|
374
463
|
|
|
375
464
|
Creates a typed ref to pass to the `apiRef` prop. Gives you imperative access to the grid after mount.
|
|
376
465
|
|
|
466
|
+
`apiRef.current` is never `null`: until the grid mounts it holds an API whose methods do nothing and whose getters return empty values. The grid installs the live API in a layout effect, so it is ready in your own `useLayoutEffect` / `useEffect` and in event handlers (v3.0+).
|
|
467
|
+
|
|
377
468
|
```tsx
|
|
378
469
|
import { useGridApiRef } from '@opencorestack/opengridx';
|
|
379
470
|
|
|
@@ -409,10 +500,11 @@ const { aggregationResult, isLoading } = useAggregation({
|
|
|
409
500
|
|
|
410
501
|
| Param | Type | Description |
|
|
411
502
|
| :--- | :--- | :--- |
|
|
412
|
-
| `rows` | `
|
|
503
|
+
| `rows` | `R[]` | The rows to aggregate (already filtered: the hook aggregates every row it is given). Any object row type (v3.0+). |
|
|
413
504
|
| `aggregationModel` | `GridAggregationModel` | Map of `field → aggFn` (e.g. `{ salary: 'sum' }`). |
|
|
414
|
-
| `isServerSide` | `boolean` | If `true`, skips client computation and uses `serverAggregationResults`. |
|
|
415
|
-
| `
|
|
505
|
+
| `isServerSide` | `boolean` | If `true`, skips client computation and uses `serverAggregationResults`, else the result of `dataSource.getAggregations`. The grid sets it whenever a `dataSource` drives the rows (server or infinite pagination, server sorting or server filtering). |
|
|
506
|
+
| `columns` | `GridColDef[]` | Optional — column definitions, so values are read through each column's `valueGetter` and `availableAggregationFunctions` is honoured. |
|
|
507
|
+
| `filterModel` | `GridFilterModel` | Optional — sent to `dataSource.getAggregations`. It does not filter `rows`. |
|
|
416
508
|
| `sortModel` | `GridSortItem[]` | Optional — used when `dataSource` is provided. |
|
|
417
509
|
| `dataSource` | `GridDataSource` | Optional — server-side data adapter for async aggregation. |
|
|
418
510
|
| `serverAggregationResults` | `GridAggregationResult \| null` | Pre-fetched results when `isServerSide: true`. |
|
|
@@ -422,8 +514,8 @@ const { aggregationResult, isLoading } = useAggregation({
|
|
|
422
514
|
| Field | Type | Description |
|
|
423
515
|
| :--- | :--- | :--- |
|
|
424
516
|
| `aggregationResult` | `GridAggregationResult` | Map of `field → computed value`. |
|
|
425
|
-
| `isLoading` | `boolean` | `true` while
|
|
426
|
-
| `error` | `unknown` | Set if the
|
|
517
|
+
| `isLoading` | `boolean` | `true` while the `getAggregations` request for the current model, filter and sort is pending. |
|
|
518
|
+
| `error` | `unknown` | Set if the request for the current model, filter and sort failed. |
|
|
427
519
|
|
|
428
520
|
**Built-in aggregation functions:** `sum`, `avg`, `min`, `max`, `count`, `unique`
|
|
429
521
|
|
|
@@ -433,7 +525,7 @@ You can also use `formatAggregationValue(value, fnName)` to produce a display st
|
|
|
433
525
|
|
|
434
526
|
### `usePivot(rawRows, rawCols, model, enabled)`
|
|
435
527
|
|
|
436
|
-
Headless hook that transforms a flat dataset into pivot rows and pivot column definitions
|
|
528
|
+
Headless hook that transforms a flat dataset into pivot rows and pivot column definitions, with the same engine `<DataGrid pivotMode />` uses. Use it to pivot outside the grid (charts, custom exports). To show a pivot in the grid, prefer `pivotMode`: it also filters the source rows, keeps the Grand Total row last when sorting and leaves it out of select-all, which a grid given `pivotRows` as plain rows does not do.
|
|
437
529
|
|
|
438
530
|
```tsx
|
|
439
531
|
import { usePivot } from '@opencorestack/opengridx';
|
|
@@ -459,7 +551,7 @@ const { pivotRows, pivotColumns, isValid } = usePivot(
|
|
|
459
551
|
|
|
460
552
|
| Param | Type | Description |
|
|
461
553
|
| :--- | :--- | :--- |
|
|
462
|
-
| `rawRows` | `
|
|
554
|
+
| `rawRows` | `R[]` | Original flat dataset. Any object row type (v3.0+); `rawCols` may be `GridColDef<R>[]` or `GridColDef[]`. |
|
|
463
555
|
| `rawCols` | `GridColDef[]` | Original column definitions. |
|
|
464
556
|
| `model` | `GridPivotModel` | Pivot configuration — `rowFields`, `columnFields`, `valueFields`. |
|
|
465
557
|
| `enabled` | `boolean` | When `false`, returns empty arrays immediately (no computation). |
|
|
@@ -468,10 +560,10 @@ const { pivotRows, pivotColumns, isValid } = usePivot(
|
|
|
468
560
|
|
|
469
561
|
| Field | Type | Description |
|
|
470
562
|
| :--- | :--- | :--- |
|
|
471
|
-
| `pivotRows` | `GridRowModel[]` |
|
|
472
|
-
| `pivotColumns` | `GridColDef[]` |
|
|
473
|
-
| `colKeys` | `string[]` | The distinct column
|
|
474
|
-
| `isValid` | `boolean` | `false` if the model
|
|
563
|
+
| `pivotRows` | `GridRowModel[]` | One row per row-field combination (ids `'__pivot_row__:["value", …]'`, from its row-field values), then the Grand Total row (id `'__pivot_grand_total__'`). There is no Grand Total row when `rawRows` is empty. |
|
|
564
|
+
| `pivotColumns` | `GridColDef[]` | Row-label columns (keeping the source column's formatter, renderer, type and alignment; `hideable: false`), then one value column per column key and value field. Value columns format aggregates like the footer. |
|
|
565
|
+
| `colKeys` | `string[]` | The distinct column-field value combinations, ordered by value (numbers numerically, strings naturally, blanks last). `['']` when there are no column fields. |
|
|
566
|
+
| `isValid` | `boolean` | `false` if the model has no usable row field or value field (fields on `groupable: false` columns and value fields whose function `availableAggregationFunctions` does not allow are skipped). |
|
|
475
567
|
|
|
476
568
|
#### `GridPivotModel`
|
|
477
569
|
|
|
@@ -533,7 +625,9 @@ const { initialState, onStateChange, clearState } = useGridStateStorage({
|
|
|
533
625
|
| :--- | :--- | :--- |
|
|
534
626
|
| `initialState` | `GridState \| undefined` | Restored state from storage — pass to `DataGrid.initialState`. |
|
|
535
627
|
| `onStateChange` | `(state: GridState) => void` | Callback to pass to `DataGrid.onStateChange`. |
|
|
536
|
-
| `clearState` | `() => void` | Removes the saved state from storage. |
|
|
628
|
+
| `clearState` | `() => void` | Removes the saved state from storage and cancels a pending write. |
|
|
629
|
+
|
|
630
|
+
If the key can change while the grid stays mounted, remount the grid with it (`<DataGrid key={storageKey} … />`): the grid reads `initialState` only on mount. When the browser blocks storage, the hook falls back to no persistence.
|
|
537
631
|
|
|
538
632
|
---
|
|
539
633
|
|
|
@@ -569,13 +663,19 @@ interface GridPaginationModel {
|
|
|
569
663
|
interface GridPivotModel {
|
|
570
664
|
rowFields: string[];
|
|
571
665
|
columnFields: string[];
|
|
572
|
-
valueFields:
|
|
666
|
+
valueFields: GridPivotValueField[];
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
interface GridPivotValueField {
|
|
670
|
+
field: string;
|
|
671
|
+
aggFn: GridPivotAggFn; // 'sum' | 'avg' | 'count' | 'min' | 'max'
|
|
672
|
+
headerName?: string;
|
|
573
673
|
}
|
|
574
674
|
```
|
|
575
675
|
|
|
576
676
|
### `GridLocaleText`
|
|
577
677
|
|
|
578
|
-
Override user-visible strings in the Pagination component. All fields are optional.
|
|
678
|
+
Override user-visible strings in the Pagination component and the empty state. All fields are optional.
|
|
579
679
|
|
|
580
680
|
```typescript
|
|
581
681
|
interface GridLocaleText {
|
|
@@ -597,26 +697,53 @@ interface GridRowMeta {
|
|
|
597
697
|
groupingField?: string;
|
|
598
698
|
groupingValue?: unknown;
|
|
599
699
|
groupLabel?: string;
|
|
600
|
-
descendantCount?: number;
|
|
700
|
+
descendantCount?: number; // data rows below, at any depth, that pass the filter
|
|
601
701
|
isExpanded?: boolean;
|
|
602
|
-
isGroupRow?: boolean;
|
|
702
|
+
isGroupRow?: boolean; // synthetic row: group, subtotal or auto-created tree parent
|
|
703
|
+
isGroupFooter?: boolean; // v3.0: the subtotal row of a group ('footer' aggregation position)
|
|
603
704
|
}
|
|
604
705
|
```
|
|
605
706
|
|
|
707
|
+
### `GridGroupedExportRow`
|
|
708
|
+
|
|
709
|
+
One entry of the list returned by `apiRef.current.getGroupedExportRows()`, and the element type of every exporter's `groupedRows` option. Traverse in array order to reproduce the grouping.
|
|
710
|
+
|
|
711
|
+
```typescript
|
|
712
|
+
interface GridGroupedExportRow {
|
|
713
|
+
type: 'group-header' | 'leaf' | 'group-subtotal' | 'grand-total';
|
|
714
|
+
depth: number; // 0 = top-level group
|
|
715
|
+
groupField?: string; // absent on 'leaf' and 'grand-total'
|
|
716
|
+
groupValue?: unknown; // absent on 'leaf' and 'grand-total'
|
|
717
|
+
groupLabel?: string; // v3.0: label as the grid shows it ('group-header', 'group-subtotal')
|
|
718
|
+
aggregatedValues?: Record<string, unknown>; // 'group-subtotal' and 'grand-total'
|
|
719
|
+
row?: GridRowModel; // 'leaf' only: your row object
|
|
720
|
+
}
|
|
721
|
+
```
|
|
722
|
+
|
|
723
|
+
### `GridDetailPanelHeight`
|
|
724
|
+
|
|
725
|
+
```typescript
|
|
726
|
+
type GridDetailPanelHeight = number | 'auto';
|
|
727
|
+
```
|
|
728
|
+
|
|
729
|
+
Returned by `getDetailPanelHeight`.
|
|
730
|
+
|
|
606
731
|
---
|
|
607
732
|
|
|
608
733
|
## 📡 Event Callback Types
|
|
609
734
|
|
|
610
735
|
These interfaces describe the parameter objects passed to every event callback prop.
|
|
611
736
|
|
|
737
|
+
Keyboard activation uses the same callbacks: **Enter** on a cell that is not editable runs the row-click handling (`onRowClick`, click-to-select, group expansion). See [Keyboard & Accessibility](features/keyboard-navigation.md) for every key and the ARIA structure.
|
|
738
|
+
|
|
612
739
|
### `GridRowParams<R>`
|
|
613
|
-
Passed to `onRowClick`.
|
|
740
|
+
Passed to `onRowClick` and `onRowDoubleClick`.
|
|
614
741
|
|
|
615
742
|
| Property | Type | Description |
|
|
616
743
|
| :--- | :--- | :--- |
|
|
617
744
|
| `row` | `R` | The full row data object. |
|
|
618
745
|
| `id` | `GridRowId` | Unique identifier of the row. |
|
|
619
|
-
| `rowIndex` | `number` | Zero-based index of the row
|
|
746
|
+
| `rowIndex` | `number` | Zero-based index of the row among the rendered rows: top-pinned, then the current page, then bottom-pinned (the row's `data-rowindex`). |
|
|
620
747
|
|
|
621
748
|
### `GridCellParams<R>`
|
|
622
749
|
Passed to `onCellClick` and `isCellEditable`.
|
|
@@ -627,8 +754,26 @@ Passed to `onCellClick` and `isCellEditable`.
|
|
|
627
754
|
| `field` | `string` | The column field name. |
|
|
628
755
|
| `value` | `unknown` | The cell value (after `valueGetter`, before `valueFormatter`). |
|
|
629
756
|
| `colDef` | `GridColDef<R>` | The column definition. |
|
|
630
|
-
| `rowIndex` | `number` | Zero-based row
|
|
631
|
-
| `colIndex` | `number` | Zero-based column
|
|
757
|
+
| `rowIndex` | `number` | Zero-based index of the row among the rendered rows: top-pinned, then the current page, then bottom-pinned. |
|
|
758
|
+
| `colIndex` | `number` | Zero-based position of the column among the visible data columns in render order (left-pinned, unpinned, right-pinned); system columns are not counted. It does not change with horizontal scrolling (v3.0). |
|
|
759
|
+
|
|
760
|
+
### `GridRenderEditCellParams<R>`
|
|
761
|
+
Passed to `renderEditCell` (v3.0+). Everything in `GridRenderCellParams` (`value` is the pending, uncommitted value), plus:
|
|
762
|
+
|
|
763
|
+
| Property | Type | Description |
|
|
764
|
+
| :--- | :--- | :--- |
|
|
765
|
+
| `onValueChange` | `(value: unknown) => void` | Updates the pending value. Nothing is saved until `onCommit`. |
|
|
766
|
+
| `onCommit` | `() => void` | Commits the pending value through `processRowUpdate` and leaves edit mode. |
|
|
767
|
+
| `onCancel` | `() => void` | Discards the pending value and leaves edit mode. |
|
|
768
|
+
|
|
769
|
+
### `GridValueSetterParams<R>`
|
|
770
|
+
Passed to `valueSetter` (v3.0+).
|
|
771
|
+
|
|
772
|
+
| Property | Type | Description |
|
|
773
|
+
| :--- | :--- | :--- |
|
|
774
|
+
| `value` | `unknown` | The committed value from the editor. |
|
|
775
|
+
| `row` | `R` | The row as it was before the edit. |
|
|
776
|
+
| `field` | `string` | The column field name. |
|
|
632
777
|
|
|
633
778
|
### `GridColumnOrderChangeParams`
|
|
634
779
|
Passed to `onColumnOrderChange`.
|
|
@@ -636,25 +781,27 @@ Passed to `onColumnOrderChange`.
|
|
|
636
781
|
| Property | Type | Description |
|
|
637
782
|
| :--- | :--- | :--- |
|
|
638
783
|
| `column` | `GridColDef` | The column definition that was moved. |
|
|
639
|
-
| `oldIndex` | `number` |
|
|
640
|
-
| `targetIndex` | `number` |
|
|
784
|
+
| `oldIndex` | `number` | The column's position before the move, in the grid's full column order: every current column (hidden ones and the row-grouping `__group__` column included), in its current order. |
|
|
785
|
+
| `targetIndex` | `number` | Its position after the move, in the same order. |
|
|
786
|
+
|
|
787
|
+
Splicing the full order with these indices gives the new order. A controlled `columnOrder` that lists only some columns, or no `__group__`, is not that order: use `onColumnOrderModelChange`, which hands you the whole new order.
|
|
641
788
|
|
|
642
789
|
### `GridRowOrderChangeParams<R>`
|
|
643
790
|
Passed to `onRowOrderChange`.
|
|
644
791
|
|
|
645
792
|
| Property | Type | Description |
|
|
646
793
|
| :--- | :--- | :--- |
|
|
647
|
-
| `row` | `R` | The row
|
|
648
|
-
| `oldIndex` | `number` |
|
|
649
|
-
| `targetIndex` | `number` |
|
|
794
|
+
| `row` | `R` | The row that was dragged: your own object from `rows`. |
|
|
795
|
+
| `oldIndex` | `number` | Its position in your `rows` prop (`rows[oldIndex] === row`), whatever the sort, filter, page or pinned rows on screen. |
|
|
796
|
+
| `targetIndex` | `number` | The position in `rows` of the row it was dropped on. Remove the row at `oldIndex` and insert it at `targetIndex`. |
|
|
650
797
|
|
|
651
798
|
### `GridRowScrollEndParams`
|
|
652
799
|
Passed to `onRowsScrollEnd`.
|
|
653
800
|
|
|
654
801
|
| Property | Type | Description |
|
|
655
802
|
| :--- | :--- | :--- |
|
|
656
|
-
| `visibleTop` | `number` |
|
|
657
|
-
| `visibleBottom` | `number` |
|
|
803
|
+
| `visibleTop` | `number` | Scroll offset (`scrollTop`) of the viewport's top edge, in pixels. |
|
|
804
|
+
| `visibleBottom` | `number` | Offset of the viewport's bottom edge (`visibleTop + viewportHeight`). |
|
|
658
805
|
| `viewportHeight` | `number` | Current height of the scroll viewport in pixels. |
|
|
659
806
|
|
|
660
807
|
### `GridDetailPanelParams<R>`
|
|
@@ -664,7 +811,7 @@ Passed to `getDetailPanelContent` and `getDetailPanelHeight`.
|
|
|
664
811
|
| :--- | :--- | :--- |
|
|
665
812
|
| `row` | `R` | The full row data object. |
|
|
666
813
|
| `id` | `GridRowId` | Unique identifier of the row. |
|
|
667
|
-
| `rowIndex` | `number` | Zero-based index of the row
|
|
814
|
+
| `rowIndex` | `number` | Zero-based index of the row among the rendered rows: top-pinned, then the current page, then bottom-pinned (the row's `data-rowindex`). |
|
|
668
815
|
|
|
669
816
|
---
|
|
670
817
|
|
|
@@ -684,8 +831,8 @@ The object passed to `getRows` by the grid on every data fetch.
|
|
|
684
831
|
|
|
685
832
|
| Property | Type | Description |
|
|
686
833
|
| :--- | :--- | :--- |
|
|
687
|
-
| `startRow` | `number` | Zero-based index of the first row to fetch
|
|
688
|
-
| `endRow` | `number` | Zero-based index
|
|
834
|
+
| `startRow` | `number` | Zero-based index of the first row to fetch. Server pagination: `page * pageSize`. Infinite scroll: the number of rows already loaded. Client pagination and tree children: `0`. |
|
|
835
|
+
| `endRow` | `number` | Zero-based index just past the last row to fetch (exclusive), so `rows.slice(startRow, endRow)` is the requested range. Server pagination: `startRow + pageSize`. Infinite scroll: `(page + 1) * pageSize`. When the grid wants every row (client pagination, the children of a tree node) it is `Number.MAX_SAFE_INTEGER`. |
|
|
689
836
|
| `sortModel` | `GridSortItem[]` | Active sort configuration. Empty array when no sort is applied. |
|
|
690
837
|
| `filterModel` | `GridFilterModel` | Active filter state. Has empty `items` when no filters are applied. |
|
|
691
838
|
| `groupKeys` | `string[]` | Path of grouping key values for the current group level (used in lazy-loaded tree/grouping). Empty array for the root level. |
|
|
@@ -712,7 +859,7 @@ import {
|
|
|
712
859
|
GridColDef,
|
|
713
860
|
} from '@opencorestack/opengridx';
|
|
714
861
|
|
|
715
|
-
interface Employee
|
|
862
|
+
interface Employee {
|
|
716
863
|
id: number;
|
|
717
864
|
name: string;
|
|
718
865
|
department: string;
|
|
@@ -764,7 +911,15 @@ export default function EmployeeGrid() {
|
|
|
764
911
|
}
|
|
765
912
|
```
|
|
766
913
|
|
|
767
|
-
**How the grid decides when to call `getRows`:**
|
|
914
|
+
**How the grid decides when to call `getRows`:** whenever a `dataSource` is provided, with a 300 ms debounce that collapses rapid changes into one request. The grid shows its loading state from the moment a request is scheduled, so the empty state never flashes up first.
|
|
915
|
+
|
|
916
|
+
| `paginationMode` | Request | Refetches when |
|
|
917
|
+
| :--- | :--- | :--- |
|
|
918
|
+
| `'client'` (default) | Every row once (`startRow: 0`, `endRow: Number.MAX_SAFE_INTEGER`). The grid pages, and sorts/filters unless those modes are `'server'`. | A `'server'` sort or filter changes, or `getRows` changes. Page changes never refetch. |
|
|
919
|
+
| `'server'` | One page. The response replaces the rows. | The page, page size, sort, filter or aggregation model changes, or `getRows` changes. |
|
|
920
|
+
| `'infinite'` | The rows from the end of what is loaded up to the current page. Responses are appended; rows whose id is already loaded are skipped. | The page grows. A sort, filter, page-size or `getRows` change restarts the list at row 0 and reports page 0 through `onPaginationModelChange`; a smaller page reloads the list up to that page. |
|
|
921
|
+
|
|
922
|
+
Models are compared by content, so inline `sortModel`/`filterModel`/`aggregationModel` objects and a `dataSource` object recreated with the same `getRows` function do not refetch. A response for parameters that have changed since (another page, sort, filter or `dataSource`, or a removed `dataSource`) is discarded. Fetched rows are keyed with `getRowId`. When `getRows` rejects, the error overlay shows the rejection's `message` (an `Error`, a string, or any object with a string `message`) and a **Retry** button that requests the rows again.
|
|
768
923
|
|
|
769
924
|
---
|
|
770
925
|
|
|
@@ -835,7 +990,7 @@ interface GridFilterModel {
|
|
|
835
990
|
| :--- | :--- | :--- | :--- |
|
|
836
991
|
| `items` | `(GridFilterItem \| GridFilterGroup)[]` | `[]` | Root-level filter conditions or nested groups. |
|
|
837
992
|
| `logicOperator` | `'and' \| 'or'` | `'and'` | How to combine the root `items`. |
|
|
838
|
-
| `quickFilterValues` | `string[]` | `[]` |
|
|
993
|
+
| `quickFilterValues` | `string[]` | `[]` | Search terms. Every term must be found (case-insensitive substring) in at least one visible, filterable column, read through `valueGetter` and, if set, `valueFormatter`. The row `id` and non-column fields are not searched. Blank terms are ignored. Applied together with `items`. The toolbar search box splits the typed text on whitespace. |
|
|
839
994
|
|
|
840
995
|
### `GridFilterItem`
|
|
841
996
|
|
|
@@ -846,7 +1001,7 @@ A single column filter condition.
|
|
|
846
1001
|
| `id` | `string \| number` | No | Optional stable identifier for this item (useful for controlled updates). |
|
|
847
1002
|
| `field` | `string` | Yes | The column field to filter on. |
|
|
848
1003
|
| `operator` | `GridFilterOperator` | Yes | The comparison operator to apply. |
|
|
849
|
-
| `value` | `unknown` | No | The value to compare against. Not required for `isEmpty` / `isNotEmpty`. |
|
|
1004
|
+
| `value` | `unknown` | No | The value to compare against. Not required for `isEmpty` / `isNotEmpty`. For every other operator, an empty value (`undefined`, `null`, a blank string or an empty array) means the item does not filter. |
|
|
850
1005
|
|
|
851
1006
|
### `GridFilterGroup`
|
|
852
1007
|
|
|
@@ -864,13 +1019,25 @@ A nested group of filter conditions combined with a logical operator. Groups can
|
|
|
864
1019
|
type GridFilterOperator =
|
|
865
1020
|
| 'contains' | 'equals' | 'startsWith' | 'endsWith'
|
|
866
1021
|
| 'isEmpty' | 'isNotEmpty' | 'isAnyOf'
|
|
867
|
-
| '>' | '>=' | '<' | '<=' | '!='
|
|
868
|
-
| 'is' | 'not'
|
|
1022
|
+
| '=' | '>' | '>=' | '<' | '<=' | '!='
|
|
1023
|
+
| 'is' | 'not'
|
|
1024
|
+
| 'after' | 'onOrAfter' | 'before' | 'onOrBefore';
|
|
869
1025
|
```
|
|
870
1026
|
|
|
1027
|
+
| Operator | Matches when the cell… |
|
|
1028
|
+
| :--- | :--- |
|
|
1029
|
+
| `contains` / `startsWith` / `endsWith` / `equals` | contains / starts with / ends with / equals the value (case-insensitive text). |
|
|
1030
|
+
| `=` `!=` `>` `>=` `<` `<=` | compares numerically with the value (numeric strings accepted). A blank cell never matches, except for `!=`, which it always matches. |
|
|
1031
|
+
| `is` / `not` | equals / does not equal the value (case-insensitive). On `type: 'date'` columns and `Date` cells: the same / a different local calendar day. |
|
|
1032
|
+
| `after` / `onOrAfter` / `before` / `onOrBefore` | is a later / same-or-later / earlier / same-or-earlier local calendar day. |
|
|
1033
|
+
| `isAnyOf` | equals any value in the array (a single value counts as a one-element array). |
|
|
1034
|
+
| `isEmpty` / `isNotEmpty` | is / is not `null`, `undefined` or blank. No value needed. |
|
|
1035
|
+
|
|
1036
|
+
Dates can be `Date` objects, epoch milliseconds or date strings; a `'YYYY-MM-DD'` string is read as a local date. Cells are read through the column's `valueGetter`.
|
|
1037
|
+
|
|
871
1038
|
### Default Operators per Column Type
|
|
872
1039
|
|
|
873
|
-
The filter panel shows only the operators relevant to each column's `type
|
|
1040
|
+
The filter panel shows only the operators relevant to each column's `type`; an operator set programmatically that the type does not list is still shown and applied. Every operator works in a programmatic `filterModel` on any column.
|
|
874
1041
|
|
|
875
1042
|
| Column `type` | Default operator | Available operators |
|
|
876
1043
|
| :--- | :--- | :--- |
|
|
@@ -909,10 +1076,12 @@ const filterModel: GridFilterModel = {
|
|
|
909
1076
|
|
|
910
1077
|
## 💾 `GridInitialState` and `GridState`
|
|
911
1078
|
|
|
912
|
-
`GridInitialState` is
|
|
1079
|
+
`GridInitialState` is `GridState` with every column field optional as well. Pass it to `initialState` to restore persisted grid state on mount (e.g. from `localStorage`). Each key corresponds to a feature slice — all are optional. A `GridState` from `onStateChange` is a valid `GridInitialState`.
|
|
913
1080
|
|
|
914
1081
|
```typescript
|
|
915
|
-
|
|
1082
|
+
interface GridInitialState extends Omit<GridState, 'columns'> {
|
|
1083
|
+
columns?: Partial<GridColumnsState>; // e.g. { columnVisibilityModel: { age: false } }
|
|
1084
|
+
}
|
|
916
1085
|
|
|
917
1086
|
interface GridState {
|
|
918
1087
|
sorting?: GridSortingState;
|
|
@@ -999,16 +1168,18 @@ type GridAggregationResult = Record<string, unknown>;
|
|
|
999
1168
|
|
|
1000
1169
|
| Function | Input | Output | Description |
|
|
1001
1170
|
| :--- | :--- | :--- | :--- |
|
|
1002
|
-
| `sum` | numeric values | `number` | Sum of
|
|
1003
|
-
| `avg` | numeric values | `number \| null` | Arithmetic mean. Returns `null` if there are
|
|
1004
|
-
| `min` | numeric values | `number \| null` | Smallest
|
|
1005
|
-
| `max` | numeric values | `number \| null` | Largest
|
|
1006
|
-
| `count` | any values | `number` | Count of
|
|
1007
|
-
| `unique` | any values | `number` | Count of distinct
|
|
1171
|
+
| `sum` | numeric values | `number` | Sum of the numeric values (numbers, numeric strings, `Date`s as timestamps). Blank cells, booleans and arrays are skipped. `0` when there are none. |
|
|
1172
|
+
| `avg` | numeric values | `number \| null` | Arithmetic mean of the same values. Returns `null` if there are none. |
|
|
1173
|
+
| `min` | numeric values | `number \| Date \| null` | Smallest value; a `Date` when the smallest value is a `Date`. Returns `null` if there are none. |
|
|
1174
|
+
| `max` | numeric values | `number \| Date \| null` | Largest value; a `Date` when the largest value is a `Date`. Returns `null` if there are none. |
|
|
1175
|
+
| `count` | any values | `number` | Count of values that are not `null`, `undefined` or a blank string. |
|
|
1176
|
+
| `unique` | any values | `number` | Count of distinct values, blanks excluded (uses a `Set`). |
|
|
1177
|
+
|
|
1178
|
+
Cells are read through the column's `valueGetter`.
|
|
1008
1179
|
|
|
1009
1180
|
All built-in functions are exported as the `BuiltInAggFn` type: `'sum' | 'avg' | 'count' | 'min' | 'max' | 'unique'`.
|
|
1010
1181
|
|
|
1011
|
-
Use `formatAggregationValue(value, fnName)` to turn a raw result into a display string
|
|
1182
|
+
Use `formatAggregationValue(value, fnName)` to turn a raw result into a display string: `'—'` for `null` / `undefined`, `avg` to at most 2 decimal places, other numbers with `toLocaleString()`, anything else with `String(value)`.
|
|
1012
1183
|
|
|
1013
1184
|
### `getAggregationPosition` Callback
|
|
1014
1185
|
|
|
@@ -1016,13 +1187,17 @@ Use `formatAggregationValue(value, fnName)` to turn a raw result into a display
|
|
|
1016
1187
|
getAggregationPosition?: (groupNode: GridTreeNode | null) => 'inline' | 'footer' | null
|
|
1017
1188
|
```
|
|
1018
1189
|
|
|
1019
|
-
|
|
1190
|
+
The return type is exported as `GridAggregationPosition` (`'inline' | 'footer' | null`, v3.0+).
|
|
1020
1191
|
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
|
1024
|
-
|
|
|
1025
|
-
| `
|
|
1192
|
+
Called on every render for each group node, with the node's current `isExpanded`, and once with `null` for the grand total. Only the answers matter, so an inline arrow function is fine.
|
|
1193
|
+
|
|
1194
|
+
| Return value | For a group | For the grand total (`null`) |
|
|
1195
|
+
| :--- | :--- | :--- |
|
|
1196
|
+
| `'inline'` | Aggregates on the group row (the default). | The footer row is shown. |
|
|
1197
|
+
| `'footer'` | Aggregates on a subtotal row placed after the group's children while the group is expanded; the group row shows none. While the group is collapsed there is no subtotal row, so the aggregates stay on the group row. | The footer row is shown (the default). |
|
|
1198
|
+
| `null` | No aggregates for this group, on screen or in `getGroupedExportRows()` (no `group-subtotal` entry). | The footer row is hidden, and `getGroupedExportRows()` has no `grand-total` entry. |
|
|
1199
|
+
|
|
1200
|
+
Subtotal rows are synthetic: `params.rowMeta` has `isGroupRow: true` and `isGroupFooter: true` (plus the group's `groupingField`, `groupingValue`, `groupLabel`), they carry the aggregates under each column's field, and they are never selected, edited or given a detail panel. Their row element has the class `ogx__row--group-footer`. To show subtotals below expanded groups only: `getAggregationPosition={(node) => (node === null ? 'footer' : node.isExpanded ? 'footer' : 'inline')}`.
|
|
1026
1201
|
|
|
1027
1202
|
### Aggregation + Row Grouping Example
|
|
1028
1203
|
|
|
@@ -1036,7 +1211,7 @@ import {
|
|
|
1036
1211
|
GridRowGroupingModel,
|
|
1037
1212
|
} from '@opencorestack/opengridx';
|
|
1038
1213
|
|
|
1039
|
-
interface Employee
|
|
1214
|
+
interface Employee {
|
|
1040
1215
|
id: number;
|
|
1041
1216
|
name: string;
|
|
1042
1217
|
department: string;
|
|
@@ -1167,7 +1342,15 @@ export default function GroupedHeadersGrid() {
|
|
|
1167
1342
|
}
|
|
1168
1343
|
```
|
|
1169
1344
|
|
|
1170
|
-
The grid renders
|
|
1345
|
+
The grid renders one group header row per nesting level above the regular per-column header row. Columns that are not referenced in `columnGroupingModel` get an empty filler cell in the group rows.
|
|
1346
|
+
|
|
1347
|
+
Group rows follow the columns as they are rendered:
|
|
1348
|
+
|
|
1349
|
+
- **Order, visibility and pinning** — a group covers its visible member columns in their current order. A group whose members are not adjacent (or that spans a pinned-section boundary) renders one group cell per run of adjacent members. Group cells over pinned columns are sticky, so they stay above their columns on horizontal scroll.
|
|
1350
|
+
- **Widths** — a group cell is exactly as wide as its member columns, including flex, `auto` and percentage widths and manual resizes.
|
|
1351
|
+
- **`headerClassName`** — added to the group cell's class list (next to `ogx-col-group-cell` and `ogx-col-group-cell--group`).
|
|
1352
|
+
- **Column reordering** — header drag and the toolbar / columns-panel reorder keep groups intact: a column can only be moved onto a column of the same innermost group, and an ungrouped column only onto another ungrouped column.
|
|
1353
|
+
- **Accessibility** — group cells are `role="columnheader"` with `aria-colspan` (visible member columns) and `aria-colindex`; filler cells are `aria-hidden`. The grid's `aria-rowcount` includes the group header rows.
|
|
1171
1354
|
|
|
1172
1355
|
---
|
|
1173
1356
|
|
|
@@ -1178,7 +1361,7 @@ List view renders the grid as a single-column list of cards, replacing all norma
|
|
|
1178
1361
|
### `GridListViewColDef<R>`
|
|
1179
1362
|
|
|
1180
1363
|
```typescript
|
|
1181
|
-
interface GridListViewColDef<R extends
|
|
1364
|
+
interface GridListViewColDef<R extends GridValidRowModel = GridRowModel> {
|
|
1182
1365
|
field: string;
|
|
1183
1366
|
renderCell: (params: GridRenderCellParams<R>) => React.ReactNode;
|
|
1184
1367
|
}
|
|
@@ -1189,9 +1372,9 @@ The `renderCell` function receives the full `GridRenderCellParams` (including `r
|
|
|
1189
1372
|
### Usage Example
|
|
1190
1373
|
|
|
1191
1374
|
```tsx
|
|
1192
|
-
import { DataGrid, GridListViewColDef, GridRenderCellParams } from '@opencorestack/opengridx';
|
|
1375
|
+
import { DataGrid, GridListViewColDef, GridRenderCellParams, GridRowModel } from '@opencorestack/opengridx';
|
|
1193
1376
|
|
|
1194
|
-
interface Employee
|
|
1377
|
+
interface Employee {
|
|
1195
1378
|
id: number;
|
|
1196
1379
|
name: string;
|
|
1197
1380
|
department: string;
|
|
@@ -1228,7 +1411,7 @@ export default function MobileGrid() {
|
|
|
1228
1411
|
### `exportToPdf`
|
|
1229
1412
|
|
|
1230
1413
|
```ts
|
|
1231
|
-
function exportToPdf<R extends
|
|
1414
|
+
function exportToPdf<R extends GridValidRowModel>(
|
|
1232
1415
|
rows: R[],
|
|
1233
1416
|
columns: GridColDef<R>[],
|
|
1234
1417
|
options?: PdfExportOptions
|
|
@@ -1246,6 +1429,7 @@ interface PdfExportOptions {
|
|
|
1246
1429
|
logoUrl?: string;
|
|
1247
1430
|
orientation?: 'portrait' | 'landscape';
|
|
1248
1431
|
selectedRows?: (string | number)[];
|
|
1432
|
+
getRowId?: (row: GridRowModel) => GridRowId; // v3.0+
|
|
1249
1433
|
aggregationResult?: Record<string, unknown> | null;
|
|
1250
1434
|
aggregationModel?: GridAggregationModel | null;
|
|
1251
1435
|
filterModel?: GridFilterModel | null;
|
|
@@ -1254,6 +1438,7 @@ interface PdfExportOptions {
|
|
|
1254
1438
|
headerBackgroundColor?: string;
|
|
1255
1439
|
headerTextColor?: string;
|
|
1256
1440
|
fontSize?: number;
|
|
1441
|
+
font?: { name: string; data: string; boldData?: string }; // v3.0+
|
|
1257
1442
|
}
|
|
1258
1443
|
```
|
|
1259
1444
|
|
|
@@ -1263,12 +1448,14 @@ interface PdfExportOptions {
|
|
|
1263
1448
|
| `title` | `string` | — | Adds a branded header block above the table |
|
|
1264
1449
|
| `logoUrl` | `string` | — | Data URI or URL for a logo image (requires `title`) |
|
|
1265
1450
|
| `orientation` | `'portrait' \| 'landscape'` | `'landscape'` | Page orientation |
|
|
1266
|
-
| `selectedRows` | `(string \| number)[]` | — | Export only rows with these IDs |
|
|
1451
|
+
| `selectedRows` | `(string \| number)[]` | — | Export only rows with these IDs. Takes precedence over `groupedRows`; footer totals are recomputed over the selection (v3.0+) |
|
|
1452
|
+
| `getRowId` | `(row) => GridRowId` | `row.id` | The grid's `getRowId`, to match `selectedRows` against rows that keep their id elsewhere (v3.0+) |
|
|
1267
1453
|
| `aggregationResult` | `Record<string, unknown>` | — | From `apiRef.current.getAggregationResult()` |
|
|
1268
1454
|
| `aggregationModel` | `GridAggregationModel` | — | From `apiRef.current.getAggregationModel()` |
|
|
1269
|
-
| `filterModel` | `GridFilterModel` | — | From `apiRef.current.getFilterModel()
|
|
1270
|
-
| `groupedRows` | `GridGroupedExportRow[]` | — | Pre-built grouped export rows from `apiRef.current.getGroupedExportRows()`. When provided, the PDF table reflects the grouping structure (group-header, indented leaves, subtotals, grand total). |
|
|
1455
|
+
| `filterModel` | `GridFilterModel` | — | From `apiRef.current.getFilterModel()`. Nested groups, the logic operator and quick-search terms are summarised; rules without a value are skipped |
|
|
1456
|
+
| `groupedRows` | `GridGroupedExportRow[]` | — | Pre-built grouped export rows from `apiRef.current.getGroupedExportRows()`. When provided (and `selectedRows` is empty), the PDF table reflects the grouping structure (group-header, indented leaves, subtotals, grand total). |
|
|
1271
1457
|
| `alternateRowColor` | `boolean` | `true` | Alternating row background shading |
|
|
1272
|
-
| `headerBackgroundColor` | `string` | `'#4f46e5'` | Column header cell background (
|
|
1273
|
-
| `headerTextColor` | `string` | `'#ffffff'` | Column header cell text color (
|
|
1458
|
+
| `headerBackgroundColor` | `string` | `'#4f46e5'` | Column header cell background (`#rrggbb` / `#rgb`) |
|
|
1459
|
+
| `headerTextColor` | `string` | `'#ffffff'` | Column header cell text color (`#rrggbb` / `#rgb`) |
|
|
1274
1460
|
| `fontSize` | `number` | `9` | Body cell font size in points |
|
|
1461
|
+
| `font` | `{ name, data, boldData? }` | — | Base64 TrueType font for text outside Latin-1 (₹, CJK, Cyrillic…). Without it, such characters are replaced with `?` (v3.0+) |
|