@mui/x-data-grid 6.0.0-alpha.2 → 6.0.0-alpha.4
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 +493 -141
- package/DataGrid/DataGrid.js +14 -34
- package/DataGrid/useDataGridComponent.js +8 -14
- package/DataGrid/useDataGridProps.js +3 -3
- package/colDef/gridCheckboxSelectionColDef.js +1 -1
- package/colDef/gridNumericOperators.d.ts +1 -1
- package/colDef/gridSingleSelectOperators.d.ts +1 -1
- package/colDef/gridStringOperators.d.ts +1 -1
- package/components/GridFooter.js +1 -1
- package/components/GridRow.js +2 -2
- package/components/base/GridBody.js +2 -2
- package/components/cell/GridEditInputCell.js +3 -8
- package/components/cell/GridEditSingleSelectCell.js +6 -38
- package/components/columnHeaders/GridColumnGroupHeader.d.ts +2 -0
- package/components/columnHeaders/GridColumnGroupHeader.js +32 -5
- package/components/columnSelection/GridHeaderCheckbox.js +3 -3
- package/components/containers/GridRoot.js +4 -3
- package/components/panel/GridColumnsPanel.d.ts +2 -0
- package/components/panel/GridColumnsPanel.js +10 -4
- package/components/panel/filterPanel/GridFilterForm.d.ts +12 -0
- package/components/panel/filterPanel/GridFilterForm.js +29 -7
- package/components/panel/filterPanel/GridFilterPanel.d.ts +12 -0
- package/components/panel/filterPanel/GridFilterPanel.js +64 -19
- package/hooks/core/pipeProcessing/useGridRegisterPipeApplier.d.ts +1 -1
- package/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.d.ts +1 -1
- package/hooks/core/strategyProcessing/useGridRegisterStrategyProcessor.d.ts +1 -1
- package/hooks/core/useGridInitialization.d.ts +1 -1
- package/hooks/core/useGridStateInitialization.d.ts +1 -1
- package/hooks/features/columnGrouping/gridColumnGroupsInterfaces.d.ts +10 -1
- package/hooks/features/columnGrouping/gridColumnGroupsSelector.d.ts +6 -0
- package/hooks/features/columnGrouping/gridColumnGroupsSelector.js +34 -1
- package/hooks/features/columnGrouping/gridColumnGroupsUtils.d.ts +15 -0
- package/hooks/features/columnGrouping/gridColumnGroupsUtils.js +89 -0
- package/hooks/features/columnGrouping/useGridColumnGrouping.d.ts +1 -15
- package/hooks/features/columnGrouping/useGridColumnGrouping.js +66 -66
- package/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +1 -1
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +60 -116
- package/hooks/features/density/densitySelector.d.ts +0 -2
- package/hooks/features/density/densitySelector.js +1 -3
- package/hooks/features/density/densityState.d.ts +0 -1
- package/hooks/features/density/useGridDensity.d.ts +1 -1
- package/hooks/features/density/useGridDensity.js +9 -45
- package/hooks/features/dimensions/useGridDimensions.js +3 -2
- package/hooks/features/{editRows/gridEditRowsSelector.d.ts → editing/gridEditingSelectors.d.ts} +0 -0
- package/hooks/features/{editRows/gridEditRowsSelector.js → editing/gridEditingSelectors.js} +0 -0
- package/hooks/features/editing/index.d.ts +1 -0
- package/hooks/features/editing/index.js +1 -0
- package/hooks/features/{editRows/useGridCellEditing.new.d.ts → editing/useGridCellEditing.d.ts} +0 -0
- package/hooks/features/{editRows/useGridCellEditing.new.js → editing/useGridCellEditing.js} +21 -6
- package/hooks/features/{editRows/useGridEditing.new.d.ts → editing/useGridEditing.d.ts} +0 -0
- package/hooks/features/{editRows/useGridEditing.new.js → editing/useGridEditing.js} +3 -3
- package/hooks/features/{editRows/useGridRowEditing.new.d.ts → editing/useGridRowEditing.d.ts} +0 -0
- package/hooks/features/{editRows/useGridRowEditing.new.js → editing/useGridRowEditing.js} +20 -6
- package/hooks/features/export/useGridPrintExport.js +2 -2
- package/hooks/features/focus/gridFocusState.d.ts +6 -0
- package/hooks/features/focus/gridFocusStateSelector.d.ts +2 -0
- package/hooks/features/focus/gridFocusStateSelector.js +6 -2
- package/hooks/features/focus/useGridFocus.js +69 -11
- package/hooks/features/index.d.ts +2 -2
- package/hooks/features/index.js +2 -2
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +135 -1
- package/hooks/features/{selection/gridSelectionSelector.d.ts → rowSelection/gridRowSelectionSelector.d.ts} +1 -1
- package/hooks/features/rowSelection/gridRowSelectionSelector.js +9 -0
- package/hooks/features/rowSelection/index.d.ts +1 -0
- package/hooks/features/rowSelection/index.js +1 -0
- package/hooks/features/rowSelection/useGridRowSelection.d.ts +12 -0
- package/hooks/features/{selection/useGridSelection.js → rowSelection/useGridRowSelection.js} +37 -37
- package/hooks/features/{selection/useGridSelectionPreProcessors.d.ts → rowSelection/useGridRowSelectionPreProcessors.d.ts} +1 -1
- package/hooks/features/{selection/useGridSelectionPreProcessors.js → rowSelection/useGridRowSelectionPreProcessors.js} +1 -1
- package/hooks/features/rows/gridRowsInterfaces.d.ts +4 -0
- package/hooks/features/rows/gridRowsUtils.d.ts +1 -1
- package/hooks/features/rows/gridRowsUtils.js +5 -2
- package/hooks/features/rows/useGridRows.js +23 -7
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +1 -1
- package/hooks/features/virtualization/useGridVirtualScroller.js +2 -2
- package/hooks/utils/useGridApi.d.ts +1 -1
- package/hooks/utils/useGridApiEventHandler.d.ts +2 -2
- package/hooks/utils/useGridApiRef.d.ts +1 -1
- package/hooks/utils/useGridInitializeState.d.ts +1 -1
- package/hooks/utils/useGridNativeEventListener.d.ts +1 -1
- package/hooks/utils/useGridSelector.d.ts +1 -1
- package/hooks/utils/useGridState.d.ts +1 -1
- package/hooks/utils/useGridVisibleRows.d.ts +2 -2
- package/index.js +1 -1
- package/internals/index.d.ts +3 -5
- package/internals/index.js +3 -5
- package/legacy/DataGrid/DataGrid.js +14 -34
- package/legacy/DataGrid/useDataGridComponent.js +8 -14
- package/legacy/DataGrid/useDataGridProps.js +3 -3
- package/legacy/colDef/gridCheckboxSelectionColDef.js +1 -1
- package/legacy/components/GridFooter.js +1 -1
- package/legacy/components/GridRow.js +2 -2
- package/legacy/components/base/GridBody.js +2 -2
- package/legacy/components/cell/GridEditInputCell.js +3 -8
- package/legacy/components/cell/GridEditSingleSelectCell.js +6 -52
- package/legacy/components/columnHeaders/GridColumnGroupHeader.js +46 -13
- package/legacy/components/columnSelection/GridHeaderCheckbox.js +3 -3
- package/legacy/components/containers/GridRoot.js +4 -3
- package/legacy/components/panel/GridColumnsPanel.js +10 -3
- package/legacy/components/panel/filterPanel/GridFilterForm.js +31 -7
- package/legacy/components/panel/filterPanel/GridFilterPanel.js +67 -18
- package/legacy/hooks/features/columnGrouping/gridColumnGroupsSelector.js +33 -1
- package/legacy/hooks/features/columnGrouping/gridColumnGroupsUtils.js +96 -0
- package/legacy/hooks/features/columnGrouping/useGridColumnGrouping.js +64 -64
- package/legacy/hooks/features/columnHeaders/useGridColumnHeaders.js +70 -122
- package/legacy/hooks/features/density/densitySelector.js +0 -6
- package/legacy/hooks/features/density/useGridDensity.js +6 -44
- package/legacy/hooks/features/dimensions/useGridDimensions.js +3 -2
- package/legacy/hooks/features/{editRows/gridEditRowsSelector.js → editing/gridEditingSelectors.js} +0 -0
- package/legacy/hooks/features/editing/index.js +1 -0
- package/legacy/hooks/features/{editRows/useGridCellEditing.new.js → editing/useGridCellEditing.js} +21 -6
- package/legacy/hooks/features/{editRows/useGridEditing.new.js → editing/useGridEditing.js} +3 -3
- package/legacy/hooks/features/{editRows/useGridRowEditing.new.js → editing/useGridRowEditing.js} +20 -6
- package/legacy/hooks/features/export/useGridPrintExport.js +2 -2
- package/legacy/hooks/features/focus/gridFocusStateSelector.js +8 -0
- package/legacy/hooks/features/focus/useGridFocus.js +72 -11
- package/legacy/hooks/features/index.js +2 -2
- package/legacy/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +129 -1
- package/legacy/hooks/features/rowSelection/gridRowSelectionSelector.js +19 -0
- package/legacy/hooks/features/rowSelection/index.js +1 -0
- package/legacy/hooks/features/{selection/useGridSelection.js → rowSelection/useGridRowSelection.js} +37 -37
- package/legacy/hooks/features/{selection/useGridSelectionPreProcessors.js → rowSelection/useGridRowSelectionPreProcessors.js} +1 -1
- package/legacy/hooks/features/rows/gridRowsUtils.js +5 -2
- package/legacy/hooks/features/rows/useGridRows.js +25 -7
- package/legacy/hooks/features/virtualization/useGridVirtualScroller.js +2 -2
- package/legacy/index.js +1 -1
- package/legacy/internals/index.js +3 -5
- package/legacy/locales/trTR.js +17 -17
- package/legacy/models/api/{gridSelectionApi.js → gridRowSelectionApi.js} +0 -0
- package/legacy/models/api/index.js +1 -1
- package/legacy/models/{gridSelectionModel.js → gridRowSelectionModel.js} +0 -0
- package/legacy/models/index.js +1 -1
- package/{models/api/gridSelectionApi.js → legacy/models/params/gridColumnGroupHeaderParams.js} +0 -0
- package/legacy/models/params/gridEditCellParams.js +0 -4
- package/legacy/models/params/index.js +1 -0
- package/locales/trTR.js +17 -17
- package/models/api/gridApiCommon.d.ts +3 -6
- package/models/api/gridApiCommunity.d.ts +1 -7
- package/models/api/gridEditingApi.d.ts +36 -121
- package/models/api/gridFocusApi.d.ts +13 -0
- package/models/api/{gridSelectionApi.d.ts → gridRowSelectionApi.d.ts} +2 -2
- package/models/{gridSelectionModel.js → api/gridRowSelectionApi.js} +0 -0
- package/models/api/index.d.ts +2 -2
- package/models/api/index.js +1 -1
- package/models/colDef/gridColDef.d.ts +0 -8
- package/models/events/gridEventLookup.d.ts +30 -19
- package/models/gridColumnGrouping.d.ts +1 -26
- package/models/gridRowSelectionModel.d.ts +3 -0
- package/{modern/models/api/gridSelectionApi.js → models/gridRowSelectionModel.js} +0 -0
- package/models/gridStateCommunity.d.ts +2 -2
- package/models/index.d.ts +1 -1
- package/models/index.js +1 -1
- package/models/params/gridColumnGroupHeaderParams.d.ts +30 -0
- package/{modern/models/gridSelectionModel.js → models/params/gridColumnGroupHeaderParams.js} +0 -0
- package/models/params/gridEditCellParams.d.ts +4 -17
- package/models/params/gridEditCellParams.js +0 -4
- package/models/params/gridRowParams.d.ts +4 -4
- package/models/params/index.d.ts +1 -0
- package/models/params/index.js +1 -0
- package/models/props/DataGridProps.d.ts +8 -32
- package/modern/DataGrid/DataGrid.js +14 -34
- package/modern/DataGrid/useDataGridComponent.js +8 -12
- package/modern/DataGrid/useDataGridProps.js +3 -3
- package/modern/colDef/gridCheckboxSelectionColDef.js +1 -1
- package/modern/components/GridFooter.js +1 -1
- package/modern/components/GridRow.js +2 -2
- package/modern/components/base/GridBody.js +2 -2
- package/modern/components/cell/GridEditInputCell.js +3 -4
- package/modern/components/cell/GridEditSingleSelectCell.js +6 -34
- package/modern/components/columnHeaders/GridColumnGroupHeader.js +32 -5
- package/modern/components/columnSelection/GridHeaderCheckbox.js +3 -3
- package/modern/components/containers/GridRoot.js +4 -3
- package/modern/components/panel/GridColumnsPanel.js +10 -4
- package/modern/components/panel/filterPanel/GridFilterForm.js +29 -7
- package/modern/components/panel/filterPanel/GridFilterPanel.js +62 -17
- package/modern/hooks/features/columnGrouping/gridColumnGroupsSelector.js +14 -1
- package/modern/hooks/features/columnGrouping/gridColumnGroupsUtils.js +83 -0
- package/modern/hooks/features/columnGrouping/useGridColumnGrouping.js +50 -62
- package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +58 -98
- package/modern/hooks/features/density/densitySelector.js +1 -3
- package/modern/hooks/features/density/useGridDensity.js +9 -37
- package/modern/hooks/features/dimensions/useGridDimensions.js +3 -2
- package/modern/hooks/features/{editRows/gridEditRowsSelector.js → editing/gridEditingSelectors.js} +0 -0
- package/modern/hooks/features/editing/index.js +1 -0
- package/modern/hooks/features/{editRows/useGridCellEditing.new.js → editing/useGridCellEditing.js} +21 -6
- package/modern/hooks/features/{editRows/useGridEditing.new.js → editing/useGridEditing.js} +3 -3
- package/modern/hooks/features/{editRows/useGridRowEditing.new.js → editing/useGridRowEditing.js} +20 -6
- package/modern/hooks/features/export/useGridPrintExport.js +2 -2
- package/modern/hooks/features/focus/gridFocusStateSelector.js +6 -2
- package/modern/hooks/features/focus/useGridFocus.js +69 -11
- package/modern/hooks/features/index.js +2 -2
- package/modern/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +135 -1
- package/modern/hooks/features/rowSelection/gridRowSelectionSelector.js +9 -0
- package/modern/hooks/features/rowSelection/index.js +1 -0
- package/modern/hooks/features/{selection/useGridSelection.js → rowSelection/useGridRowSelection.js} +37 -37
- package/modern/hooks/features/{selection/useGridSelectionPreProcessors.js → rowSelection/useGridRowSelectionPreProcessors.js} +1 -1
- package/modern/hooks/features/rows/gridRowsUtils.js +5 -2
- package/modern/hooks/features/rows/useGridRows.js +23 -7
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +2 -2
- package/modern/index.js +1 -1
- package/modern/internals/index.js +3 -5
- package/modern/locales/trTR.js +17 -17
- package/modern/models/api/gridRowSelectionApi.js +1 -0
- package/modern/models/api/index.js +1 -1
- package/modern/models/gridRowSelectionModel.js +1 -0
- package/modern/models/index.js +1 -1
- package/modern/models/params/gridColumnGroupHeaderParams.js +1 -0
- package/modern/models/params/gridEditCellParams.js +0 -4
- package/modern/models/params/index.js +1 -0
- package/node/DataGrid/DataGrid.js +14 -34
- package/node/DataGrid/useDataGridComponent.js +9 -17
- package/node/DataGrid/useDataGridProps.js +3 -3
- package/node/colDef/gridCheckboxSelectionColDef.js +2 -2
- package/node/components/GridFooter.js +2 -2
- package/node/components/GridRow.js +2 -2
- package/node/components/base/GridBody.js +2 -2
- package/node/components/cell/GridEditInputCell.js +3 -9
- package/node/components/cell/GridEditSingleSelectCell.js +6 -38
- package/node/components/columnHeaders/GridColumnGroupHeader.js +32 -5
- package/node/components/columnSelection/GridHeaderCheckbox.js +3 -3
- package/node/components/containers/GridRoot.js +4 -2
- package/node/components/panel/GridColumnsPanel.js +10 -4
- package/node/components/panel/filterPanel/GridFilterForm.js +30 -7
- package/node/components/panel/filterPanel/GridFilterPanel.js +63 -19
- package/node/hooks/features/columnGrouping/gridColumnGroupsSelector.js +40 -3
- package/node/hooks/features/columnGrouping/gridColumnGroupsUtils.js +102 -0
- package/node/hooks/features/columnGrouping/useGridColumnGrouping.js +68 -71
- package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +57 -113
- package/node/hooks/features/density/densitySelector.js +2 -6
- package/node/hooks/features/density/useGridDensity.js +9 -48
- package/node/hooks/features/dimensions/useGridDimensions.js +3 -1
- package/node/hooks/features/{editRows/gridEditRowsSelector.js → editing/gridEditingSelectors.js} +0 -0
- package/node/hooks/features/{editRows → editing}/index.js +4 -4
- package/node/hooks/features/{editRows/useGridCellEditing.new.js → editing/useGridCellEditing.js} +28 -13
- package/node/hooks/features/{editRows/useGridEditing.new.js → editing/useGridEditing.js} +4 -4
- package/node/hooks/features/{editRows/useGridRowEditing.new.js → editing/useGridRowEditing.js} +28 -14
- package/node/hooks/features/export/useGridPrintExport.js +2 -2
- package/node/hooks/features/focus/gridFocusStateSelector.js +10 -4
- package/node/hooks/features/focus/useGridFocus.js +68 -10
- package/node/hooks/features/index.js +8 -8
- package/node/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +138 -1
- package/node/hooks/features/{selection/gridSelectionSelector.js → rowSelection/gridRowSelectionSelector.js} +6 -6
- package/node/hooks/features/rowSelection/index.js +18 -0
- package/node/hooks/features/{selection/useGridSelection.js → rowSelection/useGridRowSelection.js} +43 -43
- package/node/hooks/features/{selection/useGridSelectionPreProcessors.js → rowSelection/useGridRowSelectionPreProcessors.js} +3 -3
- package/node/hooks/features/rows/gridRowsUtils.js +5 -2
- package/node/hooks/features/rows/useGridRows.js +23 -7
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +4 -4
- package/node/index.js +1 -1
- package/node/internals/index.js +23 -45
- package/node/locales/trTR.js +17 -17
- package/node/models/api/{gridSelectionApi.js → gridRowSelectionApi.js} +0 -0
- package/node/models/api/index.js +4 -4
- package/node/models/{gridSelectionModel.js → gridRowSelectionModel.js} +0 -0
- package/node/models/index.js +4 -4
- package/node/models/params/gridColumnGroupHeaderParams.js +5 -0
- package/node/models/params/gridEditCellParams.js +0 -3
- package/node/models/params/index.js +13 -0
- package/package.json +2 -2
- package/hooks/features/columnGrouping/useGridColumnGroupingPreProcessors.d.ts +0 -4
- package/hooks/features/columnGrouping/useGridColumnGroupingPreProcessors.js +0 -35
- package/hooks/features/editRows/index.d.ts +0 -1
- package/hooks/features/editRows/index.js +0 -1
- package/hooks/features/editRows/useGridCellEditing.old.d.ts +0 -4
- package/hooks/features/editRows/useGridCellEditing.old.js +0 -359
- package/hooks/features/editRows/useGridEditing.old.d.ts +0 -11
- package/hooks/features/editRows/useGridEditing.old.js +0 -167
- package/hooks/features/editRows/useGridRowEditing.old.d.ts +0 -4
- package/hooks/features/editRows/useGridRowEditing.old.js +0 -334
- package/hooks/features/selection/gridSelectionSelector.js +0 -9
- package/hooks/features/selection/index.d.ts +0 -1
- package/hooks/features/selection/index.js +0 -1
- package/hooks/features/selection/useGridSelection.d.ts +0 -12
- package/legacy/hooks/features/columnGrouping/useGridColumnGroupingPreProcessors.js +0 -35
- package/legacy/hooks/features/editRows/index.js +0 -1
- package/legacy/hooks/features/editRows/useGridCellEditing.old.js +0 -411
- package/legacy/hooks/features/editRows/useGridEditing.old.js +0 -184
- package/legacy/hooks/features/editRows/useGridRowEditing.old.js +0 -505
- package/legacy/hooks/features/selection/gridSelectionSelector.js +0 -19
- package/legacy/hooks/features/selection/index.js +0 -1
- package/models/gridSelectionModel.d.ts +0 -3
- package/modern/hooks/features/columnGrouping/useGridColumnGroupingPreProcessors.js +0 -29
- package/modern/hooks/features/editRows/index.js +0 -1
- package/modern/hooks/features/editRows/useGridCellEditing.old.js +0 -355
- package/modern/hooks/features/editRows/useGridEditing.old.js +0 -163
- package/modern/hooks/features/editRows/useGridRowEditing.old.js +0 -326
- package/modern/hooks/features/selection/gridSelectionSelector.js +0 -9
- package/modern/hooks/features/selection/index.js +0 -1
- package/node/hooks/features/columnGrouping/useGridColumnGroupingPreProcessors.js +0 -55
- package/node/hooks/features/editRows/useGridCellEditing.old.js +0 -380
- package/node/hooks/features/editRows/useGridEditing.old.js +0 -193
- package/node/hooks/features/editRows/useGridRowEditing.old.js +0 -358
- package/node/hooks/features/selection/index.js +0 -18
|
@@ -4,7 +4,7 @@ import { ownerDocument } from '@mui/material/utils';
|
|
|
4
4
|
import { useGridLogger } from '../../utils/useGridLogger';
|
|
5
5
|
import { gridVisibleRowCountSelector } from '../filter/gridFilterSelector';
|
|
6
6
|
import { gridColumnDefinitionsSelector, gridColumnVisibilityModelSelector } from '../columns/gridColumnsSelector';
|
|
7
|
-
import {
|
|
7
|
+
import { gridTotalHeaderHeightSelector } from '../columnGrouping/gridColumnGroupsSelector';
|
|
8
8
|
import { gridClasses } from '../../../constants/gridClasses';
|
|
9
9
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
10
10
|
import { gridRowsMetaSelector } from '../rows/gridRowsMetaSelector';
|
|
@@ -81,7 +81,7 @@ export const useGridPrintExport = (apiRef, props) => {
|
|
|
81
81
|
return;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
const totalHeaderHeight =
|
|
84
|
+
const totalHeaderHeight = gridTotalHeaderHeightSelector(apiRef);
|
|
85
85
|
const rowsMeta = gridRowsMetaSelector(apiRef.current.state);
|
|
86
86
|
const gridRootElement = apiRef.current.rootElementRef.current;
|
|
87
87
|
const gridClone = gridRootElement.cloneNode(true);
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { createSelector } from '../../../utils/createSelector';
|
|
2
2
|
export const gridFocusStateSelector = state => state.focus;
|
|
3
3
|
export const gridFocusCellSelector = createSelector(gridFocusStateSelector, focusState => focusState.cell);
|
|
4
|
-
export const gridFocusColumnHeaderSelector = createSelector(gridFocusStateSelector, focusState => focusState.columnHeader);
|
|
4
|
+
export const gridFocusColumnHeaderSelector = createSelector(gridFocusStateSelector, focusState => focusState.columnHeader); // eslint-disable-next-line @typescript-eslint/naming-convention
|
|
5
|
+
|
|
6
|
+
export const unstable_gridFocusColumnGroupHeaderSelector = createSelector(gridFocusStateSelector, focusState => focusState.columnGroupHeader);
|
|
5
7
|
export const gridTabIndexStateSelector = state => state.tabIndex;
|
|
6
8
|
export const gridTabIndexCellSelector = createSelector(gridTabIndexStateSelector, state => state.cell);
|
|
7
|
-
export const gridTabIndexColumnHeaderSelector = createSelector(gridTabIndexStateSelector, state => state.columnHeader);
|
|
9
|
+
export const gridTabIndexColumnHeaderSelector = createSelector(gridTabIndexStateSelector, state => state.columnHeader); // eslint-disable-next-line @typescript-eslint/naming-convention
|
|
10
|
+
|
|
11
|
+
export const unstable_gridTabIndexColumnGroupHeaderSelector = createSelector(gridTabIndexStateSelector, state => state.columnGroupHeader);
|
|
@@ -5,18 +5,20 @@ import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
|
5
5
|
import { useGridLogger } from '../../utils/useGridLogger';
|
|
6
6
|
import { useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
|
|
7
7
|
import { isNavigationKey } from '../../../utils/keyboardUtils';
|
|
8
|
-
import { gridFocusCellSelector } from './gridFocusStateSelector';
|
|
8
|
+
import { gridFocusCellSelector, unstable_gridFocusColumnGroupHeaderSelector } from './gridFocusStateSelector';
|
|
9
9
|
import { gridVisibleColumnDefinitionsSelector } from '../columns/gridColumnsSelector';
|
|
10
10
|
import { getVisibleRows } from '../../utils/useGridVisibleRows';
|
|
11
11
|
import { clamp } from '../../../utils/utils';
|
|
12
12
|
export const focusStateInitializer = state => _extends({}, state, {
|
|
13
13
|
focus: {
|
|
14
14
|
cell: null,
|
|
15
|
-
columnHeader: null
|
|
15
|
+
columnHeader: null,
|
|
16
|
+
columnGroupHeader: null
|
|
16
17
|
},
|
|
17
18
|
tabIndex: {
|
|
18
19
|
cell: null,
|
|
19
|
-
columnHeader: null
|
|
20
|
+
columnHeader: null,
|
|
21
|
+
columnGroupHeader: null
|
|
20
22
|
}
|
|
21
23
|
});
|
|
22
24
|
/**
|
|
@@ -51,14 +53,16 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
51
53
|
id,
|
|
52
54
|
field
|
|
53
55
|
},
|
|
54
|
-
columnHeader: null
|
|
56
|
+
columnHeader: null,
|
|
57
|
+
columnGroupHeader: null
|
|
55
58
|
},
|
|
56
59
|
focus: {
|
|
57
60
|
cell: {
|
|
58
61
|
id,
|
|
59
62
|
field
|
|
60
63
|
},
|
|
61
|
-
columnHeader: null
|
|
64
|
+
columnHeader: null,
|
|
65
|
+
columnGroupHeader: null
|
|
62
66
|
}
|
|
63
67
|
});
|
|
64
68
|
});
|
|
@@ -86,18 +90,50 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
86
90
|
columnHeader: {
|
|
87
91
|
field
|
|
88
92
|
},
|
|
89
|
-
cell: null
|
|
93
|
+
cell: null,
|
|
94
|
+
columnGroupHeader: null
|
|
90
95
|
},
|
|
91
96
|
focus: {
|
|
92
97
|
columnHeader: {
|
|
93
98
|
field
|
|
94
99
|
},
|
|
95
|
-
cell: null
|
|
100
|
+
cell: null,
|
|
101
|
+
columnGroupHeader: null
|
|
96
102
|
}
|
|
97
103
|
});
|
|
98
104
|
});
|
|
99
105
|
apiRef.current.forceUpdate();
|
|
100
106
|
}, [apiRef, logger, publishCellFocusOut]);
|
|
107
|
+
const setColumnGroupHeaderFocus = React.useCallback((field, depth, event = {}) => {
|
|
108
|
+
const cell = gridFocusCellSelector(apiRef);
|
|
109
|
+
|
|
110
|
+
if (cell) {
|
|
111
|
+
apiRef.current.publishEvent('cellFocusOut', apiRef.current.getCellParams(cell.id, cell.field), event);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
apiRef.current.setState(state => {
|
|
115
|
+
return _extends({}, state, {
|
|
116
|
+
tabIndex: {
|
|
117
|
+
columnGroupHeader: {
|
|
118
|
+
field,
|
|
119
|
+
depth
|
|
120
|
+
},
|
|
121
|
+
columnHeader: null,
|
|
122
|
+
cell: null
|
|
123
|
+
},
|
|
124
|
+
focus: {
|
|
125
|
+
columnGroupHeader: {
|
|
126
|
+
field,
|
|
127
|
+
depth
|
|
128
|
+
},
|
|
129
|
+
columnHeader: null,
|
|
130
|
+
cell: null
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
apiRef.current.forceUpdate();
|
|
135
|
+
}, [apiRef]);
|
|
136
|
+
const getColumnGroupHeaderFocus = React.useCallback(() => unstable_gridFocusColumnGroupHeaderSelector(apiRef), [apiRef]);
|
|
101
137
|
const moveFocusToRelativeCell = React.useCallback((id, field, direction) => {
|
|
102
138
|
let columnIndexToFocus = apiRef.current.getColumnIndex(field);
|
|
103
139
|
let rowIndexToFocus = apiRef.current.getRowIndexRelativeToVisibleRows(id);
|
|
@@ -173,12 +209,29 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
173
209
|
|
|
174
210
|
apiRef.current.setColumnHeaderFocus(field, event);
|
|
175
211
|
}, [apiRef]);
|
|
212
|
+
const focussedColumnGroup = unstable_gridFocusColumnGroupHeaderSelector(apiRef);
|
|
213
|
+
const handleColumnGroupHeaderFocus = React.useCallback(({
|
|
214
|
+
fields,
|
|
215
|
+
depth
|
|
216
|
+
}, event) => {
|
|
217
|
+
if (event.target !== event.currentTarget) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (focussedColumnGroup !== null && focussedColumnGroup.depth === depth && fields.includes(focussedColumnGroup.field)) {
|
|
222
|
+
// This group cell has already been focused
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
apiRef.current.unstable_setColumnGroupHeaderFocus(fields[0], depth, event);
|
|
227
|
+
}, [apiRef, focussedColumnGroup]);
|
|
176
228
|
const handleBlur = React.useCallback(() => {
|
|
177
229
|
logger.debug(`Clearing focus`);
|
|
178
230
|
apiRef.current.setState(state => _extends({}, state, {
|
|
179
231
|
focus: {
|
|
180
232
|
cell: null,
|
|
181
|
-
columnHeader: null
|
|
233
|
+
columnHeader: null,
|
|
234
|
+
columnGroupHeader: null
|
|
182
235
|
}
|
|
183
236
|
}));
|
|
184
237
|
}, [logger, apiRef]);
|
|
@@ -214,7 +267,8 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
214
267
|
apiRef.current.setState(state => _extends({}, state, {
|
|
215
268
|
focus: {
|
|
216
269
|
cell: null,
|
|
217
|
-
columnHeader: null
|
|
270
|
+
columnHeader: null,
|
|
271
|
+
columnGroupHeader: null
|
|
218
272
|
}
|
|
219
273
|
}));
|
|
220
274
|
apiRef.current.forceUpdate(); // There's a focused cell but another element (not a cell) was clicked
|
|
@@ -241,7 +295,8 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
241
295
|
apiRef.current.setState(state => _extends({}, state, {
|
|
242
296
|
focus: {
|
|
243
297
|
cell: null,
|
|
244
|
-
columnHeader: null
|
|
298
|
+
columnHeader: null,
|
|
299
|
+
columnGroupHeader: null
|
|
245
300
|
}
|
|
246
301
|
}));
|
|
247
302
|
}
|
|
@@ -249,7 +304,9 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
249
304
|
useGridApiMethod(apiRef, {
|
|
250
305
|
setCellFocus,
|
|
251
306
|
setColumnHeaderFocus,
|
|
252
|
-
unstable_moveFocusToRelativeCell: moveFocusToRelativeCell
|
|
307
|
+
unstable_moveFocusToRelativeCell: moveFocusToRelativeCell,
|
|
308
|
+
unstable_setColumnGroupHeaderFocus: setColumnGroupHeaderFocus,
|
|
309
|
+
unstable_getColumnGroupHeaderFocus: getColumnGroupHeaderFocus
|
|
253
310
|
}, 'GridFocusApi');
|
|
254
311
|
React.useEffect(() => {
|
|
255
312
|
const doc = ownerDocument(apiRef.current.rootElementRef.current);
|
|
@@ -264,5 +321,6 @@ export const useGridFocus = (apiRef, props) => {
|
|
|
264
321
|
useGridApiEventHandler(apiRef, 'cellKeyDown', handleCellKeyDown);
|
|
265
322
|
useGridApiEventHandler(apiRef, 'cellModeChange', handleCellModeChange);
|
|
266
323
|
useGridApiEventHandler(apiRef, 'columnHeaderFocus', handleColumnHeaderFocus);
|
|
324
|
+
useGridApiEventHandler(apiRef, 'columnGroupHeaderFocus', handleColumnGroupHeaderFocus);
|
|
267
325
|
useGridApiEventHandler(apiRef, 'rowsSet', handleRowSet);
|
|
268
326
|
};
|
|
@@ -3,13 +3,13 @@ export * from './columnMenu';
|
|
|
3
3
|
export * from './columns';
|
|
4
4
|
export * from './columnGrouping';
|
|
5
5
|
export * from './density';
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './editing';
|
|
7
7
|
export * from './filter';
|
|
8
8
|
export * from './focus';
|
|
9
9
|
export * from './pagination';
|
|
10
10
|
export * from './preferencesPanel';
|
|
11
11
|
export * from './rows';
|
|
12
|
-
export * from './
|
|
12
|
+
export * from './rowSelection';
|
|
13
13
|
export * from './sorting';
|
|
14
14
|
export * from './dimensions';
|
|
15
15
|
export * from './statePersistence';
|
|
@@ -10,6 +10,9 @@ import { GridCellModes } from '../../../models/gridEditRowModel';
|
|
|
10
10
|
import { isNavigationKey } from '../../../utils/keyboardUtils';
|
|
11
11
|
import { GRID_DETAIL_PANEL_TOGGLE_FIELD } from '../../../constants/gridDetailPanelToggleField';
|
|
12
12
|
import { gridPinnedRowsSelector } from '../rows/gridRowsSelector';
|
|
13
|
+
import { unstable_gridFocusColumnGroupHeaderSelector } from '../focus';
|
|
14
|
+
import { gridColumnGroupsHeaderMaxDepthSelector } from '../columnGrouping/gridColumnGroupsSelector';
|
|
15
|
+
import { useGridSelector } from '../../utils/useGridSelector';
|
|
13
16
|
|
|
14
17
|
function enrichPageRowsWithPinnedRows(apiRef, rows) {
|
|
15
18
|
const pinnedRows = gridPinnedRowsSelector(apiRef) || {};
|
|
@@ -68,6 +71,16 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
68
71
|
const field = apiRef.current.getVisibleColumns()[colIndex].field;
|
|
69
72
|
apiRef.current.setColumnHeaderFocus(field, event);
|
|
70
73
|
}, [apiRef, logger]);
|
|
74
|
+
const goToGroupHeader = React.useCallback((colIndex, depth, event) => {
|
|
75
|
+
logger.debug(`Navigating to header col ${colIndex}`);
|
|
76
|
+
apiRef.current.scrollToIndexes({
|
|
77
|
+
colIndex
|
|
78
|
+
});
|
|
79
|
+
const {
|
|
80
|
+
field
|
|
81
|
+
} = apiRef.current.getVisibleColumns()[colIndex];
|
|
82
|
+
apiRef.current.unstable_setColumnGroupHeaderFocus(field, depth, event);
|
|
83
|
+
}, [apiRef, logger]);
|
|
71
84
|
const getRowIdFromIndex = React.useCallback(rowIndex => {
|
|
72
85
|
return currentPageRows[rowIndex].id;
|
|
73
86
|
}, [currentPageRows]);
|
|
@@ -239,6 +252,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
239
252
|
const lastRowIndexInPage = currentPageRows.length - 1;
|
|
240
253
|
const firstColIndex = 0;
|
|
241
254
|
const lastColIndex = gridVisibleColumnDefinitionsSelector(apiRef).length - 1;
|
|
255
|
+
const columnGroupMaxDepth = gridColumnGroupsHeaderMaxDepthSelector(apiRef);
|
|
242
256
|
let shouldPreventDefault = true;
|
|
243
257
|
|
|
244
258
|
switch (event.key) {
|
|
@@ -269,6 +283,15 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
269
283
|
break;
|
|
270
284
|
}
|
|
271
285
|
|
|
286
|
+
case 'ArrowUp':
|
|
287
|
+
{
|
|
288
|
+
if (columnGroupMaxDepth > 0) {
|
|
289
|
+
goToGroupHeader(colIndexBefore, columnGroupMaxDepth - 1, event);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
|
|
272
295
|
case 'PageDown':
|
|
273
296
|
{
|
|
274
297
|
if (firstRowIndexInPage !== null && lastRowIndexInPage !== null) {
|
|
@@ -314,7 +337,117 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
314
337
|
if (shouldPreventDefault) {
|
|
315
338
|
event.preventDefault();
|
|
316
339
|
}
|
|
317
|
-
}, [apiRef, currentPageRows, goToCell, goToHeader,
|
|
340
|
+
}, [apiRef, currentPageRows.length, goToCell, getRowIdFromIndex, goToHeader, goToGroupHeader]);
|
|
341
|
+
const focusedColumnGroup = useGridSelector(apiRef, unstable_gridFocusColumnGroupHeaderSelector);
|
|
342
|
+
const handleColumnGroupHeaderKeyDown = React.useCallback((params, event) => {
|
|
343
|
+
const dimensions = apiRef.current.getRootDimensions();
|
|
344
|
+
|
|
345
|
+
if (!dimensions) {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (focusedColumnGroup === null) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
const {
|
|
354
|
+
field: currentField,
|
|
355
|
+
depth: currentDepth
|
|
356
|
+
} = focusedColumnGroup;
|
|
357
|
+
const {
|
|
358
|
+
fields,
|
|
359
|
+
depth,
|
|
360
|
+
maxDepth
|
|
361
|
+
} = params;
|
|
362
|
+
const viewportPageSize = apiRef.current.unstable_getViewportPageSize();
|
|
363
|
+
const currentColIndex = apiRef.current.getColumnIndex(currentField);
|
|
364
|
+
const colIndexBefore = currentField ? apiRef.current.getColumnIndex(currentField) : 0;
|
|
365
|
+
const firstRowIndexInPage = 0;
|
|
366
|
+
const lastRowIndexInPage = currentPageRows.length - 1;
|
|
367
|
+
const firstColIndex = 0;
|
|
368
|
+
const lastColIndex = gridVisibleColumnDefinitionsSelector(apiRef).length - 1;
|
|
369
|
+
let shouldPreventDefault = true;
|
|
370
|
+
|
|
371
|
+
switch (event.key) {
|
|
372
|
+
case 'ArrowDown':
|
|
373
|
+
{
|
|
374
|
+
if (depth === maxDepth - 1) {
|
|
375
|
+
goToHeader(currentColIndex, event);
|
|
376
|
+
} else {
|
|
377
|
+
goToGroupHeader(currentColIndex, currentDepth + 1, event);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
break;
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
case 'ArrowUp':
|
|
384
|
+
{
|
|
385
|
+
if (depth > 0) {
|
|
386
|
+
goToGroupHeader(currentColIndex, currentDepth - 1, event);
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
break;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
case 'ArrowRight':
|
|
393
|
+
{
|
|
394
|
+
const remainingRightColumns = fields.length - fields.indexOf(currentField) - 1;
|
|
395
|
+
|
|
396
|
+
if (currentColIndex + remainingRightColumns + 1 <= lastColIndex) {
|
|
397
|
+
goToGroupHeader(currentColIndex + remainingRightColumns + 1, currentDepth, event);
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
break;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
case 'ArrowLeft':
|
|
404
|
+
{
|
|
405
|
+
const remainingLeftColumns = fields.indexOf(currentField);
|
|
406
|
+
|
|
407
|
+
if (currentColIndex - remainingLeftColumns - 1 >= firstColIndex) {
|
|
408
|
+
goToGroupHeader(currentColIndex - remainingLeftColumns - 1, currentDepth, event);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
break;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
case 'PageDown':
|
|
415
|
+
{
|
|
416
|
+
if (firstRowIndexInPage !== null && lastRowIndexInPage !== null) {
|
|
417
|
+
goToCell(colIndexBefore, getRowIdFromIndex(Math.min(firstRowIndexInPage + viewportPageSize, lastRowIndexInPage)));
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
break;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
case 'Home':
|
|
424
|
+
{
|
|
425
|
+
goToGroupHeader(firstColIndex, currentDepth, event);
|
|
426
|
+
break;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
case 'End':
|
|
430
|
+
{
|
|
431
|
+
goToGroupHeader(lastColIndex, currentDepth, event);
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
case ' ':
|
|
436
|
+
{
|
|
437
|
+
// prevent Space event from scrolling
|
|
438
|
+
break;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
default:
|
|
442
|
+
{
|
|
443
|
+
shouldPreventDefault = false;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
if (shouldPreventDefault) {
|
|
448
|
+
event.preventDefault();
|
|
449
|
+
}
|
|
450
|
+
}, [apiRef, focusedColumnGroup, currentPageRows.length, goToHeader, goToGroupHeader, goToCell, getRowIdFromIndex]);
|
|
318
451
|
const handleCellKeyDown = React.useCallback((params, event) => {
|
|
319
452
|
// Ignore portal
|
|
320
453
|
if (!event.currentTarget.contains(event.target)) {
|
|
@@ -330,5 +463,6 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
330
463
|
}, [apiRef]);
|
|
331
464
|
useGridApiEventHandler(apiRef, 'cellNavigationKeyDown', handleCellNavigationKeyDown);
|
|
332
465
|
useGridApiEventHandler(apiRef, 'columnHeaderKeyDown', handleColumnHeaderKeyDown);
|
|
466
|
+
useGridApiEventHandler(apiRef, 'columnGroupHeaderKeyDown', handleColumnGroupHeaderKeyDown);
|
|
333
467
|
useGridApiEventHandler(apiRef, 'cellKeyDown', handleCellKeyDown);
|
|
334
468
|
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { createSelector } from '../../../utils/createSelector';
|
|
2
|
+
import { gridRowsLookupSelector } from '../rows/gridRowsSelector';
|
|
3
|
+
export const gridRowSelectionStateSelector = state => state.rowSelection;
|
|
4
|
+
export const selectedGridRowsCountSelector = createSelector(gridRowSelectionStateSelector, selection => selection.length);
|
|
5
|
+
export const selectedGridRowsSelector = createSelector(gridRowSelectionStateSelector, gridRowsLookupSelector, (selectedRows, rowsLookup) => new Map(selectedRows.map(id => [id, rowsLookup[id]])));
|
|
6
|
+
export const selectedIdsLookupSelector = createSelector(gridRowSelectionStateSelector, selection => selection.reduce((lookup, rowId) => {
|
|
7
|
+
lookup[rowId] = rowId;
|
|
8
|
+
return lookup;
|
|
9
|
+
}, {}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './gridRowSelectionSelector';
|
package/modern/hooks/features/{selection/useGridSelection.js → rowSelection/useGridRowSelection.js}
RENAMED
|
@@ -4,7 +4,7 @@ import { useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
|
|
|
4
4
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
5
5
|
import { useGridLogger } from '../../utils/useGridLogger';
|
|
6
6
|
import { gridRowsLookupSelector } from '../rows/gridRowsSelector';
|
|
7
|
-
import {
|
|
7
|
+
import { gridRowSelectionStateSelector, selectedGridRowsSelector, selectedIdsLookupSelector } from './gridRowSelectionSelector';
|
|
8
8
|
import { gridPaginatedVisibleSortedGridRowIdsSelector } from '../pagination';
|
|
9
9
|
import { gridFocusCellSelector } from '../focus/gridFocusStateSelector';
|
|
10
10
|
import { gridVisibleSortedRowIdsSelector } from '../filter/gridFilterSelector';
|
|
@@ -30,8 +30,8 @@ const getSelectionModelPropValue = (selectionModelProp, prevSelectionModel) => {
|
|
|
30
30
|
return [selectionModelProp];
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
export const
|
|
34
|
-
|
|
33
|
+
export const rowSelectionStateInitializer = (state, props) => _extends({}, state, {
|
|
34
|
+
rowSelection: getSelectionModelPropValue(props.rowSelectionModel) ?? []
|
|
35
35
|
});
|
|
36
36
|
/**
|
|
37
37
|
* @requires useGridRows (state, method) - can be after
|
|
@@ -40,28 +40,28 @@ export const selectionStateInitializer = (state, props) => _extends({}, state, {
|
|
|
40
40
|
* @requires useGridKeyboardNavigation (`cellKeyDown` event must first be consumed by it)
|
|
41
41
|
*/
|
|
42
42
|
|
|
43
|
-
export const
|
|
43
|
+
export const useGridRowSelection = (apiRef, props) => {
|
|
44
44
|
const logger = useGridLogger(apiRef, 'useGridSelection');
|
|
45
|
-
const
|
|
46
|
-
return getSelectionModelPropValue(props.
|
|
47
|
-
}, [apiRef, props.
|
|
45
|
+
const propRowSelectionModel = React.useMemo(() => {
|
|
46
|
+
return getSelectionModelPropValue(props.rowSelectionModel, gridRowSelectionStateSelector(apiRef.current.state));
|
|
47
|
+
}, [apiRef, props.rowSelectionModel]);
|
|
48
48
|
const lastRowToggled = React.useRef(null);
|
|
49
49
|
apiRef.current.unstable_registerControlState({
|
|
50
|
-
stateId: '
|
|
51
|
-
propModel:
|
|
52
|
-
propOnChange: props.
|
|
53
|
-
stateSelector:
|
|
54
|
-
changeEvent: '
|
|
50
|
+
stateId: 'rowSelection',
|
|
51
|
+
propModel: propRowSelectionModel,
|
|
52
|
+
propOnChange: props.onRowSelectionModelChange,
|
|
53
|
+
stateSelector: gridRowSelectionStateSelector,
|
|
54
|
+
changeEvent: 'rowSelectionChange'
|
|
55
55
|
});
|
|
56
56
|
const {
|
|
57
57
|
checkboxSelection,
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
disableMultipleRowSelection,
|
|
59
|
+
disableRowSelectionOnClick,
|
|
60
60
|
pagination,
|
|
61
61
|
paginationMode,
|
|
62
62
|
isRowSelectable: propIsRowSelectable
|
|
63
63
|
} = props;
|
|
64
|
-
const canHaveMultipleSelection = !
|
|
64
|
+
const canHaveMultipleSelection = !disableMultipleRowSelection || checkboxSelection;
|
|
65
65
|
const visibleRows = useGridVisibleRows(apiRef, props);
|
|
66
66
|
const expandMouseRowRangeSelection = React.useCallback(id => {
|
|
67
67
|
let endId = id;
|
|
@@ -94,18 +94,18 @@ export const useGridSelection = (apiRef, props) => {
|
|
|
94
94
|
* API METHODS
|
|
95
95
|
*/
|
|
96
96
|
|
|
97
|
-
const
|
|
98
|
-
const currentModel =
|
|
97
|
+
const setRowSelectionModel = React.useCallback(model => {
|
|
98
|
+
const currentModel = gridRowSelectionStateSelector(apiRef.current.state);
|
|
99
99
|
|
|
100
100
|
if (currentModel !== model) {
|
|
101
101
|
logger.debug(`Setting selection model`);
|
|
102
102
|
apiRef.current.setState(state => _extends({}, state, {
|
|
103
|
-
|
|
103
|
+
rowSelection: model
|
|
104
104
|
}));
|
|
105
105
|
apiRef.current.forceUpdate();
|
|
106
106
|
}
|
|
107
107
|
}, [apiRef, logger]);
|
|
108
|
-
const isRowSelected = React.useCallback(id =>
|
|
108
|
+
const isRowSelected = React.useCallback(id => gridRowSelectionStateSelector(apiRef.current.state).includes(id), [apiRef]);
|
|
109
109
|
const isRowSelectable = React.useCallback(id => {
|
|
110
110
|
if (propIsRowSelectable && !propIsRowSelectable(apiRef.current.getRowParams(id))) {
|
|
111
111
|
return false;
|
|
@@ -129,10 +129,10 @@ export const useGridSelection = (apiRef, props) => {
|
|
|
129
129
|
|
|
130
130
|
if (resetSelection) {
|
|
131
131
|
logger.debug(`Setting selection for row ${id}`);
|
|
132
|
-
apiRef.current.
|
|
132
|
+
apiRef.current.setRowSelectionModel(isSelected ? [id] : []);
|
|
133
133
|
} else {
|
|
134
134
|
logger.debug(`Toggling selection for row ${id}`);
|
|
135
|
-
const selection =
|
|
135
|
+
const selection = gridRowSelectionStateSelector(apiRef.current.state);
|
|
136
136
|
const newSelection = selection.filter(el => el !== id);
|
|
137
137
|
|
|
138
138
|
if (isSelected) {
|
|
@@ -142,7 +142,7 @@ export const useGridSelection = (apiRef, props) => {
|
|
|
142
142
|
const isSelectionValid = newSelection.length < 2 || canHaveMultipleSelection;
|
|
143
143
|
|
|
144
144
|
if (isSelectionValid) {
|
|
145
|
-
apiRef.current.
|
|
145
|
+
apiRef.current.setRowSelectionModel(newSelection);
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
}, [apiRef, logger, canHaveMultipleSelection]);
|
|
@@ -170,7 +170,7 @@ export const useGridSelection = (apiRef, props) => {
|
|
|
170
170
|
const isSelectionValid = newSelection.length < 2 || canHaveMultipleSelection;
|
|
171
171
|
|
|
172
172
|
if (isSelectionValid) {
|
|
173
|
-
apiRef.current.
|
|
173
|
+
apiRef.current.setRowSelectionModel(newSelection);
|
|
174
174
|
}
|
|
175
175
|
}, [apiRef, logger, canHaveMultipleSelection]);
|
|
176
176
|
const selectRowRange = React.useCallback(({
|
|
@@ -194,7 +194,7 @@ export const useGridSelection = (apiRef, props) => {
|
|
|
194
194
|
selectRow,
|
|
195
195
|
selectRows,
|
|
196
196
|
selectRowRange,
|
|
197
|
-
|
|
197
|
+
setRowSelectionModel,
|
|
198
198
|
getSelectedRows,
|
|
199
199
|
isRowSelected,
|
|
200
200
|
isRowSelectable
|
|
@@ -209,7 +209,7 @@ export const useGridSelection = (apiRef, props) => {
|
|
|
209
209
|
return;
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
const currentSelection =
|
|
212
|
+
const currentSelection = gridRowSelectionStateSelector(apiRef.current.state);
|
|
213
213
|
const rowsLookup = gridRowsLookupSelector(apiRef); // We clone the existing object to avoid mutating the same object returned by the selector to others part of the project
|
|
214
214
|
|
|
215
215
|
const selectionLookup = _extends({}, selectedIdsLookupSelector(apiRef));
|
|
@@ -223,7 +223,7 @@ export const useGridSelection = (apiRef, props) => {
|
|
|
223
223
|
});
|
|
224
224
|
|
|
225
225
|
if (hasChanged) {
|
|
226
|
-
apiRef.current.
|
|
226
|
+
apiRef.current.setRowSelectionModel(Object.values(selectionLookup));
|
|
227
227
|
}
|
|
228
228
|
}, [apiRef, props.keepNonExistentRowsSelected]);
|
|
229
229
|
const handleSingleRowSelection = React.useCallback((id, event) => {
|
|
@@ -243,7 +243,7 @@ export const useGridSelection = (apiRef, props) => {
|
|
|
243
243
|
}
|
|
244
244
|
}, [apiRef, canHaveMultipleSelection, checkboxSelection]);
|
|
245
245
|
const handleCellClick = React.useCallback((params, event) => {
|
|
246
|
-
if (
|
|
246
|
+
if (disableRowSelectionOnClick) {
|
|
247
247
|
return;
|
|
248
248
|
}
|
|
249
249
|
|
|
@@ -274,7 +274,7 @@ export const useGridSelection = (apiRef, props) => {
|
|
|
274
274
|
} else {
|
|
275
275
|
handleSingleRowSelection(params.id, event);
|
|
276
276
|
}
|
|
277
|
-
}, [
|
|
277
|
+
}, [disableRowSelectionOnClick, canHaveMultipleSelection, checkboxSelection, apiRef, expandMouseRowRangeSelection, handleSingleRowSelection]);
|
|
278
278
|
const preventSelectionOnShift = React.useCallback((params, event) => {
|
|
279
279
|
if (canHaveMultipleSelection && event.shiftKey) {
|
|
280
280
|
window.getSelection()?.removeAllRanges();
|
|
@@ -373,29 +373,29 @@ export const useGridSelection = (apiRef, props) => {
|
|
|
373
373
|
*/
|
|
374
374
|
|
|
375
375
|
React.useEffect(() => {
|
|
376
|
-
if (
|
|
377
|
-
apiRef.current.
|
|
376
|
+
if (propRowSelectionModel !== undefined) {
|
|
377
|
+
apiRef.current.setRowSelectionModel(propRowSelectionModel);
|
|
378
378
|
}
|
|
379
|
-
}, [apiRef,
|
|
380
|
-
const isStateControlled =
|
|
379
|
+
}, [apiRef, propRowSelectionModel]);
|
|
380
|
+
const isStateControlled = propRowSelectionModel != null;
|
|
381
381
|
React.useEffect(() => {
|
|
382
382
|
if (isStateControlled) {
|
|
383
383
|
return;
|
|
384
384
|
} // props.isRowSelectable changed
|
|
385
385
|
|
|
386
386
|
|
|
387
|
-
const currentSelection =
|
|
387
|
+
const currentSelection = gridRowSelectionStateSelector(apiRef.current.state);
|
|
388
388
|
|
|
389
389
|
if (isRowSelectable) {
|
|
390
390
|
const newSelection = currentSelection.filter(id => isRowSelectable(id));
|
|
391
391
|
|
|
392
392
|
if (newSelection.length < currentSelection.length) {
|
|
393
|
-
apiRef.current.
|
|
393
|
+
apiRef.current.setRowSelectionModel(newSelection);
|
|
394
394
|
}
|
|
395
395
|
}
|
|
396
396
|
}, [apiRef, isRowSelectable, isStateControlled]);
|
|
397
397
|
React.useEffect(() => {
|
|
398
|
-
const currentSelection =
|
|
398
|
+
const currentSelection = gridRowSelectionStateSelector(apiRef.current.state);
|
|
399
399
|
|
|
400
400
|
if (!canHaveMultipleSelection && currentSelection.length > 1) {
|
|
401
401
|
const {
|
|
@@ -419,7 +419,7 @@ export const useGridSelection = (apiRef, props) => {
|
|
|
419
419
|
|
|
420
420
|
return isSelectable && currentPageRowsLookup[id]; // Check if the row is in the current page
|
|
421
421
|
});
|
|
422
|
-
apiRef.current.
|
|
422
|
+
apiRef.current.setRowSelectionModel(firstSelectableRow !== undefined ? [firstSelectableRow] : []);
|
|
423
423
|
}
|
|
424
|
-
}, [apiRef, canHaveMultipleSelection, checkboxSelection,
|
|
424
|
+
}, [apiRef, canHaveMultipleSelection, checkboxSelection, disableMultipleRowSelection, isRowSelectable, pagination, paginationMode]);
|
|
425
425
|
};
|
|
@@ -18,7 +18,7 @@ const useUtilityClasses = ownerState => {
|
|
|
18
18
|
}, [classes]);
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
export const
|
|
21
|
+
export const useGridRowSelectionPreProcessors = (apiRef, props) => {
|
|
22
22
|
const ownerState = {
|
|
23
23
|
classes: props.classes
|
|
24
24
|
};
|
|
@@ -34,7 +34,8 @@ export const getRowIdFromRowModel = (rowModel, getRowId, detailErrorMessage) =>
|
|
|
34
34
|
export const createRowsInternalCache = ({
|
|
35
35
|
rows,
|
|
36
36
|
getRowId,
|
|
37
|
-
loading
|
|
37
|
+
loading,
|
|
38
|
+
rowCount
|
|
38
39
|
}) => {
|
|
39
40
|
const updates = {
|
|
40
41
|
type: 'full',
|
|
@@ -54,6 +55,7 @@ export const createRowsInternalCache = ({
|
|
|
54
55
|
return {
|
|
55
56
|
rowsBeforePartialUpdates: rows,
|
|
56
57
|
loadingPropBeforePartialUpdates: loading,
|
|
58
|
+
rowCountPropBeforePartialUpdates: rowCount,
|
|
57
59
|
updates,
|
|
58
60
|
dataRowIdToIdLookup,
|
|
59
61
|
dataRowIdToModelLookup
|
|
@@ -262,7 +264,8 @@ export const updateCacheWithNewRows = ({
|
|
|
262
264
|
dataRowIdToIdLookup,
|
|
263
265
|
updates: partialUpdates,
|
|
264
266
|
rowsBeforePartialUpdates: previousCache.rowsBeforePartialUpdates,
|
|
265
|
-
loadingPropBeforePartialUpdates: previousCache.loadingPropBeforePartialUpdates
|
|
267
|
+
loadingPropBeforePartialUpdates: previousCache.loadingPropBeforePartialUpdates,
|
|
268
|
+
rowCountPropBeforePartialUpdates: previousCache.rowCountPropBeforePartialUpdates
|
|
266
269
|
};
|
|
267
270
|
};
|
|
268
271
|
export function calculatePinnedRowsHeight(apiRef) {
|