@opencorestack/opengridx 0.1.6 → 0.1.8

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.
Files changed (130) hide show
  1. package/CHANGELOG.md +30 -1
  2. package/README.md +9 -0
  3. package/dist/index.d.ts +12 -1
  4. package/dist/opengridx.css +1 -1
  5. package/dist/opengridx.es.js +2505 -2450
  6. package/dist/opengridx.es.js.map +1 -1
  7. package/dist/opengridx.umd.js +12 -12
  8. package/dist/opengridx.umd.js.map +1 -1
  9. package/docs/API_REFERENCE.md +177 -0
  10. package/docs/README.md +60 -0
  11. package/docs/components/cell.md +44 -0
  12. package/docs/components/column-group-header.md +57 -0
  13. package/docs/components/column-resize.md +63 -0
  14. package/docs/components/column-visibility.md +61 -0
  15. package/docs/components/datagrid.md +70 -0
  16. package/docs/components/filter-panel.md +26 -0
  17. package/docs/components/header.md +39 -0
  18. package/docs/components/pagination.md +34 -0
  19. package/docs/components/row.md +31 -0
  20. package/docs/components/toolbar.md +40 -0
  21. package/docs/components/tooltip.md +68 -0
  22. package/docs/customization/slots-api.md +227 -0
  23. package/docs/customization/theming.md +293 -0
  24. package/docs/features/aggregation-pivot.md +79 -0
  25. package/docs/features/cell-spanning.md +520 -0
  26. package/docs/features/clipboard.md +76 -0
  27. package/docs/features/custom-pagination.md +143 -0
  28. package/docs/features/data-source.md +72 -0
  29. package/docs/features/editing-reordering.md +99 -0
  30. package/docs/features/export-guide.md +434 -0
  31. package/docs/features/filtering.md +83 -0
  32. package/docs/features/infinite-scroll.md +87 -0
  33. package/docs/features/list-view.md +65 -0
  34. package/docs/features/loading-states.md +68 -0
  35. package/docs/features/master-detail.md +46 -0
  36. package/docs/features/pinning.md +67 -0
  37. package/docs/features/selection.md +70 -0
  38. package/docs/features/sorting-pagination.md +66 -0
  39. package/docs/features/state-persistence.md +67 -0
  40. package/docs/features/tree-data-grouping.md +67 -0
  41. package/docs/features/virtualization.md +188 -0
  42. package/docs/roadmap.md +71 -0
  43. package/lib/components/Cell/Cell.css +119 -0
  44. package/lib/components/Cell/Cell.tsx +264 -0
  45. package/lib/components/Cell/GridEditInputCell.css +62 -0
  46. package/lib/components/Cell/GridEditInputCell.tsx +152 -0
  47. package/lib/components/ColumnGroupHeader/ColumnGroupHeader.css +67 -0
  48. package/lib/components/ColumnGroupHeader/ColumnGroupHeader.tsx +220 -0
  49. package/lib/components/ColumnResizeHandle/ColumnResizeHandle.css +31 -0
  50. package/lib/components/ColumnResizeHandle/ColumnResizeHandle.tsx +85 -0
  51. package/lib/components/ColumnVisibilityPanel/ColumnVisibilityPanel.css +137 -0
  52. package/lib/components/ColumnVisibilityPanel/ColumnVisibilityPanel.tsx +190 -0
  53. package/lib/components/DataGrid/DataGrid.css +224 -0
  54. package/lib/components/DataGrid/DataGrid.tsx +2269 -0
  55. package/lib/components/DetailPanel/DetailPanel.css +36 -0
  56. package/lib/components/DetailPanel/DetailPanel.tsx +34 -0
  57. package/lib/components/FilterPanel/FilterPanel.css +196 -0
  58. package/lib/components/FilterPanel/FilterPanel.tsx +214 -0
  59. package/lib/components/FilterPanel/index.ts +1 -0
  60. package/lib/components/Header/ColumnMenu.css +68 -0
  61. package/lib/components/Header/ColumnMenu.tsx +249 -0
  62. package/lib/components/Header/Header.css +224 -0
  63. package/lib/components/Header/Header.tsx +516 -0
  64. package/lib/components/ListView/ListView.css +112 -0
  65. package/lib/components/ListView/ListViewRow.tsx +63 -0
  66. package/lib/components/Pagination/Pagination.css +91 -0
  67. package/lib/components/Pagination/Pagination.tsx +151 -0
  68. package/lib/components/QuickFilter/QuickFilter.css +23 -0
  69. package/lib/components/QuickFilter/QuickFilter.tsx +79 -0
  70. package/lib/components/Row/Row.css +126 -0
  71. package/lib/components/Row/Row.tsx +377 -0
  72. package/lib/components/Skeleton/Skeleton.css +55 -0
  73. package/lib/components/Skeleton/Skeleton.tsx +22 -0
  74. package/lib/components/SkeletonRow/SkeletonRow.css +32 -0
  75. package/lib/components/SkeletonRow/SkeletonRow.tsx +89 -0
  76. package/lib/components/SkeletonRow/index.ts +1 -0
  77. package/lib/components/Toolbar/GlobalSearch.css +110 -0
  78. package/lib/components/Toolbar/GlobalSearch.tsx +167 -0
  79. package/lib/components/Toolbar/GridToolbar.css +221 -0
  80. package/lib/components/Toolbar/GridToolbar.tsx +658 -0
  81. package/lib/components/Toolbar/PivotPanel.css +212 -0
  82. package/lib/components/Toolbar/PivotPanel.tsx +239 -0
  83. package/lib/components/Tooltip/Tooltip.css +59 -0
  84. package/lib/components/Tooltip/Tooltip.tsx +106 -0
  85. package/lib/components/ui/Button.css +89 -0
  86. package/lib/components/ui/Button.tsx +39 -0
  87. package/lib/components/ui/Checkbox.css +71 -0
  88. package/lib/components/ui/Checkbox.tsx +66 -0
  89. package/lib/components/ui/DragHandleIcon.css +19 -0
  90. package/lib/components/ui/DragHandleIcon.tsx +18 -0
  91. package/lib/components/ui/ExpandIcon.css +38 -0
  92. package/lib/components/ui/ExpandIcon.tsx +75 -0
  93. package/lib/components/ui/Input.css +59 -0
  94. package/lib/components/ui/Input.tsx +45 -0
  95. package/lib/components/ui/index.ts +15 -0
  96. package/lib/hooks/core/useDataGrid.ts +392 -0
  97. package/lib/hooks/core/useGridApiRef.ts +10 -0
  98. package/lib/hooks/features/useAggregation.ts +143 -0
  99. package/lib/hooks/features/useGridClipboard.ts +133 -0
  100. package/lib/hooks/features/useGridDataSource.ts +190 -0
  101. package/lib/hooks/features/useGridEditing.ts +100 -0
  102. package/lib/hooks/features/useGridSpanning.ts +349 -0
  103. package/lib/hooks/features/usePivot.ts +174 -0
  104. package/lib/hooks/useColumnReorder.ts +114 -0
  105. package/lib/hooks/useRowGrouping.ts +302 -0
  106. package/lib/hooks/useRowReorder.ts +83 -0
  107. package/lib/hooks/useTreeData.ts +323 -0
  108. package/lib/index.ts +106 -0
  109. package/lib/state/index.ts +17 -0
  110. package/lib/state/types.ts +48 -0
  111. package/lib/state/useGridStateStorage.ts +113 -0
  112. package/lib/styles/base/reset.css +21 -0
  113. package/lib/styles/base/variables.css +161 -0
  114. package/lib/styles/opengridx.css +27 -0
  115. package/lib/styles/opengridx.css.d.ts +4 -0
  116. package/lib/theme/DataGridThemeProvider.tsx +276 -0
  117. package/lib/theme/defaultStyles.ts +0 -0
  118. package/lib/theme/index.ts +21 -0
  119. package/lib/theme/presets.ts +148 -0
  120. package/lib/theme/types.ts +155 -0
  121. package/lib/types/index.ts +764 -0
  122. package/lib/utils/export/exportToExcelAdvanced.ts +516 -0
  123. package/lib/utils/export/index.ts +550 -0
  124. package/lib/utils/filtering/index.ts +240 -0
  125. package/lib/utils/pinning/index.ts +282 -0
  126. package/lib/utils/sorting/index.ts +55 -0
  127. package/lib/utils/virtualization/index.ts +106 -0
  128. package/lib/vite-env.d.ts +1 -0
  129. package/llms.txt +2 -1
  130. package/package.json +12 -4
