@opencorestack/opengridx 0.1.6 → 0.1.7
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 +15 -0
- package/README.md +9 -0
- package/dist/index.d.ts +6 -0
- package/dist/opengridx.es.js +6 -6
- package/dist/opengridx.es.js.map +1 -1
- package/dist/opengridx.umd.js +4 -4
- package/dist/opengridx.umd.js.map +1 -1
- package/docs/API_REFERENCE.md +177 -0
- package/docs/README.md +60 -0
- package/docs/components/cell.md +44 -0
- package/docs/components/column-group-header.md +57 -0
- package/docs/components/column-resize.md +63 -0
- package/docs/components/column-visibility.md +61 -0
- package/docs/components/datagrid.md +70 -0
- package/docs/components/filter-panel.md +26 -0
- package/docs/components/header.md +39 -0
- package/docs/components/pagination.md +34 -0
- package/docs/components/row.md +31 -0
- package/docs/components/toolbar.md +40 -0
- package/docs/components/tooltip.md +68 -0
- package/docs/customization/slots-api.md +227 -0
- package/docs/customization/theming.md +293 -0
- package/docs/features/aggregation-pivot.md +79 -0
- package/docs/features/cell-spanning.md +520 -0
- package/docs/features/clipboard.md +76 -0
- package/docs/features/custom-pagination.md +143 -0
- package/docs/features/data-source.md +72 -0
- package/docs/features/editing-reordering.md +99 -0
- package/docs/features/export-guide.md +434 -0
- package/docs/features/filtering.md +83 -0
- package/docs/features/infinite-scroll.md +87 -0
- package/docs/features/list-view.md +65 -0
- package/docs/features/loading-states.md +68 -0
- package/docs/features/master-detail.md +46 -0
- package/docs/features/pinning.md +67 -0
- package/docs/features/selection.md +70 -0
- package/docs/features/sorting-pagination.md +66 -0
- package/docs/features/state-persistence.md +67 -0
- package/docs/features/tree-data-grouping.md +67 -0
- package/docs/features/virtualization.md +188 -0
- package/docs/roadmap.md +71 -0
- package/lib/components/Cell/Cell.css +119 -0
- package/lib/components/Cell/Cell.tsx +264 -0
- package/lib/components/Cell/GridEditInputCell.css +62 -0
- package/lib/components/Cell/GridEditInputCell.tsx +152 -0
- package/lib/components/ColumnGroupHeader/ColumnGroupHeader.css +67 -0
- package/lib/components/ColumnGroupHeader/ColumnGroupHeader.tsx +220 -0
- package/lib/components/ColumnResizeHandle/ColumnResizeHandle.css +31 -0
- package/lib/components/ColumnResizeHandle/ColumnResizeHandle.tsx +85 -0
- package/lib/components/ColumnVisibilityPanel/ColumnVisibilityPanel.css +137 -0
- package/lib/components/ColumnVisibilityPanel/ColumnVisibilityPanel.tsx +190 -0
- package/lib/components/DataGrid/DataGrid.css +224 -0
- package/lib/components/DataGrid/DataGrid.tsx +2253 -0
- package/lib/components/DetailPanel/DetailPanel.css +36 -0
- package/lib/components/DetailPanel/DetailPanel.tsx +34 -0
- package/lib/components/FilterPanel/FilterPanel.css +196 -0
- package/lib/components/FilterPanel/FilterPanel.tsx +183 -0
- package/lib/components/FilterPanel/index.ts +1 -0
- package/lib/components/Header/ColumnMenu.css +68 -0
- package/lib/components/Header/ColumnMenu.tsx +249 -0
- package/lib/components/Header/Header.css +224 -0
- package/lib/components/Header/Header.tsx +516 -0
- package/lib/components/ListView/ListView.css +112 -0
- package/lib/components/ListView/ListViewRow.tsx +63 -0
- package/lib/components/Pagination/Pagination.css +91 -0
- package/lib/components/Pagination/Pagination.tsx +151 -0
- package/lib/components/QuickFilter/QuickFilter.css +23 -0
- package/lib/components/QuickFilter/QuickFilter.tsx +79 -0
- package/lib/components/Row/Row.css +126 -0
- package/lib/components/Row/Row.tsx +377 -0
- package/lib/components/Skeleton/Skeleton.css +55 -0
- package/lib/components/Skeleton/Skeleton.tsx +22 -0
- package/lib/components/SkeletonRow/SkeletonRow.css +32 -0
- package/lib/components/SkeletonRow/SkeletonRow.tsx +89 -0
- package/lib/components/SkeletonRow/index.ts +1 -0
- package/lib/components/Toolbar/GlobalSearch.css +113 -0
- package/lib/components/Toolbar/GlobalSearch.tsx +120 -0
- package/lib/components/Toolbar/GridToolbar.css +204 -0
- package/lib/components/Toolbar/GridToolbar.tsx +647 -0
- package/lib/components/Toolbar/PivotPanel.css +212 -0
- package/lib/components/Toolbar/PivotPanel.tsx +239 -0
- package/lib/components/Tooltip/Tooltip.css +59 -0
- package/lib/components/Tooltip/Tooltip.tsx +106 -0
- package/lib/components/ui/Button.css +89 -0
- package/lib/components/ui/Button.tsx +39 -0
- package/lib/components/ui/Checkbox.css +71 -0
- package/lib/components/ui/Checkbox.tsx +66 -0
- package/lib/components/ui/DragHandleIcon.css +19 -0
- package/lib/components/ui/DragHandleIcon.tsx +18 -0
- package/lib/components/ui/ExpandIcon.css +38 -0
- package/lib/components/ui/ExpandIcon.tsx +75 -0
- package/lib/components/ui/Input.css +59 -0
- package/lib/components/ui/Input.tsx +45 -0
- package/lib/components/ui/index.ts +15 -0
- package/lib/hooks/core/useDataGrid.ts +392 -0
- package/lib/hooks/core/useGridApiRef.ts +10 -0
- package/lib/hooks/features/useAggregation.ts +143 -0
- package/lib/hooks/features/useGridClipboard.ts +133 -0
- package/lib/hooks/features/useGridDataSource.ts +190 -0
- package/lib/hooks/features/useGridEditing.ts +100 -0
- package/lib/hooks/features/useGridSpanning.ts +349 -0
- package/lib/hooks/features/usePivot.ts +149 -0
- package/lib/hooks/useColumnReorder.ts +114 -0
- package/lib/hooks/useRowGrouping.ts +302 -0
- package/lib/hooks/useRowReorder.ts +83 -0
- package/lib/hooks/useTreeData.ts +323 -0
- package/lib/index.ts +106 -0
- package/lib/state/index.ts +17 -0
- package/lib/state/types.ts +48 -0
- package/lib/state/useGridStateStorage.ts +113 -0
- package/lib/styles/base/reset.css +21 -0
- package/lib/styles/base/variables.css +161 -0
- package/lib/styles/opengridx.css +27 -0
- package/lib/styles/opengridx.css.d.ts +4 -0
- package/lib/theme/DataGridThemeProvider.tsx +276 -0
- package/lib/theme/defaultStyles.ts +0 -0
- package/lib/theme/index.ts +21 -0
- package/lib/theme/presets.ts +148 -0
- package/lib/theme/types.ts +155 -0
- package/lib/types/index.ts +764 -0
- package/lib/utils/export/exportToExcelAdvanced.ts +516 -0
- package/lib/utils/export/index.ts +550 -0
- package/lib/utils/filtering/index.ts +240 -0
- package/lib/utils/pinning/index.ts +282 -0
- package/lib/utils/sorting/index.ts +55 -0
- package/lib/utils/virtualization/index.ts +106 -0
- package/lib/vite-env.d.ts +1 -0
- package/llms.txt +2 -1
- package/package.json +13 -4
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# ⏳ Loading States & Performance
|
|
2
|
+
|
|
3
|
+
OpenGridX provides multiple ways to handle data loading, from initial shimmers to background fetching.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🦴 Skeleton Loading
|
|
8
|
+
|
|
9
|
+
The grid features a smart skeleton loader that automatically calculates the number of columns and rows needed to fill the viewport.
|
|
10
|
+
|
|
11
|
+
### Usage
|
|
12
|
+
```tsx
|
|
13
|
+
<DataGrid loading={true} />
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
- **Dynamic Calculation**: Skeletons match the current column widths and configuration.
|
|
18
|
+
- **Shimmer Animation**: Uses a CSS-optimized animation for a premium feel.
|
|
19
|
+
- **Auto-Fill**: Fills the entire visible height if `rows` are empty.
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## ♾️ Infinite Loading
|
|
24
|
+
|
|
25
|
+
For large datasets, use the `paginationMode="infinite"` to load data as the user scrolls.
|
|
26
|
+
|
|
27
|
+
- **Trigger**: Fired when the user scrolls near the bottom of the grid.
|
|
28
|
+
- **Feedback**: Displays skeleton rows at the bottom while new data is being fetched.
|
|
29
|
+
- **Guide**: See [Infinite Scroll Guide](./infinite-scroll.md) for full implementation details.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## 💤 Lazy Loading (Viewport)
|
|
34
|
+
|
|
35
|
+
Unlike infinite scroll which appends data to the end, Lazy Loading fetches specific chunks based on the user's current scroll position (viewport).
|
|
36
|
+
|
|
37
|
+
- **Benefit**: Best for datasets with millions of records where users might "jump" to the middle of the scrollbar.
|
|
38
|
+
- **Implementation**: Managed via the `GridDataSource` and `rowCount` props.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## 🔍 Global Search (Quick Filter)
|
|
43
|
+
|
|
44
|
+
Quickly filter the entire dataset across all visible columns. This is managed via the `GridToolbar`.
|
|
45
|
+
|
|
46
|
+
### Basic Setup
|
|
47
|
+
```tsx
|
|
48
|
+
<DataGrid
|
|
49
|
+
slots={{ toolbar: GridToolbar }}
|
|
50
|
+
slotProps={{
|
|
51
|
+
toolbar: {
|
|
52
|
+
showQuickFilter: true
|
|
53
|
+
}
|
|
54
|
+
}}
|
|
55
|
+
/>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Controlled Search
|
|
59
|
+
You can also control the search value externally via the `filterModel`.
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
<DataGrid
|
|
63
|
+
filterModel={{
|
|
64
|
+
items: [],
|
|
65
|
+
quickFilterValues: ['search term']
|
|
66
|
+
}}
|
|
67
|
+
/>
|
|
68
|
+
```
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# 📋 Master-Detail (Detail Panel)
|
|
2
|
+
|
|
3
|
+
Display supplementary information for a row in an expandable panel without leaving the main grid view.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🛠️ Basic Implementation
|
|
8
|
+
|
|
9
|
+
To enable detail panels, provided two main props: `getDetailPanelContent` and `getDetailPanelHeight`.
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
<DataGrid
|
|
13
|
+
rows={rows}
|
|
14
|
+
columns={columns}
|
|
15
|
+
getDetailPanelContent={(params) => (
|
|
16
|
+
<div style={{ padding: '20px' }}>
|
|
17
|
+
<h3>Details for {params.row.name}</h3>
|
|
18
|
+
<p>{params.row.description}</p>
|
|
19
|
+
</div>
|
|
20
|
+
)}
|
|
21
|
+
getDetailPanelHeight={() => 'auto'} // or a fixed number
|
|
22
|
+
/>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## 🕹️ Controlled Expansion
|
|
28
|
+
|
|
29
|
+
You can manage which rows are expanded by using the `detailPanelExpandedRowIds` and `onDetailPanelExpandedRowIdsChange` props.
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
const [expandedIds, setExpandedIds] = useState(new Set());
|
|
33
|
+
|
|
34
|
+
<DataGrid
|
|
35
|
+
detailPanelExpandedRowIds={expandedIds}
|
|
36
|
+
onDetailPanelExpandedRowIdsChange={setExpandedIds}
|
|
37
|
+
/>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## 🎨 Layout Impact
|
|
43
|
+
|
|
44
|
+
- **Expansion Column**: A `+` icon is automatically added to the start of the row.
|
|
45
|
+
- **Pinning**: The expansion column can be pinned using `pinExpandColumn={true}`. This ensures the expansion trigger is always visible even when scrolling horizontally.
|
|
46
|
+
- **Virtualization**: The grid engine correctly accounts for variable row heights when detail panels are open.
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# 📌 Pinning (Rows & Columns)
|
|
2
|
+
|
|
3
|
+
Keep critical data visible while scrolling through large tables.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ⬅️ Column Pinning
|
|
8
|
+
|
|
9
|
+
Columns can be pinned to the left or right edges of the grid. Pinned columns remain sticky while the rest of the columns scroll horizontally.
|
|
10
|
+
|
|
11
|
+
### Implementation
|
|
12
|
+
```tsx
|
|
13
|
+
<DataGrid
|
|
14
|
+
pinnedColumns={{
|
|
15
|
+
left: ['name', 'department'],
|
|
16
|
+
right: ['actions']
|
|
17
|
+
}}
|
|
18
|
+
/>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Column Configuration
|
|
22
|
+
Individual columns can be marked as non-pinnable:
|
|
23
|
+
```typescript
|
|
24
|
+
{ field: 'id', pinnable: false }
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## ⬆️ Row Pinning
|
|
30
|
+
|
|
31
|
+
Rows can be pinned to the top or bottom of the grid. Pinned rows remain visible while the user scrolls vertically through the grid body.
|
|
32
|
+
|
|
33
|
+
### Implementation
|
|
34
|
+
```tsx
|
|
35
|
+
<DataGrid
|
|
36
|
+
pinnedRows={{
|
|
37
|
+
top: ['row-1', 'row-5'], // Array of Row IDs
|
|
38
|
+
bottom: ['row-summary']
|
|
39
|
+
}}
|
|
40
|
+
/>
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Use Cases
|
|
44
|
+
- **Header Summary**: Keep a "Totals" or "Averages" row at the top.
|
|
45
|
+
- **Comparison**: Pin a specific row to compare it against other data.
|
|
46
|
+
- **Actions footer**: Pin a specialized row for bulk actions at the bottom.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## ⚙️ API Reference
|
|
51
|
+
|
|
52
|
+
### Props
|
|
53
|
+
| Prop | Type | Description |
|
|
54
|
+
| :--- | :--- | :--- |
|
|
55
|
+
| `pinnedColumns` | `GridColumnPinning` | `{ left: string[], right: string[] }` |
|
|
56
|
+
| `pinnedRows` | `GridRowPinning` | `{ top: GridRowId[], bottom: GridRowId[] }` |
|
|
57
|
+
| `onPinnedColumnsChange` | `(model) => void` | Callback triggered when pinning changes. |
|
|
58
|
+
| `onPinnedRowsChange` | `(model) => void` | Callback triggered when row pinning changes. |
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## 🎨 Styling Pinning
|
|
63
|
+
Pinned elements have specific CSS shadow classes applied to indicate depth:
|
|
64
|
+
- `.ogx-column--pinned-left--last`
|
|
65
|
+
- `.ogx-column--pinned-right--first`
|
|
66
|
+
|
|
67
|
+
These can be customized via your theme or global CSS.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# ✅ Row Selection
|
|
2
|
+
|
|
3
|
+
OpenGridX provides various ways for users to select one or multiple rows.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🔘 Selection Modes
|
|
8
|
+
|
|
9
|
+
| Mode | Description |
|
|
10
|
+
| :--- | :--- |
|
|
11
|
+
| **Checkbox Selection** | Adds a column with checkboxes for bulk selection. |
|
|
12
|
+
| **Row Click Selection** | Select a row by clicking anywhere on the row body. |
|
|
13
|
+
| **Single Selection** | Limit the user to picking only one row at a time. |
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## 🛠️ Implementation
|
|
18
|
+
|
|
19
|
+
### Enable Checkbox Selection
|
|
20
|
+
```tsx
|
|
21
|
+
<DataGrid
|
|
22
|
+
checkboxSelection
|
|
23
|
+
pinCheckboxColumn // Optional: keeps checkbox on the left during horizontal scroll
|
|
24
|
+
/>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Controlled Selection
|
|
28
|
+
Use the `rowSelectionModel` to control the selection state from your parent component.
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
const [selection, setSelection] = useState<GridRowId[]>([]);
|
|
32
|
+
|
|
33
|
+
<DataGrid
|
|
34
|
+
rowSelectionModel={selection}
|
|
35
|
+
onRowSelectionModelChange={(newSelection) => setSelection(newSelection)}
|
|
36
|
+
/>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
---
|
|
40
|
+
|
|
41
|
+
## ⚙️ API Reference
|
|
42
|
+
|
|
43
|
+
### Props
|
|
44
|
+
| Prop | Type | Default | Description |
|
|
45
|
+
| :--- | :--- | :--- | :--- |
|
|
46
|
+
| `checkboxSelection` | `boolean` | `false` | Enable the checkbox column. |
|
|
47
|
+
| `disableRowSelectionOnClick` | `boolean` | `false` | If true, clicking a cell won't select the row. |
|
|
48
|
+
| `disableMultipleRowSelection` | `boolean` | `false` | Restricts selection to a single row. |
|
|
49
|
+
| `rowSelectionModel` | `GridRowId[]` | `[]` | Controlled array of selected IDs. |
|
|
50
|
+
| `isRowSelectable` | `(params) => boolean` | `undefined` | Predicate to disable selection for specific rows. |
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
## 🖱️ Interaction Callbacks
|
|
55
|
+
|
|
56
|
+
### `onRowClick`
|
|
57
|
+
Fired when a row is clicked (even if selection is disabled on click).
|
|
58
|
+
```typescript
|
|
59
|
+
onRowClick: (params: GridRowParams) => {
|
|
60
|
+
console.log('Row clicked:', params.id, params.row);
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### `onCellClick`
|
|
65
|
+
Fired when a specific cell is clicked.
|
|
66
|
+
```typescript
|
|
67
|
+
onCellClick: (params: GridCellParams) => {
|
|
68
|
+
console.log('Cell clicked:', params.field, params.value);
|
|
69
|
+
}
|
|
70
|
+
```
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# 🔢 Sorting & Pagination
|
|
2
|
+
|
|
3
|
+
Efficiently naviagte and organize through large datasets using OpenGridX's sorting and pagination engines.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🔼 Column Sorting
|
|
8
|
+
|
|
9
|
+
Sorting can be toggled by clicking column headers. It supports single-column and multi-column (Shift+Click) sorting.
|
|
10
|
+
|
|
11
|
+
### Props
|
|
12
|
+
| Prop | Type | Description |
|
|
13
|
+
| :--- | :--- | :--- |
|
|
14
|
+
| `sortingMode` | `'client' \| 'server'` | Whether to sort locally or on the server. |
|
|
15
|
+
| `sortModel` | `GridSortItem[]` | Controlled state of active sorts. |
|
|
16
|
+
| `onSortModelChange` | `(model) => void` | Callback triggered when sorting changes. |
|
|
17
|
+
|
|
18
|
+
### Column-Specific Config
|
|
19
|
+
Disable sorting for specific columns in `GridColDef`:
|
|
20
|
+
```typescript
|
|
21
|
+
{ field: 'actions', sortable: false }
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## 📄 Pagination
|
|
27
|
+
|
|
28
|
+
OpenGridX supports standard page-based pagination and infinite scrolling.
|
|
29
|
+
|
|
30
|
+
### Usage
|
|
31
|
+
```tsx
|
|
32
|
+
<DataGrid
|
|
33
|
+
pagination
|
|
34
|
+
paginationModel={{ page: 0, pageSize: 10 }}
|
|
35
|
+
pageSizeOptions={[5, 10, 20, 50]}
|
|
36
|
+
/>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Server-Side Pagination
|
|
40
|
+
When using `paginationMode="server"`, you must provide the `rowCount` and handle page changes in your `dataSource`.
|
|
41
|
+
|
|
42
|
+
```tsx
|
|
43
|
+
<DataGrid
|
|
44
|
+
pagination
|
|
45
|
+
paginationMode="server"
|
|
46
|
+
rowCount={1000} // Total rows on server
|
|
47
|
+
onPaginationModelChange={(model) => fetchNextPage(model)}
|
|
48
|
+
/>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### Props
|
|
52
|
+
| Prop | Type | Default | Description |
|
|
53
|
+
| :--- | :--- | :--- | :--- |
|
|
54
|
+
| `pagination` | `boolean` | `false` | Enable/disable the pagination footer. |
|
|
55
|
+
| `paginationMode` | `'client' \| 'server'` | `'client'` | Location of the pagination logic. |
|
|
56
|
+
| `pageSizeOptions` | `number[]` | `[10, 25, 50]` | Options for the rows-per-page selector. |
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## ⚡ Infinite Scrolling
|
|
61
|
+
For a more modern experience, use infinite scroll combined with virtualization.
|
|
62
|
+
|
|
63
|
+
1. Set `paginationMode="infinite"`.
|
|
64
|
+
2. Implement `onRowsScrollEnd` or use the `dataSource.getRows` method to fetch data as the user scrolls.
|
|
65
|
+
|
|
66
|
+
📖 **[Full Infinite Scroll Guide](docs/features/infinite-scroll.md)**
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# 💾 State Persistence
|
|
2
|
+
|
|
3
|
+
Save and restore the grid's configuration (sorting, filtering, column order, etc.) to provide a consistent experience for returning users.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 🏗️ The `initialState` Prop
|
|
8
|
+
|
|
9
|
+
You can pre-configure the grid status on mount using the `initialState` prop.
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
<DataGrid
|
|
13
|
+
initialState={{
|
|
14
|
+
sorting: {
|
|
15
|
+
sortModel: [{ field: 'name', sort: 'asc' }]
|
|
16
|
+
}
|
|
17
|
+
}}
|
|
18
|
+
/>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## ⚓ The `useGridStateStorage` Hook
|
|
24
|
+
|
|
25
|
+
OpenGridX provides a built-in hook to simplify `localStorage` persistence.
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { DataGrid, useGridStateStorage } from '@opencorestack/opengridx';
|
|
29
|
+
|
|
30
|
+
export default function MyGrid() {
|
|
31
|
+
const { initialState, onStateChange } = useGridStateStorage('my-app-storage-key');
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<DataGrid
|
|
35
|
+
initialState={initialState}
|
|
36
|
+
onStateChange={onStateChange}
|
|
37
|
+
// ...
|
|
38
|
+
/>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## 📡 Tracking Changes
|
|
46
|
+
|
|
47
|
+
Use the `onStateChange` callback to listen for any modifications to the grid state and save them to `localStorage` or a database.
|
|
48
|
+
|
|
49
|
+
```tsx
|
|
50
|
+
<DataGrid
|
|
51
|
+
onStateChange={(state) => {
|
|
52
|
+
localStorage.setItem('grid-state', JSON.stringify(state));
|
|
53
|
+
}}
|
|
54
|
+
/>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## 🧩 Supported State Objects
|
|
60
|
+
|
|
61
|
+
The following features support state persistence:
|
|
62
|
+
- **Sorting**: `sortModel`
|
|
63
|
+
- **Filtering**: `filterModel`
|
|
64
|
+
- **Pagination**: `paginationModel`
|
|
65
|
+
- **Columns**: `columnVisibilityModel`, `columnOrder`, `pinnedColumns`, `columnWidths`
|
|
66
|
+
- **Selection**: `rowSelectionModel`
|
|
67
|
+
- **Grouping**: `rowGroupingModel`
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# 🌳 Tree Data & Row Grouping
|
|
2
|
+
|
|
3
|
+
Display complex, hierarchical data structures with ease.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 📂 Row Grouping
|
|
8
|
+
|
|
9
|
+
Row grouping allows you to categorize rows based on common column values.
|
|
10
|
+
|
|
11
|
+
### Usage
|
|
12
|
+
```tsx
|
|
13
|
+
<DataGrid
|
|
14
|
+
rows={rows}
|
|
15
|
+
rowGroupingModel={['department', 'role']}
|
|
16
|
+
/>
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
- **Multi-Level Groups**: Nest data as deeply as needed.
|
|
21
|
+
- **Aggregation Integration**: Summarize values automatically for each group level.
|
|
22
|
+
- **Expansion Control**: Control which groups are expanded by default.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## 🌿 Tree Data
|
|
27
|
+
|
|
28
|
+
Tree data is used for data that has a natural parent-child relationship (e.g., an organizational chart or file system).
|
|
29
|
+
|
|
30
|
+
### Implementation
|
|
31
|
+
1. Enable `treeData={true}`.
|
|
32
|
+
2. Provide a `getTreeDataPath` function to define the hierarchy.
|
|
33
|
+
|
|
34
|
+
```tsx
|
|
35
|
+
<DataGrid
|
|
36
|
+
treeData
|
|
37
|
+
getTreeDataPath={(row) => row.hierarchyPath} // e.g. ['CEO', 'VP Engineering', 'Manager']
|
|
38
|
+
/>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## ⚙️ API Reference
|
|
44
|
+
|
|
45
|
+
### Props
|
|
46
|
+
| Prop | Type | Default | Description |
|
|
47
|
+
| :--- | :--- | :--- | :--- |
|
|
48
|
+
| `rowGroupingModel` | `string[]` | `[]` | Fields to group by (in order). |
|
|
49
|
+
| `treeData` | `boolean` | `false` | Enable tree data mode. |
|
|
50
|
+
| `getTreeDataPath` | `(row) => string[]` | `undefined` | Function to get the path for a row. |
|
|
51
|
+
| `defaultGroupingExpansionDepth` | `number` | `0` | How many levels to expand on load. |
|
|
52
|
+
| `groupingColDef` | `GridColDef` | `undefined` | Custom configuration for the generated group column. |
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 🎨 Customizing the Group Column
|
|
57
|
+
By default, OpenGridX creates a `__group__` column. You can customize its appearance:
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
<DataGrid
|
|
61
|
+
groupingColDef={{
|
|
62
|
+
headerName: 'Hierarchy',
|
|
63
|
+
width: 300,
|
|
64
|
+
renderCell: (params) => { /* custom renderer */ }
|
|
65
|
+
}}
|
|
66
|
+
/>
|
|
67
|
+
```
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
# Virtualization
|
|
2
|
+
|
|
3
|
+
The DataGrid uses **row and column virtualization** to efficiently render large datasets by only rendering the rows and columns that are currently visible in the viewport, plus a small buffer (overscan) for smooth scrolling.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Virtualization is a technique that dramatically improves performance when working with large datasets. Instead of rendering all rows in the DOM (which would be slow and memory-intensive), the grid only renders:
|
|
8
|
+
|
|
9
|
+
1. **Visible rows** - Rows currently in the viewport
|
|
10
|
+
2. **Overscan rows** - A buffer of rows above and below the viewport for smooth scrolling
|
|
11
|
+
3. **Pinned rows** - Rows that are always visible (top/bottom)
|
|
12
|
+
|
|
13
|
+
## How It Works
|
|
14
|
+
|
|
15
|
+
### Row Virtualization
|
|
16
|
+
|
|
17
|
+
The grid calculates which rows are visible based on:
|
|
18
|
+
- Current scroll position
|
|
19
|
+
- Viewport height
|
|
20
|
+
- Row height (fixed or variable)
|
|
21
|
+
- Overscan buffer (default: 5 rows)
|
|
22
|
+
|
|
23
|
+
```tsx
|
|
24
|
+
// Example: 1000 rows, but only ~15 rendered at a time
|
|
25
|
+
<DataGrid
|
|
26
|
+
rows={thousandRows}
|
|
27
|
+
columns={columns}
|
|
28
|
+
style={{ height: 600 }}
|
|
29
|
+
/>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**Performance characteristics:**
|
|
33
|
+
- ✅ Renders ~15-25 rows regardless of total dataset size
|
|
34
|
+
- ✅ Constant memory usage
|
|
35
|
+
- ✅ Smooth 60fps scrolling
|
|
36
|
+
- ✅ Supports millions of rows
|
|
37
|
+
|
|
38
|
+
### Column Virtualization
|
|
39
|
+
|
|
40
|
+
Currently, the DataGrid renders all columns. Column virtualization (rendering only visible columns) is planned for future releases.
|
|
41
|
+
|
|
42
|
+
## Configuration
|
|
43
|
+
|
|
44
|
+
### Row Height
|
|
45
|
+
|
|
46
|
+
The grid supports both fixed and variable row heights:
|
|
47
|
+
|
|
48
|
+
```tsx
|
|
49
|
+
// Fixed row height (default: 52px)
|
|
50
|
+
<DataGrid
|
|
51
|
+
rows={rows}
|
|
52
|
+
columns={columns}
|
|
53
|
+
rowHeight={40}
|
|
54
|
+
/>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Auto Height
|
|
58
|
+
|
|
59
|
+
Disable virtualization for small datasets:
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
<DataGrid
|
|
63
|
+
rows={rows}
|
|
64
|
+
columns={columns}
|
|
65
|
+
autoHeight
|
|
66
|
+
/>
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
⚠️ **Warning:** `autoHeight` disables row virtualization and renders all rows. Only use for small datasets (< 100 rows).
|
|
70
|
+
|
|
71
|
+
## Performance Optimization
|
|
72
|
+
|
|
73
|
+
### Overscan Buffer
|
|
74
|
+
|
|
75
|
+
The overscan buffer determines how many extra rows are rendered outside the viewport. A larger buffer provides smoother scrolling but uses more memory.
|
|
76
|
+
|
|
77
|
+
**Current implementation:**
|
|
78
|
+
- Default overscan: **5 rows** (above and below viewport)
|
|
79
|
+
- Total rendered rows: ~(viewport rows + 10)
|
|
80
|
+
|
|
81
|
+
**Trade-offs:**
|
|
82
|
+
- **Smaller overscan (1-3)**: Less memory, potential flickering during fast scrolling
|
|
83
|
+
- **Larger overscan (5-8)**: More memory, smoother fast scrolling
|
|
84
|
+
- **Very large overscan (10+)**: Diminishing returns, wasted rendering
|
|
85
|
+
|
|
86
|
+
### Scroll Performance
|
|
87
|
+
|
|
88
|
+
For optimal scroll performance:
|
|
89
|
+
|
|
90
|
+
1. **Use fixed row heights** when possible
|
|
91
|
+
2. **Avoid complex cell renderers** - Keep `renderCell` functions lightweight
|
|
92
|
+
3. **Memoize custom components** - Use `React.memo` for custom cell components
|
|
93
|
+
4. **Minimize re-renders** - Use stable column definitions
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
// ✅ Good: Memoized columns
|
|
97
|
+
const columns = useMemo(() => [
|
|
98
|
+
{ field: 'id', headerName: 'ID', width: 70 },
|
|
99
|
+
{ field: 'name', headerName: 'Name', width: 200 }
|
|
100
|
+
], []);
|
|
101
|
+
|
|
102
|
+
// ❌ Bad: New column array on every render
|
|
103
|
+
const columns = [
|
|
104
|
+
{ field: 'id', headerName: 'ID', width: 70 },
|
|
105
|
+
{ field: 'name', headerName: 'Name', width: 200 }
|
|
106
|
+
];
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Detail Panel Considerations
|
|
110
|
+
|
|
111
|
+
When using detail panels, row heights become variable. The grid automatically:
|
|
112
|
+
- Calculates cumulative heights for each row
|
|
113
|
+
- Adjusts scroll calculations for expanded panels
|
|
114
|
+
- Maintains smooth scrolling
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
<DataGrid
|
|
118
|
+
rows={rows}
|
|
119
|
+
columns={columns}
|
|
120
|
+
getDetailPanelContent={({ row }) => <DetailPanel row={row} />}
|
|
121
|
+
getDetailPanelHeight={() => 200}
|
|
122
|
+
/>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
## Virtualization with Grouping/Tree Data
|
|
126
|
+
|
|
127
|
+
Row grouping and tree data work seamlessly with virtualization:
|
|
128
|
+
|
|
129
|
+
```tsx
|
|
130
|
+
// Tree data with virtualization
|
|
131
|
+
<DataGrid
|
|
132
|
+
rows={rows}
|
|
133
|
+
columns={columns}
|
|
134
|
+
treeData
|
|
135
|
+
getTreeDataPath={(row) => row.path}
|
|
136
|
+
defaultGroupingExpansionDepth={-1} // Expand all
|
|
137
|
+
/>
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**Note:** When groups are collapsed, only visible rows are rendered. Expanding a group dynamically adds rows to the render list.
|
|
141
|
+
|
|
142
|
+
## Debugging Virtualization
|
|
143
|
+
|
|
144
|
+
To see which rows are being rendered:
|
|
145
|
+
|
|
146
|
+
```tsx
|
|
147
|
+
// Add this to your column definition
|
|
148
|
+
{
|
|
149
|
+
field: 'debug',
|
|
150
|
+
headerName: 'Debug',
|
|
151
|
+
renderCell: (params) => {
|
|
152
|
+
console.log('Rendering row:', params.row.id);
|
|
153
|
+
return params.row.id;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
You should see console logs only for visible rows + overscan buffer.
|
|
159
|
+
|
|
160
|
+
## Known Limitations
|
|
161
|
+
|
|
162
|
+
1. **Column virtualization** - Not yet implemented (all columns are rendered)
|
|
163
|
+
2. **Dynamic row heights** - Requires full dataset scan for accurate scroll calculations
|
|
164
|
+
3. **Horizontal scrolling** - May show brief flicker with very wide grids
|
|
165
|
+
|
|
166
|
+
## Future Improvements
|
|
167
|
+
|
|
168
|
+
- [ ] Column virtualization for grids with 50+ columns
|
|
169
|
+
- [ ] Adaptive overscan based on scroll velocity
|
|
170
|
+
- [ ] Virtual scrollbar for extremely large datasets (millions of rows)
|
|
171
|
+
- [ ] Intersection Observer API for better scroll detection
|
|
172
|
+
|
|
173
|
+
## Comparison with MUI X DataGrid
|
|
174
|
+
|
|
175
|
+
| Feature | Aui DataGrid | MUI X DataGrid |
|
|
176
|
+
|---------|--------------|----------------|
|
|
177
|
+
| Row virtualization | ✅ Yes | ✅ Yes |
|
|
178
|
+
| Column virtualization | ❌ Planned | ✅ Yes (Pro) |
|
|
179
|
+
| Variable row heights | ✅ Yes | ✅ Yes |
|
|
180
|
+
| Overscan buffer | 5 rows | 3-8 rows (adaptive) |
|
|
181
|
+
| Max recommended rows | 100,000+ | 100,000+ |
|
|
182
|
+
|
|
183
|
+
## Related Documentation
|
|
184
|
+
|
|
185
|
+
- [Performance Best Practices](../performance.md)
|
|
186
|
+
- [Row Grouping](./tree-data-grouping.md)
|
|
187
|
+
- [Tree Data](./tree-data-grouping.md)
|
|
188
|
+
- [Detail Panel](./master-detail.md)
|