@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
|
@@ -206,9 +206,15 @@ export const applyInitialState = (columnsState, initialState) => {
|
|
|
206
206
|
|
|
207
207
|
for (let i = 0; i < columnsWithUpdatedDimensions.length; i += 1) {
|
|
208
208
|
const field = columnsWithUpdatedDimensions[i];
|
|
209
|
-
|
|
209
|
+
|
|
210
|
+
const newColDef = _extends({}, newColumnLookup[field], {
|
|
210
211
|
hasBeenResized: true
|
|
211
212
|
});
|
|
213
|
+
|
|
214
|
+
Object.entries(dimensions[field]).forEach(([key, value]) => {
|
|
215
|
+
newColDef[key] = value === -1 ? Infinity : value;
|
|
216
|
+
});
|
|
217
|
+
newColumnLookup[field] = newColDef;
|
|
212
218
|
}
|
|
213
219
|
|
|
214
220
|
const newColumnsState = {
|
|
@@ -294,16 +300,20 @@ export const createColumnsState = ({
|
|
|
294
300
|
columnsStateWithoutColumnVisibilityModel.all.push(field);
|
|
295
301
|
}
|
|
296
302
|
|
|
297
|
-
let
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
}
|
|
303
|
+
let hasBeenResized = existingState.hasBeenResized;
|
|
304
|
+
COLUMNS_DIMENSION_PROPERTIES.forEach(key => {
|
|
305
|
+
if (newColumn[key] !== undefined) {
|
|
306
|
+
hasBeenResized = true;
|
|
302
307
|
|
|
308
|
+
if (newColumn[key] === -1) {
|
|
309
|
+
newColumn[key] = Infinity;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
});
|
|
303
313
|
columnsStateWithoutColumnVisibilityModel.lookup[field] = _extends({}, existingState, {
|
|
304
314
|
hide: newColumn.hide == null ? false : newColumn.hide
|
|
305
315
|
}, newColumn, {
|
|
306
|
-
hasBeenResized
|
|
316
|
+
hasBeenResized
|
|
307
317
|
});
|
|
308
318
|
});
|
|
309
319
|
|
|
@@ -392,4 +402,47 @@ export const createColumnsState = ({
|
|
|
392
402
|
};
|
|
393
403
|
export const mergeColumnsState = columnsState => state => _extends({}, state, {
|
|
394
404
|
columns: columnsState
|
|
395
|
-
});
|
|
405
|
+
});
|
|
406
|
+
export function getFirstNonSpannedColumnToRender({
|
|
407
|
+
firstColumnToRender,
|
|
408
|
+
apiRef,
|
|
409
|
+
firstRowToRender,
|
|
410
|
+
lastRowToRender,
|
|
411
|
+
visibleRows
|
|
412
|
+
}) {
|
|
413
|
+
let firstNonSpannedColumnToRender = firstColumnToRender;
|
|
414
|
+
|
|
415
|
+
for (let i = firstRowToRender; i < lastRowToRender; i += 1) {
|
|
416
|
+
const row = visibleRows[i];
|
|
417
|
+
|
|
418
|
+
if (row) {
|
|
419
|
+
const rowId = visibleRows[i].id;
|
|
420
|
+
const cellColSpanInfo = apiRef.current.unstable_getCellColSpanInfo(rowId, firstColumnToRender);
|
|
421
|
+
|
|
422
|
+
if (cellColSpanInfo && cellColSpanInfo.spannedByColSpan) {
|
|
423
|
+
firstNonSpannedColumnToRender = cellColSpanInfo.leftVisibleCellIndex;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
return firstNonSpannedColumnToRender;
|
|
429
|
+
}
|
|
430
|
+
export function getFirstColumnIndexToRender({
|
|
431
|
+
firstColumnIndex,
|
|
432
|
+
minColumnIndex,
|
|
433
|
+
columnBuffer,
|
|
434
|
+
firstRowToRender,
|
|
435
|
+
lastRowToRender,
|
|
436
|
+
apiRef,
|
|
437
|
+
visibleRows
|
|
438
|
+
}) {
|
|
439
|
+
const initialFirstColumnToRender = Math.max(firstColumnIndex - columnBuffer, minColumnIndex);
|
|
440
|
+
const firstColumnToRender = getFirstNonSpannedColumnToRender({
|
|
441
|
+
firstColumnToRender: initialFirstColumnToRender,
|
|
442
|
+
apiRef,
|
|
443
|
+
firstRowToRender,
|
|
444
|
+
lastRowToRender,
|
|
445
|
+
visibleRows
|
|
446
|
+
});
|
|
447
|
+
return firstColumnToRender;
|
|
448
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
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
|
+
return lookup.current[rowId]?.[columnIndex];
|
|
23
|
+
}, []); // Calculate `colSpan` for the cell.
|
|
24
|
+
|
|
25
|
+
const calculateCellColSpan = React.useCallback(params => {
|
|
26
|
+
const {
|
|
27
|
+
columnIndex,
|
|
28
|
+
rowId,
|
|
29
|
+
minFirstColumnIndex,
|
|
30
|
+
maxLastColumnIndex
|
|
31
|
+
} = params;
|
|
32
|
+
const visibleColumns = apiRef.current.getVisibleColumns();
|
|
33
|
+
const columnsLength = visibleColumns.length;
|
|
34
|
+
const column = visibleColumns[columnIndex];
|
|
35
|
+
const colSpan = typeof column.colSpan === 'function' ? column.colSpan(apiRef.current.getCellParams(rowId, column.field)) : column.colSpan;
|
|
36
|
+
|
|
37
|
+
if (!colSpan || colSpan === 1) {
|
|
38
|
+
setCellColSpanInfo(rowId, columnIndex, {
|
|
39
|
+
spannedByColSpan: false,
|
|
40
|
+
cellProps: {
|
|
41
|
+
colSpan: 1,
|
|
42
|
+
width: column.computedWidth
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return {
|
|
46
|
+
colSpan: 1
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let width = column.computedWidth;
|
|
51
|
+
|
|
52
|
+
for (let j = 1; j < colSpan; j += 1) {
|
|
53
|
+
const nextColumnIndex = columnIndex + j; // Cells should be spanned only within their column section (left-pinned, right-pinned and unpinned).
|
|
54
|
+
|
|
55
|
+
if (nextColumnIndex >= minFirstColumnIndex && nextColumnIndex < maxLastColumnIndex) {
|
|
56
|
+
const nextColumn = visibleColumns[nextColumnIndex];
|
|
57
|
+
width += nextColumn.computedWidth;
|
|
58
|
+
setCellColSpanInfo(rowId, columnIndex + j, {
|
|
59
|
+
spannedByColSpan: true,
|
|
60
|
+
rightVisibleCellIndex: Math.min(columnIndex + colSpan, columnsLength - 1),
|
|
61
|
+
leftVisibleCellIndex: columnIndex
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
setCellColSpanInfo(rowId, columnIndex, {
|
|
66
|
+
spannedByColSpan: false,
|
|
67
|
+
cellProps: {
|
|
68
|
+
colSpan,
|
|
69
|
+
width
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return {
|
|
75
|
+
colSpan
|
|
76
|
+
};
|
|
77
|
+
}, [apiRef, setCellColSpanInfo]); // Calculate `colSpan` for each cell in the row
|
|
78
|
+
|
|
79
|
+
const calculateColSpan = React.useCallback(({
|
|
80
|
+
rowId,
|
|
81
|
+
minFirstColumn,
|
|
82
|
+
maxLastColumn
|
|
83
|
+
}) => {
|
|
84
|
+
for (let i = minFirstColumn; i < maxLastColumn; i += 1) {
|
|
85
|
+
const cellProps = calculateCellColSpan({
|
|
86
|
+
columnIndex: i,
|
|
87
|
+
rowId,
|
|
88
|
+
minFirstColumnIndex: minFirstColumn,
|
|
89
|
+
maxLastColumnIndex: maxLastColumn
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
if (cellProps.colSpan > 1) {
|
|
93
|
+
i += cellProps.colSpan - 1;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}, [calculateCellColSpan]);
|
|
97
|
+
const columnSpanningApi = {
|
|
98
|
+
unstable_getCellColSpanInfo: getCellColSpanInfo,
|
|
99
|
+
unstable_calculateColSpan: calculateColSpan
|
|
100
|
+
};
|
|
101
|
+
useGridApiMethod(apiRef, columnSpanningApi, 'GridColumnSpanningAPI');
|
|
102
|
+
const handleColumnReorderChange = React.useCallback(() => {
|
|
103
|
+
// `colSpan` needs to be recalculated after column reordering
|
|
104
|
+
lookup.current = {};
|
|
105
|
+
}, []);
|
|
106
|
+
useGridApiEventHandler(apiRef, GridEvents.columnOrderChange, handleColumnReorderChange);
|
|
107
|
+
};
|
|
@@ -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";
|
|
@@ -208,7 +208,13 @@ export function useGridColumns(apiRef, props) {
|
|
|
208
208
|
if (colDef.hasBeenResized) {
|
|
209
209
|
const colDefDimensions = {};
|
|
210
210
|
COLUMNS_DIMENSION_PROPERTIES.forEach(propertyName => {
|
|
211
|
-
|
|
211
|
+
let propertyValue = colDef[propertyName];
|
|
212
|
+
|
|
213
|
+
if (propertyValue === Infinity) {
|
|
214
|
+
propertyValue = -1;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
colDefDimensions[propertyName] = propertyValue;
|
|
212
218
|
});
|
|
213
219
|
dimensions[colDef.field] = colDefDimensions;
|
|
214
220
|
}
|
|
@@ -262,12 +268,23 @@ export function useGridColumns(apiRef, props) {
|
|
|
262
268
|
* EVENTS
|
|
263
269
|
*/
|
|
264
270
|
|
|
265
|
-
const
|
|
266
|
-
|
|
267
|
-
|
|
271
|
+
const prevInnerWidth = React.useRef(null);
|
|
272
|
+
|
|
273
|
+
const handleGridSizeChange = viewportInnerSize => {
|
|
274
|
+
if (prevInnerWidth.current !== viewportInnerSize.width) {
|
|
275
|
+
prevInnerWidth.current = viewportInnerSize.width;
|
|
276
|
+
setGridColumnsState(hydrateColumnsWidth(gridColumnsSelector(apiRef.current.state), viewportInnerSize.width));
|
|
268
277
|
}
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
useGridApiEventHandler(apiRef, GridEvents.viewportInnerSizeChange, handleGridSizeChange);
|
|
281
|
+
useGridApiOptionHandler(apiRef, GridEvents.columnVisibilityChange, props.onColumnVisibilityChange);
|
|
282
|
+
/**
|
|
283
|
+
* APPLIERS
|
|
284
|
+
*/
|
|
269
285
|
|
|
270
|
-
|
|
286
|
+
const hydrateColumns = React.useCallback(() => {
|
|
287
|
+
logger.info(`Columns pipe processing have changed, regenerating the columns`);
|
|
271
288
|
const columnsState = createColumnsState({
|
|
272
289
|
apiRef,
|
|
273
290
|
columnTypes,
|
|
@@ -278,18 +295,7 @@ export function useGridColumns(apiRef, props) {
|
|
|
278
295
|
});
|
|
279
296
|
setGridColumnsState(columnsState);
|
|
280
297
|
}, [apiRef, logger, setGridColumnsState, columnTypes]);
|
|
281
|
-
|
|
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));
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
useGridApiEventHandler(apiRef, GridEvents.pipeProcessorRegister, handlepipeProcessorRegister);
|
|
291
|
-
useGridApiEventHandler(apiRef, GridEvents.viewportInnerSizeChange, handleGridSizeChange);
|
|
292
|
-
useGridApiOptionHandler(apiRef, GridEvents.columnVisibilityChange, props.onColumnVisibilityChange);
|
|
298
|
+
useGridRegisterPipeApplier(apiRef, 'hydrateColumns', hydrateColumns);
|
|
293
299
|
/**
|
|
294
300
|
* EFFECTS
|
|
295
301
|
*/
|
|
@@ -144,12 +144,12 @@ export function useGridDimensions(apiRef, props) {
|
|
|
144
144
|
const isJSDOM = /jsdom/.test(window.navigator.userAgent);
|
|
145
145
|
|
|
146
146
|
if (size.height === 0 && !warningShown.current && !props.autoHeight && !isJSDOM) {
|
|
147
|
-
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/
|
|
147
|
+
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'));
|
|
148
148
|
warningShown.current = true;
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
if (size.width === 0 && !warningShown.current && !isJSDOM) {
|
|
152
|
-
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/
|
|
152
|
+
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'));
|
|
153
153
|
warningShown.current = true;
|
|
154
154
|
}
|
|
155
155
|
|
|
@@ -170,7 +170,7 @@ export function useGridDimensions(apiRef, props) {
|
|
|
170
170
|
debounceResize();
|
|
171
171
|
}, [props.autoHeight, debounceResize, logger, resize]);
|
|
172
172
|
useEnhancedEffect(() => updateGridDimensionsRef(), [updateGridDimensionsRef]);
|
|
173
|
-
useGridApiOptionHandler(apiRef, GridEvents.
|
|
173
|
+
useGridApiOptionHandler(apiRef, GridEvents.sortedRowsSet, updateGridDimensionsRef);
|
|
174
174
|
useGridApiOptionHandler(apiRef, GridEvents.pageChange, updateGridDimensionsRef);
|
|
175
175
|
useGridApiOptionHandler(apiRef, GridEvents.pageSizeChange, updateGridDimensionsRef);
|
|
176
176
|
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
|
};
|
|
@@ -334,20 +334,7 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
334
334
|
return;
|
|
335
335
|
}
|
|
336
336
|
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
Object.entries(editingState[id]).forEach(([field, fieldProps]) => {
|
|
340
|
-
const column = apiRef.current.getColumn(field);
|
|
341
|
-
|
|
342
|
-
if (column.valueSetter) {
|
|
343
|
-
rowUpdate = column.valueSetter({
|
|
344
|
-
value: fieldProps.value,
|
|
345
|
-
row: rowUpdate
|
|
346
|
-
});
|
|
347
|
-
} else {
|
|
348
|
-
rowUpdate[field] = fieldProps.value;
|
|
349
|
-
}
|
|
350
|
-
});
|
|
337
|
+
const rowUpdate = apiRef.current.unstable_getRowWithUpdatedValuesFromRowEditing(id);
|
|
351
338
|
|
|
352
339
|
if (processRowUpdate) {
|
|
353
340
|
const handleError = errorThrown => {
|
|
@@ -489,11 +476,32 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
489
476
|
});
|
|
490
477
|
});
|
|
491
478
|
}, [apiRef, throwIfNotEditable, updateOrDeleteFieldState]);
|
|
479
|
+
const getRowWithUpdatedValuesFromRowEditing = React.useCallback(id => {
|
|
480
|
+
const editingState = gridEditRowsStateSelector(apiRef.current.state);
|
|
481
|
+
const row = apiRef.current.getRow(id);
|
|
482
|
+
|
|
483
|
+
let rowUpdate = _extends({}, row);
|
|
484
|
+
|
|
485
|
+
Object.entries(editingState[id]).forEach(([field, fieldProps]) => {
|
|
486
|
+
const column = apiRef.current.getColumn(field);
|
|
487
|
+
|
|
488
|
+
if (column.valueSetter) {
|
|
489
|
+
rowUpdate = column.valueSetter({
|
|
490
|
+
value: fieldProps.value,
|
|
491
|
+
row: rowUpdate
|
|
492
|
+
});
|
|
493
|
+
} else {
|
|
494
|
+
rowUpdate[field] = fieldProps.value;
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
return rowUpdate;
|
|
498
|
+
}, [apiRef]);
|
|
492
499
|
const editingApi = {
|
|
493
500
|
getRowMode,
|
|
494
501
|
startRowEditMode,
|
|
495
502
|
stopRowEditMode,
|
|
496
|
-
unstable_setRowEditingEditCellValue: setRowEditingEditCellValue
|
|
503
|
+
unstable_setRowEditingEditCellValue: setRowEditingEditCellValue,
|
|
504
|
+
unstable_getRowWithUpdatedValuesFromRowEditing: getRowWithUpdatedValuesFromRowEditing
|
|
497
505
|
};
|
|
498
506
|
useGridApiMethod(apiRef, editingApi, 'EditingApi');
|
|
499
507
|
};
|
|
@@ -40,11 +40,7 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
40
40
|
stateSelector: gridFilterModelSelector,
|
|
41
41
|
changeEvent: GridEvents.filterModelChange
|
|
42
42
|
});
|
|
43
|
-
|
|
44
|
-
* API METHODS
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
const applyFilters = React.useCallback(() => {
|
|
43
|
+
const updateFilteredRows = React.useCallback(() => {
|
|
48
44
|
apiRef.current.setState(state => {
|
|
49
45
|
const filterModel = gridFilterModelSelector(state, apiRef.current.instanceId);
|
|
50
46
|
const isRowMatchingFilters = props.filterMode === GridFeatureModeConstant.client ? buildAggregatedFilterApplier(filterModel, apiRef) : null;
|
|
@@ -55,9 +51,16 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
55
51
|
filter: _extends({}, state.filter, filteringResult)
|
|
56
52
|
});
|
|
57
53
|
});
|
|
58
|
-
apiRef.current.publishEvent(GridEvents.
|
|
54
|
+
apiRef.current.publishEvent(GridEvents.filteredRowsSet);
|
|
55
|
+
}, [props.filterMode, apiRef]);
|
|
56
|
+
/**
|
|
57
|
+
* API METHODS
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
const applyFilters = React.useCallback(() => {
|
|
61
|
+
updateFilteredRows();
|
|
59
62
|
apiRef.current.forceUpdate();
|
|
60
|
-
}, [apiRef,
|
|
63
|
+
}, [apiRef, updateFilteredRows]);
|
|
61
64
|
const upsertFilterItem = React.useCallback(item => {
|
|
62
65
|
const filterModel = gridFilterModelSelector(apiRef);
|
|
63
66
|
const items = [...filterModel.items];
|
|
@@ -237,8 +240,10 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
237
240
|
if (methodName === 'filtering') {
|
|
238
241
|
apiRef.current.unstable_applyFilters();
|
|
239
242
|
}
|
|
240
|
-
}, [apiRef]);
|
|
241
|
-
|
|
243
|
+
}, [apiRef]); // Do not call `apiRef.current.forceUpdate` to avoid re-render before updating the sorted rows.
|
|
244
|
+
// Otherwise, the state is not consistent during the render
|
|
245
|
+
|
|
246
|
+
useGridApiEventHandler(apiRef, GridEvents.rowsSet, updateFilteredRows);
|
|
242
247
|
useGridApiEventHandler(apiRef, GridEvents.rowExpansionChange, apiRef.current.unstable_applyFilters);
|
|
243
248
|
useGridApiEventHandler(apiRef, GridEvents.columnsChange, handleColumnsChange);
|
|
244
249
|
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);
|
|
@@ -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,38 @@ 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
|
+
const visibleSortedRows = gridVisibleSortedRowEntriesSelector(apiRef);
|
|
34
|
+
const rowId = visibleSortedRows[rowIndex]?.id;
|
|
35
|
+
const nextCellColSpanInfo = apiRef.current.unstable_getCellColSpanInfo(rowId, colIndex);
|
|
36
|
+
|
|
37
|
+
if (nextCellColSpanInfo && nextCellColSpanInfo.spannedByColSpan) {
|
|
38
|
+
if (closestColumnToUse === 'left') {
|
|
39
|
+
colIndex = nextCellColSpanInfo.leftVisibleCellIndex;
|
|
40
|
+
} else if (closestColumnToUse === 'right') {
|
|
41
|
+
colIndex = nextCellColSpanInfo.rightVisibleCellIndex;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
25
45
|
logger.debug(`Navigating to cell row ${rowIndex}, col ${colIndex}`);
|
|
26
46
|
apiRef.current.scrollToIndexes({
|
|
27
47
|
colIndex,
|
|
28
48
|
rowIndex
|
|
29
49
|
});
|
|
30
50
|
const field = apiRef.current.getVisibleColumns()[colIndex].field;
|
|
31
|
-
|
|
32
|
-
const node = visibleSortedRows[rowIndex];
|
|
33
|
-
apiRef.current.setCellFocus(node.id, field);
|
|
51
|
+
apiRef.current.setCellFocus(rowId, field);
|
|
34
52
|
}, [apiRef, logger]);
|
|
35
53
|
const goToHeader = React.useCallback((colIndex, event) => {
|
|
36
54
|
logger.debug(`Navigating to header col ${colIndex}`);
|
|
@@ -83,7 +101,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
83
101
|
case 'ArrowRight':
|
|
84
102
|
{
|
|
85
103
|
if (colIndexBefore < lastColIndex) {
|
|
86
|
-
goToCell(colIndexBefore + 1, rowIndexBefore);
|
|
104
|
+
goToCell(colIndexBefore + 1, rowIndexBefore, 'right');
|
|
87
105
|
}
|
|
88
106
|
|
|
89
107
|
break;
|
|
@@ -102,9 +120,9 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
102
120
|
{
|
|
103
121
|
// "Tab" is only triggered by the row / cell editing feature
|
|
104
122
|
if (event.shiftKey && colIndexBefore > firstColIndex) {
|
|
105
|
-
goToCell(colIndexBefore - 1, rowIndexBefore);
|
|
123
|
+
goToCell(colIndexBefore - 1, rowIndexBefore, 'left');
|
|
106
124
|
} else if (!event.shiftKey && colIndexBefore < lastColIndex) {
|
|
107
|
-
goToCell(colIndexBefore + 1, rowIndexBefore);
|
|
125
|
+
goToCell(colIndexBefore + 1, rowIndexBefore, 'right');
|
|
108
126
|
}
|
|
109
127
|
|
|
110
128
|
break;
|
|
@@ -112,6 +130,18 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
112
130
|
|
|
113
131
|
case ' ':
|
|
114
132
|
{
|
|
133
|
+
const field = params.field;
|
|
134
|
+
|
|
135
|
+
if (field === GRID_DETAIL_PANEL_TOGGLE_FIELD) {
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const colDef = params.colDef;
|
|
140
|
+
|
|
141
|
+
if (colDef && colDef.type === 'treeDataGroup') {
|
|
142
|
+
break;
|
|
143
|
+
}
|
|
144
|
+
|
|
115
145
|
if (!event.shiftKey && rowIndexBefore < lastRowIndexInPage) {
|
|
116
146
|
goToCell(colIndexBefore, Math.min(rowIndexBefore + viewportPageSize, lastRowIndexInPage));
|
|
117
147
|
}
|
|
@@ -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);
|