@mui/x-data-grid 5.8.0 → 5.9.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 +141 -63
- package/DataGrid/DataGrid.js +1 -1
- package/DataGrid/useDataGridComponent.js +3 -1
- package/LICENSE +21 -0
- package/README.md +1 -1
- package/components/GridRow.d.ts +4 -0
- package/components/GridRow.js +49 -23
- package/components/base/GridOverlays.js +4 -3
- package/components/cell/GridActionsCell.d.ts +5 -1
- package/components/cell/GridActionsCell.js +170 -21
- package/components/cell/GridActionsCellItem.d.ts +66 -4
- package/components/cell/GridActionsCellItem.js +7 -5
- package/components/cell/GridCell.d.ts +1 -0
- package/components/cell/GridCell.js +28 -7
- package/components/cell/GridEditInputCell.js +1 -1
- package/components/cell/GridEditSingleSelectCell.js +22 -13
- package/components/columnHeaders/GridColumnHeaderItem.js +4 -7
- package/components/columnHeaders/GridColumnHeaders.d.ts +0 -1
- package/components/columnHeaders/GridColumnHeaders.js +1 -1
- package/components/columnSelection/GridCellCheckboxRenderer.d.ts +3 -3
- package/components/columnSelection/GridCellCheckboxRenderer.js +20 -3
- package/components/panel/GridPanel.js +1 -0
- package/components/panel/filterPanel/GridFilterForm.js +14 -10
- package/components/panel/filterPanel/GridFilterInputBoolean.js +13 -8
- package/components/panel/filterPanel/GridFilterInputSingleSelect.js +22 -15
- package/components/panel/filterPanel/GridFilterInputValue.js +22 -15
- package/components/toolbar/GridToolbarDensitySelector.js +1 -1
- package/components/toolbar/GridToolbarFilterButton.d.ts +1 -1
- package/components/virtualization/GridVirtualScroller.js +2 -0
- package/components/virtualization/GridVirtualScrollerContent.js +1 -3
- package/constants/gridDetailPanelToggleField.d.ts +1 -0
- package/constants/gridDetailPanelToggleField.js +2 -0
- package/hooks/core/pipeProcessing/gridPipeProcessingApi.d.ts +32 -15
- package/hooks/core/pipeProcessing/index.d.ts +1 -0
- package/hooks/core/pipeProcessing/index.js +2 -1
- package/hooks/core/pipeProcessing/useGridPipeProcessing.d.ts +8 -3
- package/hooks/core/pipeProcessing/useGridPipeProcessing.js +53 -19
- package/hooks/core/pipeProcessing/useGridRegisterPipeApplier.d.ts +3 -0
- package/hooks/core/pipeProcessing/useGridRegisterPipeApplier.js +27 -0
- package/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.d.ts +0 -3
- package/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.js +0 -4
- package/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +0 -1
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +76 -10
- package/hooks/features/columns/gridColumnsInterfaces.d.ts +3 -1
- package/hooks/features/columns/gridColumnsUtils.d.ts +19 -1
- package/hooks/features/columns/gridColumnsUtils.js +61 -8
- package/hooks/features/columns/useGridColumnSpanning.d.ts +7 -0
- package/hooks/features/columns/useGridColumnSpanning.js +109 -0
- package/hooks/features/columns/useGridColumns.js +24 -18
- package/hooks/features/dimensions/useGridDimensions.js +3 -3
- package/hooks/features/editRows/useGridCellEditing.new.js +18 -10
- package/hooks/features/editRows/useGridEditing.new.js +7 -3
- package/hooks/features/editRows/useGridRowEditing.new.js +23 -15
- package/hooks/features/filter/useGridFilter.js +14 -9
- package/hooks/features/focus/useGridFocus.js +19 -9
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.d.ts +1 -0
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +39 -7
- package/hooks/features/rows/gridRowsSelector.d.ts +1 -0
- package/hooks/features/rows/gridRowsSelector.js +1 -0
- package/hooks/features/rows/gridRowsState.d.ts +4 -0
- package/hooks/features/rows/useGridRows.d.ts +2 -2
- package/hooks/features/rows/useGridRows.js +5 -4
- package/hooks/features/rows/useGridRowsMeta.js +6 -13
- package/hooks/features/scroll/useGridScroll.d.ts +2 -0
- package/hooks/features/scroll/useGridScroll.js +25 -3
- package/hooks/features/selection/useGridSelection.js +3 -2
- package/hooks/features/sorting/useGridSorting.js +10 -10
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +7 -0
- package/hooks/features/virtualization/useGridVirtualScroller.js +54 -27
- package/index.js +1 -1
- package/internals/index.d.ts +1 -0
- package/internals/index.js +1 -0
- package/legacy/DataGrid/DataGrid.js +1 -1
- package/legacy/DataGrid/useDataGridComponent.js +3 -1
- package/legacy/components/GridRow.js +47 -23
- package/legacy/components/base/GridOverlays.js +4 -3
- package/legacy/components/cell/GridActionsCell.js +188 -27
- package/legacy/components/cell/GridActionsCellItem.js +7 -5
- package/legacy/components/cell/GridCell.js +29 -7
- package/legacy/components/cell/GridEditInputCell.js +1 -1
- package/legacy/components/cell/GridEditSingleSelectCell.js +33 -24
- package/legacy/components/columnHeaders/GridColumnHeaderItem.js +4 -7
- package/legacy/components/columnHeaders/GridColumnHeaders.js +2 -3
- package/legacy/components/columnSelection/GridCellCheckboxRenderer.js +21 -3
- package/legacy/components/panel/GridPanel.js +1 -0
- package/legacy/components/panel/filterPanel/GridFilterForm.js +14 -10
- package/legacy/components/panel/filterPanel/GridFilterInputBoolean.js +13 -8
- package/legacy/components/panel/filterPanel/GridFilterInputSingleSelect.js +22 -17
- package/legacy/components/panel/filterPanel/GridFilterInputValue.js +22 -17
- package/legacy/components/toolbar/GridToolbarDensitySelector.js +1 -1
- package/legacy/components/virtualization/GridVirtualScroller.js +2 -0
- package/legacy/components/virtualization/GridVirtualScrollerContent.js +1 -3
- package/legacy/constants/gridDetailPanelToggleField.js +2 -0
- package/legacy/hooks/core/pipeProcessing/index.js +2 -1
- package/legacy/hooks/core/pipeProcessing/useGridPipeProcessing.js +60 -24
- package/legacy/hooks/core/pipeProcessing/useGridRegisterPipeApplier.js +27 -0
- package/legacy/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.js +0 -4
- package/legacy/hooks/features/columnHeaders/useGridColumnHeaders.js +89 -10
- package/legacy/hooks/features/columns/gridColumnsUtils.js +79 -22
- package/legacy/hooks/features/columns/useGridColumnSpanning.js +107 -0
- package/legacy/hooks/features/columns/useGridColumns.js +24 -18
- package/legacy/hooks/features/dimensions/useGridDimensions.js +3 -3
- package/legacy/hooks/features/editRows/useGridCellEditing.new.js +14 -8
- package/legacy/hooks/features/editRows/useGridEditing.new.js +7 -3
- package/legacy/hooks/features/editRows/useGridRowEditing.new.js +32 -24
- package/legacy/hooks/features/filter/useGridFilter.js +14 -9
- package/legacy/hooks/features/focus/useGridFocus.js +19 -9
- package/legacy/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +39 -6
- package/legacy/hooks/features/rows/gridRowsSelector.js +3 -0
- package/legacy/hooks/features/rows/useGridRows.js +5 -4
- package/legacy/hooks/features/rows/useGridRowsMeta.js +6 -13
- package/legacy/hooks/features/scroll/useGridScroll.js +25 -3
- package/legacy/hooks/features/selection/useGridSelection.js +3 -2
- package/legacy/hooks/features/sorting/useGridSorting.js +5 -7
- package/legacy/hooks/features/virtualization/useGridVirtualScroller.js +65 -37
- package/legacy/index.js +1 -1
- package/legacy/internals/index.js +1 -0
- package/legacy/locales/huHU.js +120 -0
- package/legacy/locales/index.js +1 -0
- package/legacy/models/api/gridColumnSpanning.js +1 -0
- package/legacy/models/events/gridEvents.js +2 -3
- package/legacy/models/gridColumnSpanning.js +1 -0
- package/locales/huHU.d.ts +2 -0
- package/locales/huHU.js +108 -0
- package/locales/index.d.ts +1 -0
- package/locales/index.js +1 -0
- package/models/api/gridApiCommon.d.ts +2 -1
- package/models/api/gridColumnSpanning.d.ts +28 -0
- package/models/api/gridColumnSpanning.js +1 -0
- package/models/api/gridEditingApi.d.ts +49 -3
- package/models/colDef/gridColDef.d.ts +5 -0
- package/models/events/gridEventLookup.d.ts +3 -8
- package/models/events/gridEvents.d.ts +9 -14
- package/models/events/gridEvents.js +2 -3
- package/models/gridColumnSpanning.d.ts +12 -0
- package/models/gridColumnSpanning.js +1 -0
- package/models/gridEditRowModel.d.ts +1 -1
- package/models/params/gridCellParams.d.ts +12 -2
- package/models/params/gridRowParams.d.ts +5 -0
- package/models/props/DataGridProps.d.ts +1 -1
- package/modern/DataGrid/DataGrid.js +1 -1
- package/modern/DataGrid/useDataGridComponent.js +3 -1
- package/modern/components/GridRow.js +47 -21
- package/modern/components/base/GridOverlays.js +4 -3
- package/modern/components/cell/GridActionsCell.js +168 -21
- package/modern/components/cell/GridActionsCellItem.js +7 -5
- package/modern/components/cell/GridCell.js +28 -7
- package/modern/components/cell/GridEditInputCell.js +1 -1
- package/modern/components/cell/GridEditSingleSelectCell.js +20 -11
- package/modern/components/columnHeaders/GridColumnHeaderItem.js +4 -7
- package/modern/components/columnHeaders/GridColumnHeaders.js +1 -1
- package/modern/components/columnSelection/GridCellCheckboxRenderer.js +20 -3
- package/modern/components/panel/GridPanel.js +1 -0
- package/modern/components/panel/filterPanel/GridFilterForm.js +10 -6
- package/modern/components/panel/filterPanel/GridFilterInputBoolean.js +11 -6
- package/modern/components/panel/filterPanel/GridFilterInputSingleSelect.js +20 -13
- package/modern/components/panel/filterPanel/GridFilterInputValue.js +20 -13
- package/modern/components/toolbar/GridToolbarDensitySelector.js +1 -1
- package/modern/components/virtualization/GridVirtualScroller.js +2 -0
- package/modern/components/virtualization/GridVirtualScrollerContent.js +1 -3
- package/modern/constants/gridDetailPanelToggleField.js +2 -0
- package/modern/hooks/core/pipeProcessing/index.js +2 -1
- package/modern/hooks/core/pipeProcessing/useGridPipeProcessing.js +53 -19
- package/modern/hooks/core/pipeProcessing/useGridRegisterPipeApplier.js +27 -0
- package/modern/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.js +0 -4
- package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +76 -10
- package/modern/hooks/features/columns/gridColumnsUtils.js +61 -8
- package/modern/hooks/features/columns/useGridColumnSpanning.js +107 -0
- package/modern/hooks/features/columns/useGridColumns.js +24 -18
- package/modern/hooks/features/dimensions/useGridDimensions.js +3 -3
- package/modern/hooks/features/editRows/useGridCellEditing.new.js +18 -10
- package/modern/hooks/features/editRows/useGridEditing.new.js +7 -3
- package/modern/hooks/features/editRows/useGridRowEditing.new.js +23 -15
- package/modern/hooks/features/filter/useGridFilter.js +14 -9
- package/modern/hooks/features/focus/useGridFocus.js +19 -9
- package/modern/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +37 -7
- package/modern/hooks/features/rows/gridRowsSelector.js +1 -0
- package/modern/hooks/features/rows/useGridRows.js +5 -4
- package/modern/hooks/features/rows/useGridRowsMeta.js +6 -13
- package/modern/hooks/features/scroll/useGridScroll.js +23 -3
- package/modern/hooks/features/selection/useGridSelection.js +3 -2
- package/modern/hooks/features/sorting/useGridSorting.js +10 -10
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +54 -23
- package/modern/index.js +1 -1
- package/modern/internals/index.js +1 -0
- package/modern/locales/huHU.js +108 -0
- package/modern/locales/index.js +1 -0
- package/modern/models/api/gridColumnSpanning.js +1 -0
- package/modern/models/events/gridEvents.js +2 -3
- package/modern/models/gridColumnSpanning.js +1 -0
- package/node/DataGrid/DataGrid.js +1 -1
- package/node/DataGrid/useDataGridComponent.js +4 -1
- package/node/components/GridRow.js +50 -23
- package/node/components/base/GridOverlays.js +3 -2
- package/node/components/cell/GridActionsCell.js +172 -21
- package/node/components/cell/GridActionsCellItem.js +7 -4
- package/node/components/cell/GridCell.js +28 -7
- package/node/components/cell/GridEditInputCell.js +1 -1
- package/node/components/cell/GridEditSingleSelectCell.js +23 -13
- package/node/components/columnHeaders/GridColumnHeaderItem.js +4 -7
- package/node/components/columnHeaders/GridColumnHeaders.js +1 -1
- package/node/components/columnSelection/GridCellCheckboxRenderer.js +20 -3
- package/node/components/panel/GridPanel.js +1 -0
- package/node/components/panel/filterPanel/GridFilterForm.js +15 -10
- package/node/components/panel/filterPanel/GridFilterInputBoolean.js +14 -8
- package/node/components/panel/filterPanel/GridFilterInputSingleSelect.js +23 -15
- package/node/components/panel/filterPanel/GridFilterInputValue.js +23 -15
- package/node/components/toolbar/GridToolbarDensitySelector.js +1 -1
- package/node/components/virtualization/GridVirtualScroller.js +2 -0
- package/node/components/virtualization/GridVirtualScrollerContent.js +1 -3
- package/node/constants/gridDetailPanelToggleField.js +9 -0
- package/node/hooks/core/pipeProcessing/index.js +13 -0
- package/node/hooks/core/pipeProcessing/useGridPipeProcessing.js +51 -20
- package/node/hooks/core/pipeProcessing/useGridRegisterPipeApplier.js +42 -0
- package/node/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.js +0 -3
- package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +80 -10
- package/node/hooks/features/columns/gridColumnsUtils.js +65 -9
- package/node/hooks/features/columns/useGridColumnSpanning.js +130 -0
- package/node/hooks/features/columns/useGridColumns.js +23 -17
- package/node/hooks/features/dimensions/useGridDimensions.js +3 -3
- package/node/hooks/features/editRows/useGridCellEditing.new.js +18 -10
- package/node/hooks/features/editRows/useGridEditing.new.js +6 -2
- package/node/hooks/features/editRows/useGridRowEditing.new.js +21 -14
- package/node/hooks/features/filter/useGridFilter.js +14 -9
- package/node/hooks/features/focus/useGridFocus.js +19 -9
- package/node/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +40 -7
- package/node/hooks/features/rows/gridRowsSelector.js +3 -1
- package/node/hooks/features/rows/useGridRows.js +5 -4
- package/node/hooks/features/rows/useGridRowsMeta.js +6 -14
- package/node/hooks/features/scroll/useGridScroll.js +26 -2
- package/node/hooks/features/selection/useGridSelection.js +4 -2
- package/node/hooks/features/sorting/useGridSorting.js +10 -10
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +59 -27
- package/node/index.js +1 -1
- package/node/internals/index.js +8 -0
- package/node/locales/huHU.js +118 -0
- package/node/locales/index.js +13 -0
- package/node/models/api/gridColumnSpanning.js +5 -0
- package/node/models/events/gridEvents.js +2 -3
- package/node/models/gridColumnSpanning.js +5 -0
- package/package.json +4 -4
- package/utils/domUtils.d.ts +2 -2
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
3
|
+
import { useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
|
|
4
|
+
import { GridEvents } from '../../../models/events/gridEvents';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @requires useGridColumns (method, event)
|
|
8
|
+
* @requires useGridParamsApi (method)
|
|
9
|
+
*/
|
|
10
|
+
export const useGridColumnSpanning = apiRef => {
|
|
11
|
+
const lookup = React.useRef({});
|
|
12
|
+
const setCellColSpanInfo = React.useCallback((rowId, columnIndex, cellColSpanInfo) => {
|
|
13
|
+
const sizes = lookup.current;
|
|
14
|
+
|
|
15
|
+
if (!sizes[rowId]) {
|
|
16
|
+
sizes[rowId] = {};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
sizes[rowId][columnIndex] = cellColSpanInfo;
|
|
20
|
+
}, []);
|
|
21
|
+
const getCellColSpanInfo = React.useCallback((rowId, columnIndex) => {
|
|
22
|
+
var _lookup$current$rowId;
|
|
23
|
+
|
|
24
|
+
return (_lookup$current$rowId = lookup.current[rowId]) == null ? void 0 : _lookup$current$rowId[columnIndex];
|
|
25
|
+
}, []); // Calculate `colSpan` for the cell.
|
|
26
|
+
|
|
27
|
+
const calculateCellColSpan = React.useCallback(params => {
|
|
28
|
+
const {
|
|
29
|
+
columnIndex,
|
|
30
|
+
rowId,
|
|
31
|
+
minFirstColumnIndex,
|
|
32
|
+
maxLastColumnIndex
|
|
33
|
+
} = params;
|
|
34
|
+
const visibleColumns = apiRef.current.getVisibleColumns();
|
|
35
|
+
const columnsLength = visibleColumns.length;
|
|
36
|
+
const column = visibleColumns[columnIndex];
|
|
37
|
+
const colSpan = typeof column.colSpan === 'function' ? column.colSpan(apiRef.current.getCellParams(rowId, column.field)) : column.colSpan;
|
|
38
|
+
|
|
39
|
+
if (!colSpan || colSpan === 1) {
|
|
40
|
+
setCellColSpanInfo(rowId, columnIndex, {
|
|
41
|
+
spannedByColSpan: false,
|
|
42
|
+
cellProps: {
|
|
43
|
+
colSpan: 1,
|
|
44
|
+
width: column.computedWidth
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return {
|
|
48
|
+
colSpan: 1
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let width = column.computedWidth;
|
|
53
|
+
|
|
54
|
+
for (let j = 1; j < colSpan; j += 1) {
|
|
55
|
+
const nextColumnIndex = columnIndex + j; // Cells should be spanned only within their column section (left-pinned, right-pinned and unpinned).
|
|
56
|
+
|
|
57
|
+
if (nextColumnIndex >= minFirstColumnIndex && nextColumnIndex < maxLastColumnIndex) {
|
|
58
|
+
const nextColumn = visibleColumns[nextColumnIndex];
|
|
59
|
+
width += nextColumn.computedWidth;
|
|
60
|
+
setCellColSpanInfo(rowId, columnIndex + j, {
|
|
61
|
+
spannedByColSpan: true,
|
|
62
|
+
rightVisibleCellIndex: Math.min(columnIndex + colSpan, columnsLength - 1),
|
|
63
|
+
leftVisibleCellIndex: columnIndex
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
setCellColSpanInfo(rowId, columnIndex, {
|
|
68
|
+
spannedByColSpan: false,
|
|
69
|
+
cellProps: {
|
|
70
|
+
colSpan,
|
|
71
|
+
width
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
colSpan
|
|
78
|
+
};
|
|
79
|
+
}, [apiRef, setCellColSpanInfo]); // Calculate `colSpan` for each cell in the row
|
|
80
|
+
|
|
81
|
+
const calculateColSpan = React.useCallback(({
|
|
82
|
+
rowId,
|
|
83
|
+
minFirstColumn,
|
|
84
|
+
maxLastColumn
|
|
85
|
+
}) => {
|
|
86
|
+
for (let i = minFirstColumn; i < maxLastColumn; i += 1) {
|
|
87
|
+
const cellProps = calculateCellColSpan({
|
|
88
|
+
columnIndex: i,
|
|
89
|
+
rowId,
|
|
90
|
+
minFirstColumnIndex: minFirstColumn,
|
|
91
|
+
maxLastColumnIndex: maxLastColumn
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
if (cellProps.colSpan > 1) {
|
|
95
|
+
i += cellProps.colSpan - 1;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}, [calculateCellColSpan]);
|
|
99
|
+
const columnSpanningApi = {
|
|
100
|
+
unstable_getCellColSpanInfo: getCellColSpanInfo,
|
|
101
|
+
unstable_calculateColSpan: calculateColSpan
|
|
102
|
+
};
|
|
103
|
+
useGridApiMethod(apiRef, columnSpanningApi, 'GridColumnSpanningAPI');
|
|
104
|
+
const handleColumnReorderChange = React.useCallback(() => {
|
|
105
|
+
// `colSpan` needs to be recalculated after column reordering
|
|
106
|
+
lookup.current = {};
|
|
107
|
+
}, []);
|
|
108
|
+
useGridApiEventHandler(apiRef, GridEvents.columnOrderChange, handleColumnReorderChange);
|
|
109
|
+
};
|
|
@@ -5,7 +5,7 @@ import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
|
5
5
|
import { useGridLogger } from '../../utils/useGridLogger';
|
|
6
6
|
import { gridColumnFieldsSelector, gridColumnDefinitionsSelector, gridColumnLookupSelector, gridColumnsMetaSelector, gridColumnsSelector, gridColumnVisibilityModelSelector, gridVisibleColumnDefinitionsSelector, gridColumnPositionsSelector } from './gridColumnsSelector';
|
|
7
7
|
import { useGridApiEventHandler, useGridApiOptionHandler } from '../../utils/useGridApiEventHandler';
|
|
8
|
-
import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
|
|
8
|
+
import { useGridRegisterPipeProcessor, useGridRegisterPipeApplier } from '../../core/pipeProcessing';
|
|
9
9
|
import { hydrateColumnsWidth, computeColumnTypes, createColumnsState, mergeColumnsState, COLUMNS_DIMENSION_PROPERTIES } from './gridColumnsUtils';
|
|
10
10
|
import { GridPreferencePanelsValue } from '../preferencesPanel';
|
|
11
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -214,7 +214,13 @@ export function useGridColumns(apiRef, props) {
|
|
|
214
214
|
if (colDef.hasBeenResized) {
|
|
215
215
|
const colDefDimensions = {};
|
|
216
216
|
COLUMNS_DIMENSION_PROPERTIES.forEach(propertyName => {
|
|
217
|
-
|
|
217
|
+
let propertyValue = colDef[propertyName];
|
|
218
|
+
|
|
219
|
+
if (propertyValue === Infinity) {
|
|
220
|
+
propertyValue = -1;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
colDefDimensions[propertyName] = propertyValue;
|
|
218
224
|
});
|
|
219
225
|
dimensions[colDef.field] = colDefDimensions;
|
|
220
226
|
}
|
|
@@ -272,12 +278,23 @@ export function useGridColumns(apiRef, props) {
|
|
|
272
278
|
* EVENTS
|
|
273
279
|
*/
|
|
274
280
|
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
281
|
+
const prevInnerWidth = React.useRef(null);
|
|
282
|
+
|
|
283
|
+
const handleGridSizeChange = viewportInnerSize => {
|
|
284
|
+
if (prevInnerWidth.current !== viewportInnerSize.width) {
|
|
285
|
+
prevInnerWidth.current = viewportInnerSize.width;
|
|
286
|
+
setGridColumnsState(hydrateColumnsWidth(gridColumnsSelector(apiRef.current.state), viewportInnerSize.width));
|
|
278
287
|
}
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
useGridApiEventHandler(apiRef, GridEvents.viewportInnerSizeChange, handleGridSizeChange);
|
|
291
|
+
useGridApiOptionHandler(apiRef, GridEvents.columnVisibilityChange, props.onColumnVisibilityChange);
|
|
292
|
+
/**
|
|
293
|
+
* APPLIERS
|
|
294
|
+
*/
|
|
279
295
|
|
|
280
|
-
|
|
296
|
+
const hydrateColumns = React.useCallback(() => {
|
|
297
|
+
logger.info(`Columns pipe processing have changed, regenerating the columns`);
|
|
281
298
|
const columnsState = createColumnsState({
|
|
282
299
|
apiRef,
|
|
283
300
|
columnTypes,
|
|
@@ -288,18 +305,7 @@ export function useGridColumns(apiRef, props) {
|
|
|
288
305
|
});
|
|
289
306
|
setGridColumnsState(columnsState);
|
|
290
307
|
}, [apiRef, logger, setGridColumnsState, columnTypes]);
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
const handleGridSizeChange = viewportInnerSize => {
|
|
294
|
-
if (prevInnerWidth.current !== viewportInnerSize.width) {
|
|
295
|
-
prevInnerWidth.current = viewportInnerSize.width;
|
|
296
|
-
setGridColumnsState(hydrateColumnsWidth(gridColumnsSelector(apiRef.current.state), viewportInnerSize.width));
|
|
297
|
-
}
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
useGridApiEventHandler(apiRef, GridEvents.pipeProcessorRegister, handlepipeProcessorRegister);
|
|
301
|
-
useGridApiEventHandler(apiRef, GridEvents.viewportInnerSizeChange, handleGridSizeChange);
|
|
302
|
-
useGridApiOptionHandler(apiRef, GridEvents.columnVisibilityChange, props.onColumnVisibilityChange);
|
|
308
|
+
useGridRegisterPipeApplier(apiRef, 'hydrateColumns', hydrateColumns);
|
|
303
309
|
/**
|
|
304
310
|
* EFFECTS
|
|
305
311
|
*/
|
|
@@ -146,12 +146,12 @@ export function useGridDimensions(apiRef, props) {
|
|
|
146
146
|
const isJSDOM = /jsdom/.test(window.navigator.userAgent);
|
|
147
147
|
|
|
148
148
|
if (size.height === 0 && !warningShown.current && !props.autoHeight && !isJSDOM) {
|
|
149
|
-
logger.warn(['The parent of the grid has an empty height.', 'You need to make sure the container has an intrinsic height.', 'The grid displays with a height of 0px.', '', 'You can find a solution in the docs:', 'https://mui.com/
|
|
149
|
+
logger.warn(['The parent of the grid has an empty height.', 'You need to make sure the container has an intrinsic height.', 'The grid displays with a height of 0px.', '', 'You can find a solution in the docs:', 'https://mui.com/x/react-data-grid/layout/'].join('\n'));
|
|
150
150
|
warningShown.current = true;
|
|
151
151
|
}
|
|
152
152
|
|
|
153
153
|
if (size.width === 0 && !warningShown.current && !isJSDOM) {
|
|
154
|
-
logger.warn(['The parent of the grid has an empty width.', 'You need to make sure the container has an intrinsic width.', 'The grid displays with a width of 0px.', '', 'You can find a solution in the docs:', 'https://mui.com/
|
|
154
|
+
logger.warn(['The parent of the grid has an empty width.', 'You need to make sure the container has an intrinsic width.', 'The grid displays with a width of 0px.', '', 'You can find a solution in the docs:', 'https://mui.com/x/react-data-grid/layout/'].join('\n'));
|
|
155
155
|
warningShown.current = true;
|
|
156
156
|
}
|
|
157
157
|
|
|
@@ -172,7 +172,7 @@ export function useGridDimensions(apiRef, props) {
|
|
|
172
172
|
debounceResize();
|
|
173
173
|
}, [props.autoHeight, debounceResize, logger, resize]);
|
|
174
174
|
useEnhancedEffect(() => updateGridDimensionsRef(), [updateGridDimensionsRef]);
|
|
175
|
-
useGridApiOptionHandler(apiRef, GridEvents.
|
|
175
|
+
useGridApiOptionHandler(apiRef, GridEvents.sortedRowsSet, updateGridDimensionsRef);
|
|
176
176
|
useGridApiOptionHandler(apiRef, GridEvents.pageChange, updateGridDimensionsRef);
|
|
177
177
|
useGridApiOptionHandler(apiRef, GridEvents.pageSizeChange, updateGridDimensionsRef);
|
|
178
178
|
useGridApiOptionHandler(apiRef, GridEvents.columnsChange, updateGridDimensionsRef);
|
|
@@ -223,10 +223,7 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
223
223
|
}
|
|
224
224
|
|
|
225
225
|
const editingState = gridEditRowsStateSelector(apiRef.current.state);
|
|
226
|
-
const row = apiRef.current.getRow(id);
|
|
227
|
-
const column = apiRef.current.getColumn(field);
|
|
228
226
|
const {
|
|
229
|
-
value,
|
|
230
227
|
error,
|
|
231
228
|
isProcessingProps
|
|
232
229
|
} = editingState[id][field];
|
|
@@ -235,12 +232,7 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
235
232
|
return;
|
|
236
233
|
}
|
|
237
234
|
|
|
238
|
-
const rowUpdate =
|
|
239
|
-
value,
|
|
240
|
-
row
|
|
241
|
-
}) : _extends({}, row, {
|
|
242
|
-
[field]: value
|
|
243
|
-
});
|
|
235
|
+
const rowUpdate = apiRef.current.unstable_getRowWithUpdatedValuesFromCellEditing(id, field);
|
|
244
236
|
|
|
245
237
|
if (processRowUpdate) {
|
|
246
238
|
const handleError = errorThrown => {
|
|
@@ -252,6 +244,7 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
252
244
|
};
|
|
253
245
|
|
|
254
246
|
try {
|
|
247
|
+
const row = apiRef.current.getRow(id);
|
|
255
248
|
Promise.resolve(processRowUpdate(rowUpdate, row)).then(finalRowUpdate => {
|
|
256
249
|
apiRef.current.updateRows([finalRowUpdate]);
|
|
257
250
|
updateFocusedCellIfNeeded();
|
|
@@ -320,11 +313,26 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
320
313
|
editingState = gridEditRowsStateSelector(apiRef.current.state);
|
|
321
314
|
return !editingState[id][field].error;
|
|
322
315
|
}, [apiRef, throwIfNotEditable, throwIfNotInMode, updateOrDeleteFieldState]);
|
|
316
|
+
const getRowWithUpdatedValuesFromCellEditing = React.useCallback((id, field) => {
|
|
317
|
+
const column = apiRef.current.getColumn(field);
|
|
318
|
+
const editingState = gridEditRowsStateSelector(apiRef.current.state);
|
|
319
|
+
const {
|
|
320
|
+
value
|
|
321
|
+
} = editingState[id][field];
|
|
322
|
+
const row = apiRef.current.getRow(id);
|
|
323
|
+
return column.valueSetter ? column.valueSetter({
|
|
324
|
+
value,
|
|
325
|
+
row
|
|
326
|
+
}) : _extends({}, row, {
|
|
327
|
+
[field]: value
|
|
328
|
+
});
|
|
329
|
+
}, [apiRef]);
|
|
323
330
|
const editingApi = {
|
|
324
331
|
getCellMode,
|
|
325
332
|
startCellEditMode,
|
|
326
333
|
stopCellEditMode,
|
|
327
|
-
unstable_setCellEditingEditCellValue: setCellEditingEditCellValue
|
|
334
|
+
unstable_setCellEditingEditCellValue: setCellEditingEditCellValue,
|
|
335
|
+
unstable_getRowWithUpdatedValuesFromCellEditing: getRowWithUpdatedValuesFromCellEditing
|
|
328
336
|
};
|
|
329
337
|
useGridApiMethod(apiRef, editingApi, 'EditingApi');
|
|
330
338
|
};
|
|
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
4
4
|
import { useGridCellEditing } from './useGridCellEditing.new';
|
|
5
|
-
import { GridCellModes } from '../../../models/gridEditRowModel';
|
|
5
|
+
import { GridCellModes, GridEditModes } from '../../../models/gridEditRowModel';
|
|
6
6
|
import { useGridRowEditing } from './useGridRowEditing.new';
|
|
7
7
|
export const editingStateInitializer = state => _extends({}, state, {
|
|
8
8
|
editRows: {}
|
|
@@ -99,7 +99,7 @@ export const useGridEditing = (apiRef, props) => {
|
|
|
99
99
|
} = params;
|
|
100
100
|
return new Promise(resolve => {
|
|
101
101
|
maybeDebounce(id, field, debounceMs, async () => {
|
|
102
|
-
const setEditCellValueToCall = props.editMode ===
|
|
102
|
+
const setEditCellValueToCall = props.editMode === GridEditModes.Row ? apiRef.current.unstable_setRowEditingEditCellValue : apiRef.current.unstable_setCellEditingEditCellValue; // Check if the cell is in edit mode
|
|
103
103
|
// By the time this callback runs the user may have cancelled the editing
|
|
104
104
|
|
|
105
105
|
if (apiRef.current.getCellMode(id, field) === GridCellModes.Edit) {
|
|
@@ -109,10 +109,14 @@ export const useGridEditing = (apiRef, props) => {
|
|
|
109
109
|
});
|
|
110
110
|
});
|
|
111
111
|
}, [apiRef, props.editMode]);
|
|
112
|
+
const getRowWithUpdatedValues = React.useCallback((id, field) => {
|
|
113
|
+
return props.editMode === GridEditModes.Cell ? apiRef.current.unstable_getRowWithUpdatedValuesFromCellEditing(id, field) : apiRef.current.unstable_getRowWithUpdatedValuesFromRowEditing(id);
|
|
114
|
+
}, [apiRef, props.editMode]);
|
|
112
115
|
const editingSharedApi = {
|
|
113
116
|
isCellEditable,
|
|
114
117
|
setEditCellValue,
|
|
115
|
-
unstable_runPendingEditCellValueMutation: runPendingEditCellValueMutation
|
|
118
|
+
unstable_runPendingEditCellValueMutation: runPendingEditCellValueMutation,
|
|
119
|
+
unstable_getRowWithUpdatedValues: getRowWithUpdatedValues
|
|
116
120
|
};
|
|
117
121
|
useGridApiMethod(apiRef, editingSharedApi, 'EditingApi');
|
|
118
122
|
};
|
|
@@ -336,20 +336,7 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
336
336
|
return;
|
|
337
337
|
}
|
|
338
338
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
Object.entries(editingState[id]).forEach(([field, fieldProps]) => {
|
|
342
|
-
const column = apiRef.current.getColumn(field);
|
|
343
|
-
|
|
344
|
-
if (column.valueSetter) {
|
|
345
|
-
rowUpdate = column.valueSetter({
|
|
346
|
-
value: fieldProps.value,
|
|
347
|
-
row: rowUpdate
|
|
348
|
-
});
|
|
349
|
-
} else {
|
|
350
|
-
rowUpdate[field] = fieldProps.value;
|
|
351
|
-
}
|
|
352
|
-
});
|
|
339
|
+
const rowUpdate = apiRef.current.unstable_getRowWithUpdatedValuesFromRowEditing(id);
|
|
353
340
|
|
|
354
341
|
if (processRowUpdate) {
|
|
355
342
|
const handleError = errorThrown => {
|
|
@@ -491,11 +478,32 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
491
478
|
});
|
|
492
479
|
});
|
|
493
480
|
}, [apiRef, throwIfNotEditable, updateOrDeleteFieldState]);
|
|
481
|
+
const getRowWithUpdatedValuesFromRowEditing = React.useCallback(id => {
|
|
482
|
+
const editingState = gridEditRowsStateSelector(apiRef.current.state);
|
|
483
|
+
const row = apiRef.current.getRow(id);
|
|
484
|
+
|
|
485
|
+
let rowUpdate = _extends({}, row);
|
|
486
|
+
|
|
487
|
+
Object.entries(editingState[id]).forEach(([field, fieldProps]) => {
|
|
488
|
+
const column = apiRef.current.getColumn(field);
|
|
489
|
+
|
|
490
|
+
if (column.valueSetter) {
|
|
491
|
+
rowUpdate = column.valueSetter({
|
|
492
|
+
value: fieldProps.value,
|
|
493
|
+
row: rowUpdate
|
|
494
|
+
});
|
|
495
|
+
} else {
|
|
496
|
+
rowUpdate[field] = fieldProps.value;
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
return rowUpdate;
|
|
500
|
+
}, [apiRef]);
|
|
494
501
|
const editingApi = {
|
|
495
502
|
getRowMode,
|
|
496
503
|
startRowEditMode,
|
|
497
504
|
stopRowEditMode,
|
|
498
|
-
unstable_setRowEditingEditCellValue: setRowEditingEditCellValue
|
|
505
|
+
unstable_setRowEditingEditCellValue: setRowEditingEditCellValue,
|
|
506
|
+
unstable_getRowWithUpdatedValuesFromRowEditing: getRowWithUpdatedValuesFromRowEditing
|
|
499
507
|
};
|
|
500
508
|
useGridApiMethod(apiRef, editingApi, 'EditingApi');
|
|
501
509
|
};
|
|
@@ -44,11 +44,7 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
44
44
|
stateSelector: gridFilterModelSelector,
|
|
45
45
|
changeEvent: GridEvents.filterModelChange
|
|
46
46
|
});
|
|
47
|
-
|
|
48
|
-
* API METHODS
|
|
49
|
-
*/
|
|
50
|
-
|
|
51
|
-
const applyFilters = React.useCallback(() => {
|
|
47
|
+
const updateFilteredRows = React.useCallback(() => {
|
|
52
48
|
apiRef.current.setState(state => {
|
|
53
49
|
const filterModel = gridFilterModelSelector(state, apiRef.current.instanceId);
|
|
54
50
|
const isRowMatchingFilters = props.filterMode === GridFeatureModeConstant.client ? buildAggregatedFilterApplier(filterModel, apiRef) : null;
|
|
@@ -59,9 +55,16 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
59
55
|
filter: _extends({}, state.filter, filteringResult)
|
|
60
56
|
});
|
|
61
57
|
});
|
|
62
|
-
apiRef.current.publishEvent(GridEvents.
|
|
58
|
+
apiRef.current.publishEvent(GridEvents.filteredRowsSet);
|
|
59
|
+
}, [props.filterMode, apiRef]);
|
|
60
|
+
/**
|
|
61
|
+
* API METHODS
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
const applyFilters = React.useCallback(() => {
|
|
65
|
+
updateFilteredRows();
|
|
63
66
|
apiRef.current.forceUpdate();
|
|
64
|
-
}, [apiRef,
|
|
67
|
+
}, [apiRef, updateFilteredRows]);
|
|
65
68
|
const upsertFilterItem = React.useCallback(item => {
|
|
66
69
|
const filterModel = gridFilterModelSelector(apiRef);
|
|
67
70
|
const items = [...filterModel.items];
|
|
@@ -245,8 +248,10 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
245
248
|
if (methodName === 'filtering') {
|
|
246
249
|
apiRef.current.unstable_applyFilters();
|
|
247
250
|
}
|
|
248
|
-
}, [apiRef]);
|
|
249
|
-
|
|
251
|
+
}, [apiRef]); // Do not call `apiRef.current.forceUpdate` to avoid re-render before updating the sorted rows.
|
|
252
|
+
// Otherwise, the state is not consistent during the render
|
|
253
|
+
|
|
254
|
+
useGridApiEventHandler(apiRef, GridEvents.rowsSet, updateFilteredRows);
|
|
250
255
|
useGridApiEventHandler(apiRef, GridEvents.rowExpansionChange, apiRef.current.unstable_applyFilters);
|
|
251
256
|
useGridApiEventHandler(apiRef, GridEvents.columnsChange, handleColumnsChange);
|
|
252
257
|
useGridApiEventHandler(apiRef, GridEvents.activeStrategyProcessorChange, handleStrategyProcessorChange);
|
|
@@ -102,21 +102,31 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
102
102
|
rowIndexToFocus += 1;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
+
const currentPage = getVisibleRows(apiRef, {
|
|
106
|
+
pagination: props.pagination,
|
|
107
|
+
paginationMode: props.paginationMode
|
|
108
|
+
});
|
|
109
|
+
|
|
105
110
|
if (columnIndexToFocus >= visibleColumns.length) {
|
|
106
|
-
// Go to next row if we are
|
|
111
|
+
// Go to next row if we are after the last column
|
|
107
112
|
rowIndexToFocus += 1;
|
|
108
|
-
|
|
113
|
+
|
|
114
|
+
if (rowIndexToFocus < currentPage.rows.length) {
|
|
115
|
+
// Go to first column of the next row if there's one more row
|
|
116
|
+
columnIndexToFocus = 0;
|
|
117
|
+
}
|
|
109
118
|
} else if (columnIndexToFocus < 0) {
|
|
110
|
-
// Go to previous row if we are
|
|
119
|
+
// Go to previous row if we are before the first column
|
|
111
120
|
rowIndexToFocus -= 1;
|
|
112
|
-
|
|
121
|
+
|
|
122
|
+
if (rowIndexToFocus >= 0) {
|
|
123
|
+
// Go to last column of the previous if there's one more row
|
|
124
|
+
columnIndexToFocus = visibleColumns.length - 1;
|
|
125
|
+
}
|
|
113
126
|
}
|
|
114
127
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
paginationMode: props.paginationMode
|
|
118
|
-
});
|
|
119
|
-
rowIndexToFocus = clamp(rowIndexToFocus, currentPage.range.firstRowIndex, currentPage.range.lastRowIndex);
|
|
128
|
+
rowIndexToFocus = clamp(rowIndexToFocus, 0, currentPage.rows.length - 1);
|
|
129
|
+
columnIndexToFocus = clamp(columnIndexToFocus, 0, visibleColumns.length - 1);
|
|
120
130
|
const rowToFocus = currentPage.rows[rowIndexToFocus];
|
|
121
131
|
const columnToFocus = visibleColumns[columnIndexToFocus];
|
|
122
132
|
apiRef.current.setCellFocus(rowToFocus.id, columnToFocus.field);
|
|
@@ -8,5 +8,6 @@ import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
|
|
|
8
8
|
* @requires useGridDimensions (method) - can be after
|
|
9
9
|
* @requires useGridFocus (method) - can be after
|
|
10
10
|
* @requires useGridScroll (method) - can be after
|
|
11
|
+
* @requires useGridColumnSpanning (method) - can be after
|
|
11
12
|
*/
|
|
12
13
|
export declare const useGridKeyboardNavigation: (apiRef: React.MutableRefObject<GridApiCommunity>, props: Pick<DataGridProcessedProps, 'pagination' | 'paginationMode'>) => void;
|
|
@@ -9,6 +9,7 @@ import { GRID_CHECKBOX_SELECTION_COL_DEF } from '../../../colDef/gridCheckboxSel
|
|
|
9
9
|
import { gridClasses } from '../../../constants/gridClasses';
|
|
10
10
|
import { GridCellModes } from '../../../models/gridEditRowModel';
|
|
11
11
|
import { isNavigationKey } from '../../../utils/keyboardUtils';
|
|
12
|
+
import { GRID_DETAIL_PANEL_TOGGLE_FIELD } from '../../../constants/gridDetailPanelToggleField';
|
|
12
13
|
/**
|
|
13
14
|
* @requires useGridSorting (method) - can be after
|
|
14
15
|
* @requires useGridFilter (state) - can be after
|
|
@@ -16,21 +17,40 @@ import { isNavigationKey } from '../../../utils/keyboardUtils';
|
|
|
16
17
|
* @requires useGridDimensions (method) - can be after
|
|
17
18
|
* @requires useGridFocus (method) - can be after
|
|
18
19
|
* @requires useGridScroll (method) - can be after
|
|
20
|
+
* @requires useGridColumnSpanning (method) - can be after
|
|
19
21
|
*/
|
|
20
22
|
|
|
21
23
|
export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
22
24
|
const logger = useGridLogger(apiRef, 'useGridKeyboardNavigation');
|
|
23
25
|
const currentPage = useGridVisibleRows(apiRef, props);
|
|
24
|
-
|
|
26
|
+
/**
|
|
27
|
+
* @param {number} colIndex Index of the column to focus
|
|
28
|
+
* @param {number} rowIndex index of the row to focus
|
|
29
|
+
* @param {string} closestColumnToUse Which closest column cell to use when the cell is spanned by `colSpan`.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
const goToCell = React.useCallback((colIndex, rowIndex, closestColumnToUse = 'left') => {
|
|
33
|
+
var _visibleSortedRows$ro;
|
|
34
|
+
|
|
35
|
+
const visibleSortedRows = gridVisibleSortedRowEntriesSelector(apiRef);
|
|
36
|
+
const rowId = (_visibleSortedRows$ro = visibleSortedRows[rowIndex]) == null ? void 0 : _visibleSortedRows$ro.id;
|
|
37
|
+
const nextCellColSpanInfo = apiRef.current.unstable_getCellColSpanInfo(rowId, colIndex);
|
|
38
|
+
|
|
39
|
+
if (nextCellColSpanInfo && nextCellColSpanInfo.spannedByColSpan) {
|
|
40
|
+
if (closestColumnToUse === 'left') {
|
|
41
|
+
colIndex = nextCellColSpanInfo.leftVisibleCellIndex;
|
|
42
|
+
} else if (closestColumnToUse === 'right') {
|
|
43
|
+
colIndex = nextCellColSpanInfo.rightVisibleCellIndex;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
25
47
|
logger.debug(`Navigating to cell row ${rowIndex}, col ${colIndex}`);
|
|
26
48
|
apiRef.current.scrollToIndexes({
|
|
27
49
|
colIndex,
|
|
28
50
|
rowIndex
|
|
29
51
|
});
|
|
30
52
|
const field = apiRef.current.getVisibleColumns()[colIndex].field;
|
|
31
|
-
|
|
32
|
-
const node = visibleSortedRows[rowIndex];
|
|
33
|
-
apiRef.current.setCellFocus(node.id, field);
|
|
53
|
+
apiRef.current.setCellFocus(rowId, field);
|
|
34
54
|
}, [apiRef, logger]);
|
|
35
55
|
const goToHeader = React.useCallback((colIndex, event) => {
|
|
36
56
|
logger.debug(`Navigating to header col ${colIndex}`);
|
|
@@ -83,7 +103,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
83
103
|
case 'ArrowRight':
|
|
84
104
|
{
|
|
85
105
|
if (colIndexBefore < lastColIndex) {
|
|
86
|
-
goToCell(colIndexBefore + 1, rowIndexBefore);
|
|
106
|
+
goToCell(colIndexBefore + 1, rowIndexBefore, 'right');
|
|
87
107
|
}
|
|
88
108
|
|
|
89
109
|
break;
|
|
@@ -102,9 +122,9 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
102
122
|
{
|
|
103
123
|
// "Tab" is only triggered by the row / cell editing feature
|
|
104
124
|
if (event.shiftKey && colIndexBefore > firstColIndex) {
|
|
105
|
-
goToCell(colIndexBefore - 1, rowIndexBefore);
|
|
125
|
+
goToCell(colIndexBefore - 1, rowIndexBefore, 'left');
|
|
106
126
|
} else if (!event.shiftKey && colIndexBefore < lastColIndex) {
|
|
107
|
-
goToCell(colIndexBefore + 1, rowIndexBefore);
|
|
127
|
+
goToCell(colIndexBefore + 1, rowIndexBefore, 'right');
|
|
108
128
|
}
|
|
109
129
|
|
|
110
130
|
break;
|
|
@@ -112,6 +132,18 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
112
132
|
|
|
113
133
|
case ' ':
|
|
114
134
|
{
|
|
135
|
+
const field = params.field;
|
|
136
|
+
|
|
137
|
+
if (field === GRID_DETAIL_PANEL_TOGGLE_FIELD) {
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const colDef = params.colDef;
|
|
142
|
+
|
|
143
|
+
if (colDef && colDef.type === 'treeDataGroup') {
|
|
144
|
+
break;
|
|
145
|
+
}
|
|
146
|
+
|
|
115
147
|
if (!event.shiftKey && rowIndexBefore < lastRowIndexInPage) {
|
|
116
148
|
goToCell(colIndexBefore, Math.min(rowIndexBefore + viewportPageSize, lastRowIndexInPage));
|
|
117
149
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { GridStateCommunity } from '../../../models/gridStateCommunity';
|
|
2
2
|
export declare const gridRowsStateSelector: (state: GridStateCommunity) => import("./gridRowsState").GridRowsState;
|
|
3
3
|
export declare const gridRowCountSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, number>;
|
|
4
|
+
export declare const gridRowsLoadingSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, boolean | undefined>;
|
|
4
5
|
export declare const gridTopLevelRowCountSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, number>;
|
|
5
6
|
export declare const gridRowsLookupSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, import("../../..").GridRowsLookup<any>>;
|
|
6
7
|
export declare const gridRowTreeSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, import("../../..").GridRowTreeConfig>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createSelector } from '../../../utils/createSelector';
|
|
2
2
|
export const gridRowsStateSelector = state => state.rows;
|
|
3
3
|
export const gridRowCountSelector = createSelector(gridRowsStateSelector, rows => rows.totalRowCount);
|
|
4
|
+
export const gridRowsLoadingSelector = createSelector(gridRowsStateSelector, rows => rows.loading);
|
|
4
5
|
export const gridTopLevelRowCountSelector = createSelector(gridRowsStateSelector, rows => rows.totalTopLevelRowCount);
|
|
5
6
|
export const gridRowsLookupSelector = createSelector(gridRowsStateSelector, rows => rows.idRowsLookup);
|
|
6
7
|
export const gridRowTreeSelector = createSelector(gridRowsStateSelector, rows => rows.tree);
|
|
@@ -31,6 +31,10 @@ export interface GridRowsInternalCache {
|
|
|
31
31
|
lastUpdateMs: number;
|
|
32
32
|
}
|
|
33
33
|
export interface GridRowsState extends GridRowTreeCreationValue {
|
|
34
|
+
/**
|
|
35
|
+
* Matches the value of the `loading` prop.
|
|
36
|
+
*/
|
|
37
|
+
loading?: boolean;
|
|
34
38
|
/**
|
|
35
39
|
* Amount of rows before applying the filtering.
|
|
36
40
|
* It also counts the expanded and collapsed children rows.
|
|
@@ -2,5 +2,5 @@ import * as React from 'react';
|
|
|
2
2
|
import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
|
|
3
3
|
import { GridApiCommunity } from '../../../models/api/gridApiCommunity';
|
|
4
4
|
import { GridStateInitializer } from '../../utils/useGridInitializeState';
|
|
5
|
-
export declare const rowsStateInitializer: GridStateInitializer<Pick<DataGridProcessedProps, 'rows' | 'rowCount' | 'getRowId'>>;
|
|
6
|
-
export declare const useGridRows: (apiRef: React.MutableRefObject<GridApiCommunity>, props: Pick<DataGridProcessedProps, 'rows' | 'getRowId' | 'rowCount' | 'throttleRowsMs' | 'signature' | 'pagination' | 'paginationMode'>) => void;
|
|
5
|
+
export declare const rowsStateInitializer: GridStateInitializer<Pick<DataGridProcessedProps, 'rows' | 'rowCount' | 'getRowId' | 'loading'>>;
|
|
6
|
+
export declare const useGridRows: (apiRef: React.MutableRefObject<GridApiCommunity>, props: Pick<DataGridProcessedProps, 'rows' | 'getRowId' | 'rowCount' | 'throttleRowsMs' | 'signature' | 'pagination' | 'paginationMode' | 'loading'>) => void;
|
|
@@ -43,7 +43,7 @@ const convertGridRowsPropToState = ({
|
|
|
43
43
|
};
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
const getRowsStateFromCache = (rowsCache, previousTree, apiRef, rowCountProp) => {
|
|
46
|
+
const getRowsStateFromCache = (rowsCache, previousTree, apiRef, rowCountProp, loadingProp) => {
|
|
47
47
|
const {
|
|
48
48
|
value
|
|
49
49
|
} = rowsCache.state;
|
|
@@ -53,6 +53,7 @@ const getRowsStateFromCache = (rowsCache, previousTree, apiRef, rowCountProp) =>
|
|
|
53
53
|
}));
|
|
54
54
|
const dataTopLevelRowCount = groupingResponse.treeDepth === 1 ? groupingResponse.ids.length : Object.values(groupingResponse.tree).filter(node => node.parent == null).length;
|
|
55
55
|
return _extends({}, groupingResponse, {
|
|
56
|
+
loading: loadingProp,
|
|
56
57
|
totalRowCount: Math.max(rowCount, groupingResponse.ids.length),
|
|
57
58
|
totalTopLevelRowCount: Math.max(rowCount, dataTopLevelRowCount)
|
|
58
59
|
});
|
|
@@ -75,7 +76,7 @@ export const rowsStateInitializer = (state, props, apiRef) => {
|
|
|
75
76
|
lastUpdateMs: Date.now()
|
|
76
77
|
};
|
|
77
78
|
return _extends({}, state, {
|
|
78
|
-
rows: getRowsStateFromCache(rowsCache, null, apiRef, props.rowCount),
|
|
79
|
+
rows: getRowsStateFromCache(rowsCache, null, apiRef, props.rowCount, props.loading),
|
|
79
80
|
rowsCache // TODO remove from state
|
|
80
81
|
|
|
81
82
|
});
|
|
@@ -106,7 +107,7 @@ export const useGridRows = (apiRef, props) => {
|
|
|
106
107
|
rowsCache.current.timeout = null;
|
|
107
108
|
rowsCache.current.lastUpdateMs = Date.now();
|
|
108
109
|
apiRef.current.setState(state => _extends({}, state, {
|
|
109
|
-
rows: getRowsStateFromCache(rowsCache.current, gridRowTreeSelector(apiRef), apiRef, props.rowCount)
|
|
110
|
+
rows: getRowsStateFromCache(rowsCache.current, gridRowTreeSelector(apiRef), apiRef, props.rowCount, props.loading)
|
|
110
111
|
}));
|
|
111
112
|
apiRef.current.publishEvent(GridEvents.rowsSet);
|
|
112
113
|
apiRef.current.forceUpdate();
|
|
@@ -132,7 +133,7 @@ export const useGridRows = (apiRef, props) => {
|
|
|
132
133
|
}
|
|
133
134
|
|
|
134
135
|
run();
|
|
135
|
-
}, [props.throttleRowsMs, props.rowCount, apiRef]);
|
|
136
|
+
}, [props.throttleRowsMs, props.rowCount, props.loading, apiRef]);
|
|
136
137
|
/**
|
|
137
138
|
* API METHODS
|
|
138
139
|
*/
|