@@ -0,0 +1,764 @@
1
+
2
+
3
+ /** Unique identifier for a row (string or number). */
4
+ export type GridRowId = string | number;
5
+
6
+ /** Base interface for a grid row data object. */
7
+ export interface GridRowModel {
8
+ /** Uniquely identifies the row. */
9
+ id: GridRowId;
10
+ /** Any other dynamic row properties. */
11
+ [key: string]: any;
12
+ }
13
+
14
+ export type GridAlignment = 'left' | 'center' | 'right';
15
+
16
+ /** Represents a row node in the grid's hierarchical tree structure. */
17
+ export interface GridTreeNode {
18
+ /** Unique ID of the row. */
19
+ id: GridRowId;
20
+ /** ID of the parent node, or null if root. */
21
+ parentId: GridRowId | null;
22
+ /** Current depth in the tree (0 for root). */
23
+ depth: number;
24
+ /** The key used for grouping at this level. */
25
+ groupingKey: string;
26
+
27
+ /** The field this node is grouping by. */
28
+ groupingField?: string;
29
+ /** The actual value being grouped. */
30
+ groupingValue?: any;
31
+
32
+ /** Computed aggregation results for this group. */
33
+ aggregatedValues?: Record<string, any>;
34
+ /** Position of the aggregation row relative to the group. */
35
+ aggregationPosition?: 'inline' | 'footer' | null;
36
+ /** Current expansion state. */
37
+ isExpanded: boolean;
38
+ /** IDs of the direct child nodes. */
39
+ children?: GridRowId[];
40
+ /** Display label for the group. */
41
+ label?: string;
42
+
43
+ /** Total count of all descendants (recursive). */
44
+ descendantCount?: number;
45
+
46
+ /** Count of children on the server (for lazy loading). */
47
+ serverChildrenCount?: number;
48
+ }
49
+
50
+ export type GridSortDirection = 'asc' | 'desc' | null;
51
+
52
+ /**
53
+ * Metadata for a single column.
54
+ * Governs rendering, sorting, filtering, and data transformation.
55
+ */
56
+ export interface GridColDef<R extends GridRowModel = GridRowModel> {
57
+ /** The unique identifier for the column, typically matching a row object key. */
58
+ field: string;
59
+ /** Text displayed in the column header. */
60
+ headerName?: string;
61
+ /** Tooltip or accessible description for the header. */
62
+ description?: string;
63
+
64
+ /** If true, this column can be used as a grouping dimension. */
65
+ groupable?: boolean;
66
+
67
+ /** If true, this column can be summarized using aggregation functions. */
68
+ aggregable?: boolean;
69
+ /** List of allowed aggregation functions (e.g., ['sum', 'avg']). */
70
+ availableAggregationFunctions?: string[];
71
+
72
+ /** Width in pixels or a percentage string. Defaults to automatic calculation. */
73
+ width?: number | string;
74
+ /** Minimum width in pixels. */
75
+ minWidth?: number;
76
+ /** Maximum width in pixels. */
77
+ maxWidth?: number;
78
+ /** Relative flex weight used when distributing extra space. */
79
+ flex?: number;
80
+ /** Content alignment within cells. */
81
+ align?: GridAlignment;
82
+ /** Content alignment within the header cell. */
83
+ headerAlign?: GridAlignment;
84
+ /** If false, sorting is disabled for this column. */
85
+ sortable?: boolean;
86
+ /** If false, filtering is disabled for this column. */
87
+ filterable?: boolean;
88
+ /** If false, the user cannot manually resize this column. */
89
+ resizable?: boolean;
90
+ /** If false, the column cannot be hidden via the UI. */
91
+ hideable?: boolean;
92
+ /** If false, the column cannot be pinned. */
93
+ pinnable?: boolean;
94
+ /** Type used to determine default operators and formatting logic. */
95
+ type?: 'string' | 'number' | 'date' | 'boolean' | 'singleSelect' | 'image';
96
+ /** Options used for 'singleSelect' type. */
97
+ valueOptions?: Array<string | number | { value: any; label: string }>;
98
+
99
+ /** Function to compute a cell value from raw row data. */
100
+ valueGetter?: (params: GridValueGetterParams<R>) => any;
101
+ /** Function to format a value into a human-readable string. */
102
+ valueFormatter?: (params: GridValueFormatterParams<R>) => string;
103
+ /** Custom component or element to render in the cell. */
104
+ renderCell?: (params: GridRenderCellParams<R>) => React.ReactNode;
105
+ /** Custom component or element to render in the header. */
106
+ renderHeader?: (params: GridRenderHeaderParams) => React.ReactNode;
107
+ /** Component to render when the cell is in edit mode. */
108
+ renderEditCell?: (params: GridRenderCellParams<R>) => React.ReactNode;
109
+ /** If true, the cell's value can be modified by the user. */
110
+ editable?: boolean;
111
+ /** Optional stacking order (CSS z-index). */
112
+ zIndex?: number;
113
+ /** If true, the column kebab/hamburger menu is disabled. */
114
+ disableColumnMenu?: boolean;
115
+
116
+ /** Number of columns this cell should occupy horizontally. */
117
+ colSpan?: number | ((params: GridRenderCellParams<R>) => number);
118
+ /** Number of rows this cell should occupy vertically. */
119
+ rowSpan?: number | ((params: GridRenderCellParams<R>) => number);
120
+
121
+ /**
122
+ * Custom CSS class applied to every cell in this column.
123
+ * Can be a static string or a function that receives the cell params and returns a string.
124
+ * Useful for per-row conditional styling without custom renderCell.
125
+ * @example
126
+ * cellClassName: 'my-class'
127
+ * cellClassName: ({ value }) => value > 100 ? 'cell--high' : 'cell--low'
128
+ */
129
+ cellClassName?: string | ((params: GridRenderCellParams<R>) => string);
130
+
131
+ /**
132
+ * Custom CSS class applied to the header cell of this column.
133
+ * @example
134
+ * headerClassName: 'my-header'
135
+ */
136
+ headerClassName?: string;
137
+
138
+ /**
139
+ * If false, this column is excluded from all exports (CSV, Excel, JSON, Print).
140
+ * Useful for action columns with buttons.
141
+ * @default true
142
+ */
143
+ exportable?: boolean;
144
+ }
145
+
146
+ /** Column definition used exclusively in List View mode. */
147
+ export interface GridListViewColDef<R extends GridRowModel = GridRowModel> {
148
+ field: string;
149
+ renderCell: (params: GridRenderCellParams<R>) => React.ReactNode;
150
+ }
151
+
152
+ /**
153
+ * Describes one level of column grouping.
154
+ * Groups can be nested by placing child GridColumnGroup objects in `children`.
155
+ * Leaf groups reference actual column fields via `children: string[]`.
156
+ *
157
+ * Example – two levels:
158
+ * [
159
+ * { groupId: 'q1', headerName: 'Q1 2024', children: ['q1Sales', 'q1Target'] },
160
+ * { groupId: 'info', headerName: 'Info', children: [
161
+ * { groupId: 'personal', headerName: 'Personal', children: ['name', 'age'] }
162
+ * ] }
163
+ * ]
164
+ */
165
+ export interface GridColumnGroup {
166
+ /** Unique identifier for this group. */
167
+ groupId: string;
168
+ /** Text displayed in the group header cell. */
169
+ headerName: string;
170
+ /** Optional override for the header cell background color. */
171
+ headerClassName?: string;
172
+ /**
173
+ * Either an array of column field strings (leaf group)
174
+ * or an array of child GridColumnGroup objects (nested group).
175
+ */
176
+ children: Array<string | GridColumnGroup>;
177
+ }
178
+
179
+ export type GridColumnGroupingModel = GridColumnGroup[];
180
+
181
+
182
+ /** Parameters passed to the `valueGetter` function. */
183
+ export interface GridValueGetterParams<R extends GridRowModel = GridRowModel> {
184
+ /** The row object. */
185
+ row: R;
186
+ /** The field name. */
187
+ field: string;
188
+ /** The raw value from the row object. */
189
+ value: any;
190
+ }
191
+
192
+ /** Parameters passed to the `valueFormatter` function. */
193
+ export interface GridValueFormatterParams<R extends GridRowModel = GridRowModel> {
194
+ /** The raw value to format. */
195
+ value: any;
196
+ /** The row object. */
197
+ row: R;
198
+ /** The field name. */
199
+ field: string;
200
+ }
201
+
202
+ /** Parameters passed to the `renderCell` function. */
203
+ export interface GridRenderCellParams<R extends GridRowModel = GridRowModel> {
204
+ /** The current cell value. */
205
+ value: any;
206
+ /** The row object. */
207
+ row: R;
208
+ /** The field name and unique ID. */
209
+ field: string;
210
+ /** The column definition. */
211
+ colDef: GridColDef<R>;
212
+ /** The index of the row in the currently visible dataset. */
213
+ rowIndex: number;
214
+ /** The index of the column. */
215
+ colIndex: number;
216
+ }
217
+
218
+ export interface GridRenderHeaderParams {
219
+ field: string;
220
+ colDef: GridColDef;
221
+ colIndex: number;
222
+ }
223
+
224
+ export interface GridSortModel {
225
+ field: string;
226
+ sort: GridSortDirection;
227
+ }
228
+
229
+ export interface GridSortItem {
230
+ field: string;
231
+ sort: 'asc' | 'desc';
232
+ }
233
+
234
+ export type GridFilterOperator =
235
+ | 'contains'
236
+ | 'equals'
237
+ | 'startsWith'
238
+ | 'endsWith'
239
+ | 'isEmpty'
240
+ | 'isNotEmpty'
241
+ | 'isAnyOf'
242
+ | '>'
243
+ | '>='
244
+ | '<'
245
+ | '<='
246
+ | '!='
247
+ | 'is'
248
+ | 'not';
249
+
250
+ /** Describes a filter condition for a specific column. */
251
+ export interface GridFilterItem {
252
+ /** Optional ID for the filter item. */
253
+ id?: string | number;
254
+ /** The field name to filter. */
255
+ field: string;
256
+ /** The comparison operator. */
257
+ operator: GridFilterOperator;
258
+ /** The value to compare against. */
259
+ value?: any;
260
+ }
261
+
262
+ /** Describes a group of filters combined with a logical operator. */
263
+ export interface GridFilterGroup {
264
+ /** Optional ID for the group. */
265
+ id?: string | number;
266
+ /** Logical operator to join child items ('and' | 'or'). */
267
+ logicOperator: 'and' | 'or';
268
+ /** Array of child filter items or groups. */
269
+ items: (GridFilterItem | GridFilterGroup)[];
270
+ }
271
+
272
+ /** The overall state of grid filtering. */
273
+ export interface GridFilterModel {
274
+ /** Root-level filter items or groups. */
275
+ items?: (GridFilterItem | GridFilterGroup)[];
276
+ /** Global logical operator (defaults to 'and'). */
277
+ logicOperator?: 'and' | 'or';
278
+ /** Array of strings used for the quick search feature across all columns. */
279
+ quickFilterValues?: string[];
280
+ }
281
+
282
+ export type GridPinnedPosition = 'left' | 'right';
283
+
284
+ export type GridColumnVisibilityModel = Record<string, boolean>;
285
+
286
+ /** Configuration for pinning columns to the grid edges. */
287
+ export interface GridColumnPinning {
288
+ /** Field strings to pin to the left edge. */
289
+ left?: string[];
290
+ /** Field strings to pin to the right edge. */
291
+ right?: string[];
292
+ }
293
+
294
+ /** Configuration for pinning rows to the grid viewport. */
295
+ export interface GridRowPinning {
296
+ /** Row IDs to pin to the top. */
297
+ top?: GridRowId[];
298
+ /** Row IDs to pin to the bottom. */
299
+ bottom?: GridRowId[];
300
+ }
301
+
302
+ export interface GridColumnOrderChangeParams {
303
+ column: GridColDef;
304
+ oldIndex: number;
305
+ targetIndex: number;
306
+ }
307
+
308
+ export type GridColumnOrder = string[];
309
+
310
+ export interface GridRowOrderChangeParams<R extends GridRowModel = GridRowModel> {
311
+ row: R;
312
+ oldIndex: number;
313
+ targetIndex: number;
314
+ }
315
+
316
+ export interface GridGetRowsParams {
317
+ startRow: number;
318
+ endRow: number;
319
+ sortModel: GridSortItem[];
320
+ filterModel: GridFilterModel;
321
+ groupKeys: string[];
322
+ aggregationModel?: GridAggregationModel;
323
+ }
324
+
325
+ export interface GridGetRowsResponse<R extends GridRowModel = GridRowModel> {
326
+ rows: R[];
327
+ rowCount?: number;
328
+ aggregationResults?: Record<string, any>;
329
+ }
330
+
331
+ /**
332
+ * Interface for providing data to the grid from a remote source.
333
+ * Enables server-side sorting, filtering, and pagination.
334
+ */
335
+ export interface GridDataSource<R extends GridRowModel = GridRowModel> {
336
+ /**
337
+ * Fetches a chunk of rows based on current grid state.
338
+ * @param params Sorting, filtering, and range parameters.
339
+ */
340
+ getRows: (params: GridGetRowsParams) => Promise<GridGetRowsResponse<R>>;
341
+ /**
342
+ * Optional: Fetches aggregation results for the entire dataset.
343
+ */
344
+ getAggregations?: (params: Omit<GridGetRowsParams, 'startRow' | 'endRow'>) => Promise<Record<string, any>>;
345
+ }
346
+
347
+ export interface GridPaginationModel {
348
+ page: number;
349
+ pageSize: number;
350
+ }
351
+
352
+ export type GridRowSelectionModel = GridRowId[];
353
+
354
+ export interface GridPinnedColumns {
355
+ left?: string[];
356
+ right?: string[];
357
+ }
358
+
359
+ export interface GridPinnedRows<R extends GridRowModel = GridRowModel> {
360
+ top?: R[];
361
+ bottom?: R[];
362
+ }
363
+
364
+ export interface GridVirtualizationState {
365
+ renderContext: GridRenderContext;
366
+ scrollTop: number;
367
+ scrollLeft: number;
368
+ }
369
+
370
+ export type GridRowGroupingModel = string[];
371
+
372
+ export type GridAggregationFunction = (values: any[]) => any;
373
+
374
+ export interface GridAggregationModel {
375
+ [field: string]: string;
376
+ }
377
+
378
+ export type GridAggregationResult = Record<string, any>;
379
+
380
+ export type GridAggregationPosition = 'footer' | 'inline' | 'both';
381
+
382
+ export type GridPivotAggFn = 'sum' | 'avg' | 'count' | 'min' | 'max';
383
+
384
+ export interface GridPivotValueField {
385
+ field: string;
386
+ aggFn: GridPivotAggFn;
387
+ headerName?: string;
388
+ }
389
+
390
+ export interface GridPivotModel {
391
+ rowFields: string[];
392
+ columnFields: string[];
393
+ valueFields: GridPivotValueField[];
394
+ }
395
+
396
+ export interface GridRenderContext {
397
+ firstRowIndex: number;
398
+ lastRowIndex: number;
399
+ firstColumnIndex: number;
400
+ lastColumnIndex: number;
401
+ }
402
+
403
+ export interface GridState {
404
+ rows: {
405
+ idRowsLookup: Map<GridRowId, GridRowModel>;
406
+ allRows: GridRowId[];
407
+ };
408
+ sorting: {
409
+ sortModel: GridSortItem[];
410
+ };
411
+ filter: {
412
+ filterModel: GridFilterModel;
413
+ };
414
+ pagination: {
415
+ paginationModel: GridPaginationModel;
416
+ rowCount: number;
417
+ };
418
+ columns: {
419
+ all: GridColDef[];
420
+ lookup: Map<string, GridColDef>;
421
+ orderedFields: string[];
422
+ columnVisibilityModel: GridColumnVisibilityModel;
423
+ };
424
+ selection: {
425
+ selectedRows: Set<GridRowId>;
426
+ };
427
+ pinning: {
428
+ pinnedColumns: GridPinnedColumns;
429
+ pinnedRows: GridPinnedRows;
430
+ };
431
+ virtualization: GridVirtualizationState;
432
+ dimensions: {
433
+ rowHeight: number;
434
+ headerHeight: number;
435
+ viewportWidth: number;
436
+ viewportHeight: number;
437
+ };
438
+ dataSource: {
439
+ loading: boolean;
440
+ error: any;
441
+ };
442
+ }
443
+
444
+ export interface GridRowScrollEndParams {
445
+ visibleTop: number;
446
+ visibleBottom: number;
447
+ viewportHeight: number;
448
+ }
449
+
450
+ /**
451
+ * Main properties for the DataGrid component.
452
+ */
453
+ export interface DataGridProps<R extends GridRowModel = GridRowModel> {
454
+ /** The dataset to display in the grid. */
455
+ rows: R[];
456
+ /** Column definitions governing how data is displayed and interacted with. */
457
+ columns: GridColDef<R>[];
458
+
459
+ /** Function to extract a unique ID from a row object. Defaults to `row.id`. */
460
+ getRowId?: (row: R) => GridRowId;
461
+
462
+ /** Height of each row in pixels. Defaults to 52. */
463
+ rowHeight?: number;
464
+ /** Height of the header row in pixels. Defaults to 56. */
465
+ headerHeight?: number;
466
+ /** If true, the grid height will adjust to match the total height of its rows. */
467
+ autoHeight?: boolean;
468
+
469
+ /** Sorting mode: 'client' (default) or 'server'. */
470
+ sortingMode?: 'client' | 'server';
471
+ /** The current sorting model. */
472
+ sortModel?: GridSortItem[];
473
+ /** Callback fired when the sorting model changes. */
474
+ onSortModelChange?: (model: GridSortItem[]) => void;
475
+
476
+ /** Filtering mode: 'client' (default) or 'server'. */
477
+ filterMode?: 'client' | 'server';
478
+ /** The current filter model. */
479
+ filterModel?: GridFilterModel;
480
+ /** Callback fired when the filter model changes. */
481
+ onFilterModelChange?: (model: GridFilterModel) => void;
482
+
483
+ /** If true, pagination UI and logic are enabled. */
484
+ pagination?: boolean;
485
+ /** Pagination mode: 'client' (default), 'server', or 'infinite'. */
486
+ paginationMode?: 'client' | 'server' | 'infinite';
487
+ /** The current pagination state (page and pageSize). */
488
+ paginationModel?: GridPaginationModel;
489
+ /** Callback fired when the pagination model changes. */
490
+ onPaginationModelChange?: (model: GridPaginationModel) => void;
491
+ /** Array of available page sizes (e.g., [10, 25, 50]). */
492
+ pageSizeOptions?: number[];
493
+ /** Total number of rows (required for server-side pagination). */
494
+ rowCount?: number;
495
+
496
+ /** Defines which columns are pinned to the sides. */
497
+ pinnedColumns?: GridColumnPinning;
498
+ /** Callback fired when column pinning changes. */
499
+ onPinnedColumnsChange?: (model: GridColumnPinning) => void;
500
+
501
+ /** Controls which columns are visible. */
502
+ columnVisibilityModel?: GridColumnVisibilityModel;
503
+ /** Callback fired when column visibility changes. */
504
+ onColumnVisibilityModelChange?: (model: GridColumnVisibilityModel) => void;
505
+
506
+ /** Defines which rows are pinned to the top or bottom. */
507
+ pinnedRows?: GridRowPinning;
508
+ /** Callback fired when row pinning changes. */
509
+ onPinnedRowsChange?: (model: GridRowPinning) => void;
510
+
511
+ /** If true, a column of checkboxes is added for row selection. */
512
+ checkboxSelection?: boolean;
513
+ /** If true, the checkbox column remains visible during horizontal scrolling. */
514
+ pinCheckboxColumn?: boolean;
515
+ /** If true, the expansion column (for Master-Detail) remains visible during horizontal scrolling. */
516
+ pinExpandColumn?: boolean;
517
+ /** The current selection state (array of row IDs). */
518
+ rowSelectionModel?: GridRowSelectionModel;
519
+ /** Callback fired when the selection model changes. */
520
+ onRowSelectionModelChange?: (model: GridRowSelectionModel) => void;
521
+ /** If true, clicking a row won't toggle its selection. */
522
+ disableRowSelectionOnClick?: boolean;
523
+ /** If true, the user can only select a single row at a time. */
524
+ disableMultipleRowSelection?: boolean;
525
+
526
+ /** If true, a loading shimmer/skeleton is displayed. */
527
+ loading?: boolean;
528
+ /** Visual density of the grid. */
529
+ density?: 'compact' | 'standard' | 'comfortable';
530
+
531
+ /** Optional custom CSS class for the grid container. */
532
+ className?: string;
533
+ /** Optional custom inline styles for the grid container. */
534
+ style?: React.CSSProperties;
535
+ /** Total height of the grid container (pixels or percentage). */
536
+ height?: number | string;
537
+
538
+ /** ARIA label for accessibility. */
539
+ ariaLabel?: string;
540
+ /** Message displayed when there are no rows to show. */
541
+ noRowsLabel?: string;
542
+
543
+ /** Advanced: The starting internal state of the grid. */
544
+ initialState?: import('../state/types').GridInitialState;
545
+ /** Advanced: Callback fired for every internal state update. */
546
+ onStateChange?: (state: import('../state/types').GridState) => void;
547
+
548
+ /** Callback fired when a row is clicked. */
549
+ onRowClick?: (params: GridRowParams<R>) => void;
550
+ /** Callback fired when a cell is clicked. */
551
+ onCellClick?: (params: GridCellParams<R>) => void;
552
+
553
+ /** Renders the detail panel content for a row in Master-Detail mode. */
554
+ getDetailPanelContent?: (params: GridDetailPanelParams<R>) => React.ReactNode;
555
+ /** Defines the height of the detail panel. */
556
+ getDetailPanelHeight?: (params: GridDetailPanelParams<R>) => GridDetailPanelHeight;
557
+ /** Controlled state for expanded detail panels. */
558
+ detailPanelExpandedRowIds?: Set<GridRowId>;
559
+ /** Callback fired when expanded detail panels change. */
560
+ onDetailPanelExpandedRowIdsChange?: (expandedRowIds: Set<GridRowId>) => void;
561
+
562
+ /** If true, manual column reordering via drag-and-drop is disabled. */
563
+ disableColumnReorder?: boolean;
564
+ /** Controlled horizontal order of column fields. */
565
+ columnOrder?: GridColumnOrder;
566
+ /** Callback fired when column order changes. */
567
+ onColumnOrderChange?: (params: GridColumnOrderChangeParams) => void;
568
+
569
+ /** If true, rows can be reordered via drag-and-drop. */
570
+ rowReordering?: boolean;
571
+ /** Callback fired when rows are reordered. */
572
+ onRowOrderChange?: (params: GridRowOrderChangeParams<R>) => void;
573
+
574
+ /** If true, enables hierarchical tree data display. */
575
+ treeData?: boolean;
576
+ /** Function to get the path (array of strings) for a row in Tree Data mode. */
577
+ getTreeDataPath?: (row: R) => string[];
578
+ /** Optional override for the grouping column. */
579
+ groupingColDef?: GridColDef<R>;
580
+ /** Initial expansion depth for Tree Data. */
581
+ defaultGroupingExpansionDepth?: number;
582
+
583
+ /** Controlled state for row grouping. */
584
+ rowGroupingModel?: GridRowGroupingModel;
585
+ /** Callback fired when row grouping changes. */
586
+ onRowGroupingModelChange?: (model: GridRowGroupingModel) => void;
587
+ /** Controlled state for data aggregation (e.g., { salary: 'sum' }). */
588
+ aggregationModel?: GridAggregationModel;
589
+ /** Callback fired when aggregation model changes. */
590
+ onAggregationModelChange?: (model: GridAggregationModel) => void;
591
+ /** Advanced: Controls where aggregation results appear relative to groups. */
592
+ getAggregationPosition?: (groupNode: GridTreeNode | null) => 'inline' | 'footer' | null;
593
+
594
+ /** If true, switches the grid to multidimensional Pivot Mode. */
595
+ pivotMode?: boolean;
596
+ /** Controlled state for pivot configuration (rows, columns, values). */
597
+ pivotModel?: GridPivotModel;
598
+ /** Callback fired when pivot model changes. */
599
+ onPivotModelChange?: (model: GridPivotModel) => void;
600
+
601
+ /** Predicate to control cell editability on a per-cell basis. */
602
+ isCellEditable?: (params: GridCellParams<R>) => boolean;
603
+ /** Callback to process an updated row after inline editing. Supports promises and validation. */
604
+ processRowUpdate?: (newRow: R, oldRow: R) => R | Promise<R>;
605
+ /** Callback fired if `processRowUpdate` throws or rejects. */
606
+ onProcessRowUpdateError?: (error: any) => void;
607
+
608
+ /** Interface for connecting the grid to an external (server-side) data source. */
609
+ dataSource?: GridDataSource<R>;
610
+ /** Callback fired when scrolling reaches the bottom of the grid viewport. */
611
+ onRowsScrollEnd?: (params: GridRowScrollEndParams) => void;
612
+
613
+ /** Advanced: Reactive reference to the internal API for imperative control. */
614
+ apiRef?: React.MutableRefObject<GridApi>;
615
+
616
+ /** Custom components to replace internal grid parts. */
617
+ slots?: {
618
+ /** Component rendered as the grid toolbar. */
619
+ toolbar?: React.ComponentType<any>;
620
+ /** Component rendered as the pagination control. */
621
+ pagination?: React.ComponentType<any>;
622
+ /** Component rendered when the grid is empty. */
623
+ noRowsOverlay?: React.ComponentType<any>;
624
+ /** Component rendered during loading states. */
625
+ loadingOverlay?: React.ComponentType<any>;
626
+ /** Component rendered at the very bottom of the grid. */
627
+ footer?: React.ComponentType<any>;
628
+ };
629
+ /** Properties passed directly to custom slots. */
630
+ slotProps?: {
631
+ toolbar?: any;
632
+ pagination?: any;
633
+ noRowsOverlay?: any;
634
+ loadingOverlay?: any;
635
+ footer?: any;
636
+ };
637
+
638
+ /** When true, renders the grid as a single-column list of cards. Perfect for mobile/responsive views. */
639
+ listView?: boolean;
640
+ /** The column definition used in list view. Must supply a `renderCell` function. */
641
+ listViewColumn?: GridListViewColDef<R>;
642
+
643
+ /**
644
+ * Defines column groups rendered as spanning header rows above the normal
645
+ * column headers, supporting multiple levels of nesting.
646
+ */
647
+ columnGroupingModel?: GridColumnGroupingModel;
648
+ }
649
+
650
+ export interface GridEditCellProps<V = any> {
651
+ id: GridRowId;
652
+ field: string;
653
+ value?: V;
654
+ formattedValue?: string;
655
+ }
656
+
657
+ export type GridRowModes = 'view' | 'edit';
658
+
659
+ export interface GridRowModesModel {
660
+ [id: GridRowId]: { mode: GridRowModes; fieldToFocus?: string };
661
+ }
662
+
663
+ export interface GridRowParams<R extends GridRowModel = GridRowModel> {
664
+ row: R;
665
+ id: GridRowId;
666
+ rowIndex: number;
667
+ }
668
+
669
+ export interface GridCellParams<R extends GridRowModel = GridRowModel> {
670
+ row: R;
671
+ field: string;
672
+ value: any;
673
+ colDef: GridColDef<R>;
674
+ rowIndex: number;
675
+ colIndex: number;
676
+ }
677
+
678
+ export interface GridDetailPanelParams<R extends GridRowModel = GridRowModel> {
679
+ row: R;
680
+ id: GridRowId;
681
+ rowIndex: number;
682
+ }
683
+
684
+ export type GridDetailPanelHeight = number | 'auto';
685
+
686
+ export type GridDetailPanelContent<R extends GridRowModel = GridRowModel> =
687
+ | React.ReactNode
688
+ | ((params: GridDetailPanelParams<R>) => React.ReactNode);
689
+
690
+ export interface GridDetailPanelState {
691
+ expandedRowIds: Set<GridRowId>;
692
+ contentCache: Map<GridRowId, React.ReactNode>;
693
+ }
694
+
695
+ /**
696
+ * The Imperative API for interacting with the DataGrid.
697
+ * Access this via the `apiRef` prop or a ref passed to the component.
698
+ */
699
+ export interface GridApi {
700
+ /**
701
+ * Returns the row model with the given ID.
702
+ * @param id The row unique ID.
703
+ */
704
+ getRow: (id: GridRowId) => GridRowModel | null;
705
+ /** Returns all rows currently loaded into the grid. */
706
+ getAllRows: () => GridRowModel[];
707
+ /** Returns all rows currently visible after filtering and sorting. */
708
+ getVisibleRows: () => GridRowModel[];
709
+ /** Returns the current aggregation results. */
710
+ getAggregationResult: () => Record<string, any> | null;
711
+ /** Returns the active aggregation configuration. */
712
+ getAggregationModel: () => GridAggregationModel | null;
713
+
714
+ /** Returns the column definition for the given field. */
715
+ getColumn: (field: string) => GridColDef | null;
716
+ /** Returns all defined columns. */
717
+ getAllColumns: () => GridColDef[];
718
+ /** Returns all columns currently visible. */
719
+ getVisibleColumns: () => GridColDef[];
720
+
721
+ /**
722
+ * Sets the selection state of a specific row.
723
+ * @param id The row unique ID.
724
+ * @param isSelected Visibility state.
725
+ */
726
+ selectRow: (id: GridRowId, isSelected?: boolean) => void;
727
+ /**
728
+ * Sets the selection state for multiple rows at once.
729
+ * @param ids Array of row IDs.
730
+ * @param isSelected Visibility state.
731
+ */
732
+ selectRows: (ids: GridRowId[], isSelected?: boolean) => void;
733
+ /** Returns an array of IDs for all currently selected rows. */
734
+ getSelectedRows: () => GridRowId[];
735
+
736
+ /**
737
+ * Triggers sorting on a specific column.
738
+ * @param field The column field.
739
+ * @param direction Sort order ('asc', 'desc', or null to clear).
740
+ */
741
+ sortColumn: (field: string, direction: GridSortDirection) => void;
742
+ /** Returns the active sorting model. */
743
+ getSortModel: () => GridSortItem[];
744
+
745
+ /** Programmatically sets the filtering model. */
746
+ setFilterModel: (model: GridFilterModel) => void;
747
+ /** Returns the current filtering model. */
748
+ getFilterModel: () => GridFilterModel;
749
+
750
+ /** Changes the current page. */
751
+ setPage: (page: number) => void;
752
+ /** Changes the current page size. */
753
+ setPageSize: (pageSize: number) => void;
754
+
755
+ /** Scrolls the grid viewport to a specific row or column index. */
756
+ scrollToIndexes: (params: { rowIndex?: number; colIndex?: number }) => void;
757
+
758
+ /**
759
+ * Programmatically copies all currently selected rows to the clipboard as TSV.
760
+ * Equivalent to the user pressing Ctrl+C / Cmd+C.
761
+ * @returns A Promise that resolves when the copy completes.
762
+ */
763
+ copySelectedRows: () => Promise<void>;
764
+ }