@mui/x-data-grid 5.7.0 → 5.8.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 +74 -0
- package/DataGrid/DataGrid.d.ts +8 -3
- package/DataGrid/DataGrid.js +27 -4
- package/DataGrid/useDataGridComponent.js +2 -4
- package/DataGrid/useDataGridProps.d.ts +2 -1
- package/colDef/gridBooleanColDef.d.ts +1 -1
- package/colDef/gridBooleanOperators.d.ts +1 -1
- package/colDef/gridDateColDef.d.ts +5 -9
- package/colDef/gridDateColDef.js +2 -2
- package/colDef/gridDateOperators.d.ts +1 -1
- package/{models/colDef → colDef}/gridDefaultColumnTypes.d.ts +1 -1
- package/{models/colDef → colDef}/gridDefaultColumnTypes.js +6 -6
- package/colDef/gridNumericColDef.d.ts +1 -1
- package/colDef/gridNumericOperators.d.ts +2 -2
- package/colDef/gridStringColDef.d.ts +1 -1
- package/colDef/gridStringOperators.d.ts +1 -1
- package/colDef/index.d.ts +1 -0
- package/colDef/index.js +2 -1
- package/components/GridRow.js +1 -1
- package/components/cell/GridCell.d.ts +4 -4
- package/components/cell/GridCell.js +2 -2
- package/components/cell/GridEditInputCell.js +2 -2
- package/components/cell/GridEditSingleSelectCell.js +2 -2
- package/components/columnHeaders/GridColumnHeaderFilterIconButton.d.ts +12 -0
- package/components/columnHeaders/{ColumnHeaderFilterIcon.js → GridColumnHeaderFilterIconButton.js} +22 -4
- package/components/columnHeaders/GridColumnHeaderItem.js +5 -5
- package/components/columnHeaders/index.d.ts +1 -0
- package/components/columnHeaders/index.js +1 -0
- package/components/columnSelection/GridCellCheckboxRenderer.js +2 -2
- package/components/columnSelection/GridHeaderCheckbox.d.ts +1 -1
- package/components/containers/GridRoot.js +29 -17
- package/components/menu/columnMenu/GridColumnMenu.js +1 -1
- package/components/panel/GridPanel.d.ts +2 -2
- package/components/panel/GridPreferencesPanel.js +1 -1
- package/constants/defaultGridSlotsComponents.js +2 -1
- package/constants/gridClasses.d.ts +15 -3
- package/hooks/core/index.d.ts +1 -1
- package/hooks/core/{preProcessing/gridPreProcessingApi.d.ts → pipeProcessing/gridPipeProcessingApi.d.ts} +19 -18
- package/hooks/core/{preProcessing/gridPreProcessingApi.js → pipeProcessing/gridPipeProcessingApi.js} +0 -0
- package/hooks/core/pipeProcessing/index.d.ts +3 -0
- package/hooks/core/pipeProcessing/index.js +3 -0
- package/hooks/core/pipeProcessing/useGridPipeProcessing.d.ts +27 -0
- package/hooks/core/pipeProcessing/useGridPipeProcessing.js +74 -0
- package/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.d.ts +7 -0
- package/hooks/core/{preProcessing/useGridRegisterPreProcessor.js → pipeProcessing/useGridRegisterPipeProcessor.js} +2 -2
- package/hooks/core/strategyProcessing/useGridStrategyProcessing.d.ts +27 -16
- package/hooks/core/strategyProcessing/useGridStrategyProcessing.js +26 -15
- package/hooks/core/useGridInitialization.js +2 -2
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +1 -1
- package/hooks/features/columns/gridColumnsSelector.d.ts +6 -6
- package/hooks/features/columns/gridColumnsUtils.d.ts +3 -3
- package/hooks/features/columns/gridColumnsUtils.js +49 -17
- package/hooks/features/columns/useGridColumns.js +36 -27
- package/hooks/features/dimensions/gridDimensionsApi.d.ts +5 -0
- package/hooks/features/dimensions/useGridDimensions.js +2 -1
- package/hooks/features/editRows/useGridCellEditing.new.d.ts +1 -1
- package/hooks/features/editRows/useGridCellEditing.new.js +22 -7
- package/hooks/features/editRows/useGridRowEditing.new.d.ts +1 -1
- package/hooks/features/editRows/useGridRowEditing.new.js +22 -7
- package/hooks/features/events/useGridEvents.d.ts +1 -1
- package/hooks/features/events/useGridEvents.js +2 -0
- package/hooks/features/filter/gridFilterSelector.d.ts +3 -9
- package/hooks/features/filter/useGridFilter.js +4 -4
- package/hooks/features/{keyboard → keyboardNavigation}/useGridKeyboardNavigation.d.ts +2 -5
- package/hooks/features/{keyboard → keyboardNavigation}/useGridKeyboardNavigation.js +27 -6
- package/hooks/features/pagination/gridPaginationSelector.d.ts +1 -3
- package/hooks/features/pagination/useGridPage.js +9 -4
- package/hooks/features/pagination/useGridPageSize.js +3 -3
- package/hooks/features/preferencesPanel/useGridPreferencesPanel.js +18 -5
- package/hooks/features/rows/gridRowsSelector.d.ts +1 -1
- package/hooks/features/rows/gridRowsUtils.d.ts +8 -0
- package/hooks/features/rows/gridRowsUtils.js +11 -0
- package/hooks/features/rows/index.d.ts +1 -0
- package/hooks/features/rows/index.js +1 -1
- package/hooks/features/rows/useGridRows.js +3 -3
- package/hooks/features/rows/useGridRowsMeta.js +3 -3
- package/hooks/features/scroll/useGridScroll.js +4 -13
- package/hooks/features/selection/gridSelectionSelector.d.ts +1 -3
- package/hooks/features/selection/useGridSelection.d.ts +4 -2
- package/hooks/features/selection/useGridSelection.js +72 -25
- package/hooks/features/selection/useGridSelectionPreProcessors.js +2 -2
- package/hooks/features/sorting/gridSortingSelector.d.ts +1 -3
- package/hooks/features/sorting/gridSortingUtils.d.ts +1 -2
- package/hooks/features/sorting/useGridSorting.js +3 -3
- package/hooks/features/statePersistence/useGridStatePersistence.js +2 -2
- package/hooks/utils/useGridRootProps.d.ts +1 -1
- package/hooks/utils/useGridVisibleRows.d.ts +2 -2
- package/index.js +1 -1
- package/internals/index.d.ts +3 -6
- package/internals/index.js +2 -3
- package/legacy/DataGrid/DataGrid.js +27 -4
- package/legacy/DataGrid/useDataGridComponent.js +2 -4
- package/legacy/colDef/gridDateColDef.js +2 -2
- package/legacy/{models/colDef → colDef}/gridDefaultColumnTypes.js +6 -6
- package/legacy/colDef/index.js +2 -1
- package/legacy/components/GridRow.js +1 -1
- package/legacy/components/cell/GridCell.js +2 -2
- package/legacy/components/cell/GridEditInputCell.js +2 -2
- package/legacy/components/cell/GridEditSingleSelectCell.js +2 -2
- package/legacy/components/columnHeaders/{ColumnHeaderFilterIcon.js → GridColumnHeaderFilterIconButton.js} +22 -4
- package/legacy/components/columnHeaders/GridColumnHeaderItem.js +5 -5
- package/legacy/components/columnHeaders/index.js +1 -0
- package/legacy/components/columnSelection/GridCellCheckboxRenderer.js +2 -2
- package/legacy/components/containers/GridRoot.js +34 -17
- package/legacy/components/menu/columnMenu/GridColumnMenu.js +1 -1
- package/legacy/components/panel/GridPreferencesPanel.js +1 -1
- package/legacy/constants/defaultGridSlotsComponents.js +2 -1
- package/legacy/hooks/core/{preProcessing/gridPreProcessingApi.js → pipeProcessing/gridPipeProcessingApi.js} +0 -0
- package/legacy/hooks/core/pipeProcessing/index.js +3 -0
- package/legacy/hooks/core/pipeProcessing/useGridPipeProcessing.js +83 -0
- package/legacy/hooks/core/{preProcessing/useGridRegisterPreProcessor.js → pipeProcessing/useGridRegisterPipeProcessor.js} +2 -2
- package/legacy/hooks/core/strategyProcessing/useGridStrategyProcessing.js +26 -15
- package/legacy/hooks/core/useGridInitialization.js +2 -2
- package/legacy/hooks/features/columnHeaders/useGridColumnHeaders.js +1 -1
- package/legacy/hooks/features/columns/gridColumnsUtils.js +49 -18
- package/legacy/hooks/features/columns/useGridColumns.js +36 -27
- package/legacy/hooks/features/dimensions/useGridDimensions.js +2 -1
- package/legacy/hooks/features/editRows/useGridCellEditing.new.js +22 -7
- package/legacy/hooks/features/editRows/useGridRowEditing.new.js +22 -7
- package/legacy/hooks/features/events/useGridEvents.js +2 -0
- package/legacy/hooks/features/filter/useGridFilter.js +4 -4
- package/legacy/hooks/features/{keyboard → keyboardNavigation}/useGridKeyboardNavigation.js +27 -6
- package/legacy/hooks/features/pagination/useGridPage.js +11 -4
- package/legacy/hooks/features/pagination/useGridPageSize.js +3 -3
- package/legacy/hooks/features/preferencesPanel/useGridPreferencesPanel.js +18 -5
- package/legacy/hooks/features/rows/gridRowsUtils.js +13 -0
- package/legacy/hooks/features/rows/index.js +1 -1
- package/legacy/hooks/features/rows/useGridRows.js +5 -5
- package/legacy/hooks/features/rows/useGridRowsMeta.js +3 -3
- package/legacy/hooks/features/scroll/useGridScroll.js +4 -13
- package/legacy/hooks/features/selection/useGridSelection.js +74 -25
- package/legacy/hooks/features/selection/useGridSelectionPreProcessors.js +2 -2
- package/legacy/hooks/features/sorting/useGridSorting.js +3 -3
- package/legacy/hooks/features/statePersistence/useGridStatePersistence.js +2 -2
- package/legacy/index.js +1 -1
- package/legacy/internals/index.js +2 -3
- package/legacy/locales/daDK.js +36 -32
- package/legacy/models/colDef/index.js +1 -2
- package/legacy/models/events/gridEvents.js +4 -2
- package/legacy/models/gridRows.js +1 -33
- package/legacy/models/index.js +2 -2
- package/{modern/hooks/core/preProcessing/gridPreProcessingApi.js → legacy/models/params/gridPreferencePanelParams.js} +0 -0
- package/legacy/models/params/index.js +2 -1
- package/locales/daDK.js +32 -32
- package/models/api/gridApiCommon.d.ts +2 -2
- package/models/api/gridEditingApi.d.ts +2 -2
- package/models/api/gridParamsApi.d.ts +5 -5
- package/models/api/gridRowApi.d.ts +2 -2
- package/models/colDef/gridColDef.d.ts +33 -28
- package/models/colDef/index.d.ts +0 -1
- package/models/colDef/index.js +1 -2
- package/models/events/gridEventLookup.d.ts +12 -6
- package/models/events/gridEvents.d.ts +11 -5
- package/models/events/gridEvents.js +4 -2
- package/models/gridCell.d.ts +1 -0
- package/models/gridEditRowModel.d.ts +1 -1
- package/models/gridFilterOperator.d.ts +3 -2
- package/models/gridRows.d.ts +10 -18
- package/models/gridRows.js +1 -31
- package/models/gridSlotsComponent.d.ts +5 -0
- package/models/gridSlotsComponentsProps.d.ts +1 -0
- package/models/gridSortModel.d.ts +3 -4
- package/models/index.d.ts +1 -1
- package/models/index.js +2 -2
- package/models/params/gridCellParams.d.ts +14 -14
- package/models/params/gridColumnHeaderParams.d.ts +3 -2
- package/models/params/gridEditCellParams.d.ts +2 -3
- package/models/params/gridPreferencePanelParams.d.ts +3 -0
- package/models/params/gridPreferencePanelParams.js +1 -0
- package/models/params/gridRowParams.d.ts +7 -8
- package/models/params/gridValueOptionsParams.d.ts +3 -3
- package/models/params/index.d.ts +1 -0
- package/models/params/index.js +2 -1
- package/models/props/DataGridProps.d.ts +36 -16
- package/modern/DataGrid/DataGrid.js +27 -4
- package/modern/DataGrid/useDataGridComponent.js +2 -4
- package/modern/colDef/gridDateColDef.js +2 -2
- package/modern/{models/colDef → colDef}/gridDefaultColumnTypes.js +6 -6
- package/modern/colDef/index.js +2 -1
- package/modern/components/GridRow.js +1 -1
- package/modern/components/cell/GridCell.js +2 -2
- package/modern/components/cell/GridEditInputCell.js +2 -2
- package/modern/components/cell/GridEditSingleSelectCell.js +2 -2
- package/modern/components/columnHeaders/{ColumnHeaderFilterIcon.js → GridColumnHeaderFilterIconButton.js} +22 -4
- package/modern/components/columnHeaders/GridColumnHeaderItem.js +3 -3
- package/modern/components/columnHeaders/index.js +1 -0
- package/modern/components/columnSelection/GridCellCheckboxRenderer.js +2 -2
- package/modern/components/containers/GridRoot.js +29 -17
- package/modern/components/menu/columnMenu/GridColumnMenu.js +1 -1
- package/modern/components/panel/GridPreferencesPanel.js +1 -1
- package/modern/constants/defaultGridSlotsComponents.js +2 -1
- package/modern/hooks/core/pipeProcessing/gridPipeProcessingApi.js +1 -0
- package/modern/hooks/core/pipeProcessing/index.js +3 -0
- package/modern/hooks/core/pipeProcessing/useGridPipeProcessing.js +74 -0
- package/modern/hooks/core/{preProcessing/useGridRegisterPreProcessor.js → pipeProcessing/useGridRegisterPipeProcessor.js} +2 -2
- package/modern/hooks/core/strategyProcessing/useGridStrategyProcessing.js +26 -15
- package/modern/hooks/core/useGridInitialization.js +2 -2
- package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +1 -1
- package/modern/hooks/features/columns/gridColumnsUtils.js +49 -17
- package/modern/hooks/features/columns/useGridColumns.js +36 -27
- package/modern/hooks/features/dimensions/useGridDimensions.js +2 -1
- package/modern/hooks/features/editRows/useGridCellEditing.new.js +22 -7
- package/modern/hooks/features/editRows/useGridRowEditing.new.js +22 -7
- package/modern/hooks/features/events/useGridEvents.js +2 -0
- package/modern/hooks/features/filter/useGridFilter.js +4 -4
- package/modern/hooks/features/{keyboard → keyboardNavigation}/useGridKeyboardNavigation.js +27 -6
- package/modern/hooks/features/pagination/useGridPage.js +9 -4
- package/modern/hooks/features/pagination/useGridPageSize.js +3 -3
- package/modern/hooks/features/preferencesPanel/useGridPreferencesPanel.js +18 -5
- package/modern/hooks/features/rows/gridRowsUtils.js +11 -0
- package/modern/hooks/features/rows/index.js +1 -1
- package/modern/hooks/features/rows/useGridRows.js +1 -1
- package/modern/hooks/features/rows/useGridRowsMeta.js +3 -3
- package/modern/hooks/features/scroll/useGridScroll.js +4 -9
- package/modern/hooks/features/selection/useGridSelection.js +72 -25
- package/modern/hooks/features/selection/useGridSelectionPreProcessors.js +2 -2
- package/modern/hooks/features/sorting/useGridSorting.js +3 -3
- package/modern/hooks/features/statePersistence/useGridStatePersistence.js +2 -2
- package/modern/index.js +1 -1
- package/modern/internals/index.js +2 -3
- package/modern/locales/daDK.js +32 -32
- package/modern/models/colDef/index.js +1 -2
- package/modern/models/events/gridEvents.js +4 -2
- package/modern/models/gridRows.js +1 -31
- package/modern/models/index.js +2 -2
- package/modern/models/params/gridPreferencePanelParams.js +1 -0
- package/modern/models/params/index.js +2 -1
- package/node/DataGrid/DataGrid.js +27 -4
- package/node/DataGrid/useDataGridComponent.js +2 -5
- package/node/colDef/gridDateColDef.js +2 -2
- package/node/{models/colDef → colDef}/gridDefaultColumnTypes.js +6 -6
- package/node/colDef/index.js +13 -0
- package/node/components/GridRow.js +1 -1
- package/node/components/cell/GridCell.js +2 -2
- package/node/components/cell/GridEditInputCell.js +2 -2
- package/node/components/cell/GridEditSingleSelectCell.js +2 -2
- package/node/components/columnHeaders/{ColumnHeaderFilterIcon.js → GridColumnHeaderFilterIconButton.js} +23 -5
- package/node/components/columnHeaders/GridColumnHeaderItem.js +5 -6
- package/node/components/columnHeaders/index.js +13 -0
- package/node/components/columnSelection/GridCellCheckboxRenderer.js +2 -2
- package/node/components/containers/GridRoot.js +28 -17
- package/node/components/menu/columnMenu/GridColumnMenu.js +1 -1
- package/node/components/panel/GridPreferencesPanel.js +1 -1
- package/node/constants/defaultGridSlotsComponents.js +1 -0
- package/node/hooks/core/{preProcessing/gridPreProcessingApi.js → pipeProcessing/gridPipeProcessingApi.js} +0 -0
- package/node/hooks/core/pipeProcessing/index.js +44 -0
- package/node/hooks/core/pipeProcessing/useGridPipeProcessing.js +93 -0
- package/node/hooks/core/{preProcessing/useGridRegisterPreProcessor.js → pipeProcessing/useGridRegisterPipeProcessor.js} +4 -4
- package/node/hooks/core/strategyProcessing/useGridStrategyProcessing.js +26 -15
- package/node/hooks/core/useGridInitialization.js +2 -2
- package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +1 -1
- package/node/hooks/features/columns/gridColumnsUtils.js +54 -21
- package/node/hooks/features/columns/useGridColumns.js +36 -27
- package/node/hooks/features/dimensions/useGridDimensions.js +2 -1
- package/node/hooks/features/editRows/useGridCellEditing.new.js +24 -7
- package/node/hooks/features/editRows/useGridRowEditing.new.js +24 -7
- package/node/hooks/features/events/useGridEvents.js +2 -0
- package/node/hooks/features/filter/useGridFilter.js +4 -4
- package/node/hooks/features/{keyboard → keyboardNavigation}/useGridKeyboardNavigation.js +29 -6
- package/node/hooks/features/pagination/useGridPage.js +8 -3
- package/node/hooks/features/pagination/useGridPageSize.js +3 -3
- package/node/hooks/features/preferencesPanel/useGridPreferencesPanel.js +20 -5
- package/node/hooks/features/rows/gridRowsUtils.js +18 -0
- package/node/hooks/features/rows/index.js +15 -1
- package/node/hooks/features/rows/useGridRows.js +5 -5
- package/node/hooks/features/rows/useGridRowsMeta.js +3 -3
- package/node/hooks/features/scroll/useGridScroll.js +3 -13
- package/node/hooks/features/selection/useGridSelection.js +71 -24
- package/node/hooks/features/selection/useGridSelectionPreProcessors.js +2 -2
- package/node/hooks/features/sorting/useGridSorting.js +3 -3
- package/node/hooks/features/statePersistence/useGridStatePersistence.js +2 -2
- package/node/index.js +1 -1
- package/node/internals/index.js +4 -12
- package/node/locales/daDK.js +32 -32
- package/node/models/colDef/index.js +0 -13
- package/node/models/events/gridEvents.js +4 -2
- package/node/models/gridRows.js +1 -34
- package/node/models/index.js +13 -13
- package/node/models/params/gridPreferencePanelParams.js +5 -0
- package/node/models/params/index.js +13 -0
- package/package.json +1 -1
- package/components/columnHeaders/ColumnHeaderFilterIcon.d.ts +0 -5
- package/hooks/core/preProcessing/index.d.ts +0 -3
- package/hooks/core/preProcessing/index.js +0 -3
- package/hooks/core/preProcessing/useGridPreProcessing.d.ts +0 -6
- package/hooks/core/preProcessing/useGridPreProcessing.js +0 -53
- package/hooks/core/preProcessing/useGridRegisterPreProcessor.d.ts +0 -7
- package/hooks/features/keyboard/useGridKeyboard.d.ts +0 -10
- package/hooks/features/keyboard/useGridKeyboard.js +0 -70
- package/legacy/hooks/core/preProcessing/index.js +0 -3
- package/legacy/hooks/core/preProcessing/useGridPreProcessing.js +0 -62
- package/legacy/hooks/features/keyboard/useGridKeyboard.js +0 -70
- package/modern/hooks/core/preProcessing/index.js +0 -3
- package/modern/hooks/core/preProcessing/useGridPreProcessing.js +0 -53
- package/modern/hooks/features/keyboard/useGridKeyboard.js +0 -70
- package/node/hooks/core/preProcessing/index.js +0 -44
- package/node/hooks/core/preProcessing/useGridPreProcessing.js +0 -72
- package/node/hooks/features/keyboard/useGridKeyboard.js +0 -91
|
@@ -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 {
|
|
8
|
+
import { useGridRegisterPipeProcessor } 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";
|
|
@@ -14,7 +14,7 @@ export const columnsStateInitializer = (state, props, apiRef) => {
|
|
|
14
14
|
const columnsTypes = computeColumnTypes(props.columnTypes);
|
|
15
15
|
const columnsState = createColumnsState({
|
|
16
16
|
apiRef,
|
|
17
|
-
columnsTypes,
|
|
17
|
+
columnTypes: columnsTypes,
|
|
18
18
|
columnsToUpsert: props.columns,
|
|
19
19
|
initialState: props.initialState?.columns,
|
|
20
20
|
shouldRegenColumnVisibilityModelFromColumns: !isUsingColumnVisibilityModel,
|
|
@@ -33,13 +33,15 @@ export const columnsStateInitializer = (state, props, apiRef) => {
|
|
|
33
33
|
|
|
34
34
|
export function useGridColumns(apiRef, props) {
|
|
35
35
|
const logger = useGridLogger(apiRef, 'useGridColumns');
|
|
36
|
-
const
|
|
36
|
+
const columnTypes = React.useMemo(() => computeColumnTypes(props.columnTypes), [props.columnTypes]);
|
|
37
|
+
const previousColumnsProp = React.useRef(props.columns);
|
|
38
|
+
const previousColumnTypesProp = React.useRef(columnTypes);
|
|
37
39
|
/**
|
|
38
40
|
* If `initialState.columns.columnVisibilityModel` or `columnVisibilityModel` was defined during the 1st render, we are directly updating the model
|
|
39
41
|
* If not, we keep the old behavior and update the `GridColDef.hide` option (which will update the state model through the `GridColDef.hide` => `columnVisibilityModel` sync in `createColumnsState`
|
|
40
42
|
*/
|
|
41
43
|
|
|
42
|
-
const isUsingColumnVisibilityModel = React.useRef(!!props.columnVisibilityModel || !!props.initialState?.columns?.columnVisibilityModel)
|
|
44
|
+
const isUsingColumnVisibilityModel = React.useRef(!!props.columnVisibilityModel || !!props.initialState?.columns?.columnVisibilityModel);
|
|
43
45
|
apiRef.current.unstable_updateControlState({
|
|
44
46
|
stateId: 'visibleColumns',
|
|
45
47
|
propModel: props.columnVisibilityModel,
|
|
@@ -76,7 +78,7 @@ export function useGridColumns(apiRef, props) {
|
|
|
76
78
|
apiRef.current.setState(state => _extends({}, state, {
|
|
77
79
|
columns: createColumnsState({
|
|
78
80
|
apiRef,
|
|
79
|
-
|
|
81
|
+
columnTypes,
|
|
80
82
|
columnsToUpsert: [],
|
|
81
83
|
initialState: undefined,
|
|
82
84
|
shouldRegenColumnVisibilityModelFromColumns: false,
|
|
@@ -86,24 +88,24 @@ export function useGridColumns(apiRef, props) {
|
|
|
86
88
|
}));
|
|
87
89
|
apiRef.current.forceUpdate();
|
|
88
90
|
}
|
|
89
|
-
}, [apiRef,
|
|
91
|
+
}, [apiRef, columnTypes]);
|
|
90
92
|
const updateColumns = React.useCallback(columns => {
|
|
91
93
|
const columnsState = createColumnsState({
|
|
92
94
|
apiRef,
|
|
93
|
-
|
|
95
|
+
columnTypes,
|
|
94
96
|
columnsToUpsert: columns,
|
|
95
97
|
initialState: undefined,
|
|
96
98
|
shouldRegenColumnVisibilityModelFromColumns: true,
|
|
97
99
|
keepOnlyColumnsToUpsert: false
|
|
98
100
|
});
|
|
99
101
|
setGridColumnsState(columnsState);
|
|
100
|
-
}, [apiRef, setGridColumnsState,
|
|
102
|
+
}, [apiRef, setGridColumnsState, columnTypes]);
|
|
101
103
|
const updateColumn = React.useCallback(column => apiRef.current.updateColumns([column]), [apiRef]);
|
|
102
104
|
const setColumnVisibility = React.useCallback((field, isVisible) => {
|
|
103
105
|
// We keep updating the `hide` option of `GridColDef` when not controlling the model to avoid any breaking change.
|
|
104
106
|
// `updateColumns` take care of updating the model itself if needs be.
|
|
105
107
|
// TODO v6: stop using the `hide` field even when the model is not defined
|
|
106
|
-
if (isUsingColumnVisibilityModel) {
|
|
108
|
+
if (isUsingColumnVisibilityModel.current) {
|
|
107
109
|
const columnVisibilityModel = gridColumnVisibilityModelSelector(apiRef);
|
|
108
110
|
const isCurrentlyVisible = columnVisibilityModel[field] ?? true;
|
|
109
111
|
|
|
@@ -129,7 +131,7 @@ export function useGridColumns(apiRef, props) {
|
|
|
129
131
|
};
|
|
130
132
|
apiRef.current.publishEvent(GridEvents.columnVisibilityChange, params);
|
|
131
133
|
}
|
|
132
|
-
}, [apiRef
|
|
134
|
+
}, [apiRef]);
|
|
133
135
|
const setColumnIndex = React.useCallback((field, targetIndexPosition) => {
|
|
134
136
|
const allColumns = gridColumnFieldsSelector(apiRef);
|
|
135
137
|
const oldIndexPosition = allColumns.findIndex(col => col === field);
|
|
@@ -190,7 +192,7 @@ export function useGridColumns(apiRef, props) {
|
|
|
190
192
|
const stateExportPreProcessing = React.useCallback(prevState => {
|
|
191
193
|
const columnsStateToExport = {};
|
|
192
194
|
|
|
193
|
-
if (isUsingColumnVisibilityModel) {
|
|
195
|
+
if (isUsingColumnVisibilityModel.current) {
|
|
194
196
|
const columnVisibilityModelToExport = gridColumnVisibilityModelSelector(apiRef);
|
|
195
197
|
const hasHiddenColumns = Object.values(columnVisibilityModelToExport).some(value => value === false);
|
|
196
198
|
|
|
@@ -219,9 +221,9 @@ export function useGridColumns(apiRef, props) {
|
|
|
219
221
|
return _extends({}, prevState, {
|
|
220
222
|
columns: columnsStateToExport
|
|
221
223
|
});
|
|
222
|
-
}, [apiRef
|
|
224
|
+
}, [apiRef]);
|
|
223
225
|
const stateRestorePreProcessing = React.useCallback((params, context) => {
|
|
224
|
-
const columnVisibilityModelToImport = isUsingColumnVisibilityModel ? context.stateToRestore.columns?.columnVisibilityModel : undefined;
|
|
226
|
+
const columnVisibilityModelToImport = isUsingColumnVisibilityModel.current ? context.stateToRestore.columns?.columnVisibilityModel : undefined;
|
|
225
227
|
const initialState = context.stateToRestore.columns;
|
|
226
228
|
|
|
227
229
|
if (columnVisibilityModelToImport == null && initialState == null) {
|
|
@@ -230,10 +232,10 @@ export function useGridColumns(apiRef, props) {
|
|
|
230
232
|
|
|
231
233
|
const columnsState = createColumnsState({
|
|
232
234
|
apiRef,
|
|
233
|
-
|
|
235
|
+
columnTypes,
|
|
234
236
|
columnsToUpsert: [],
|
|
235
237
|
initialState,
|
|
236
|
-
shouldRegenColumnVisibilityModelFromColumns: !isUsingColumnVisibilityModel,
|
|
238
|
+
shouldRegenColumnVisibilityModelFromColumns: !isUsingColumnVisibilityModel.current,
|
|
237
239
|
currentColumnVisibilityModel: columnVisibilityModelToImport,
|
|
238
240
|
keepOnlyColumnsToUpsert: false
|
|
239
241
|
});
|
|
@@ -244,7 +246,7 @@ export function useGridColumns(apiRef, props) {
|
|
|
244
246
|
}
|
|
245
247
|
|
|
246
248
|
return params;
|
|
247
|
-
}, [apiRef,
|
|
249
|
+
}, [apiRef, columnTypes]);
|
|
248
250
|
const preferencePanelPreProcessing = React.useCallback((initialValue, value) => {
|
|
249
251
|
if (value === GridPreferencePanelsValue.columns) {
|
|
250
252
|
const ColumnsPanel = props.components.ColumnsPanel;
|
|
@@ -253,14 +255,14 @@ export function useGridColumns(apiRef, props) {
|
|
|
253
255
|
|
|
254
256
|
return initialValue;
|
|
255
257
|
}, [props.components.ColumnsPanel, props.componentsProps?.columnsPanel]);
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
258
|
+
useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
|
|
259
|
+
useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
|
|
260
|
+
useGridRegisterPipeProcessor(apiRef, 'preferencePanel', preferencePanelPreProcessing);
|
|
259
261
|
/**
|
|
260
262
|
* EVENTS
|
|
261
263
|
*/
|
|
262
264
|
|
|
263
|
-
const
|
|
265
|
+
const handlepipeProcessorRegister = React.useCallback(name => {
|
|
264
266
|
if (name !== 'hydrateColumns') {
|
|
265
267
|
return;
|
|
266
268
|
}
|
|
@@ -268,14 +270,14 @@ export function useGridColumns(apiRef, props) {
|
|
|
268
270
|
logger.info(`Columns pre-processing have changed, regenerating the columns`);
|
|
269
271
|
const columnsState = createColumnsState({
|
|
270
272
|
apiRef,
|
|
271
|
-
|
|
273
|
+
columnTypes,
|
|
272
274
|
columnsToUpsert: [],
|
|
273
275
|
initialState: undefined,
|
|
274
|
-
shouldRegenColumnVisibilityModelFromColumns: !isUsingColumnVisibilityModel,
|
|
276
|
+
shouldRegenColumnVisibilityModelFromColumns: !isUsingColumnVisibilityModel.current,
|
|
275
277
|
keepOnlyColumnsToUpsert: false
|
|
276
278
|
});
|
|
277
279
|
setGridColumnsState(columnsState);
|
|
278
|
-
}, [apiRef, logger, setGridColumnsState,
|
|
280
|
+
}, [apiRef, logger, setGridColumnsState, columnTypes]);
|
|
279
281
|
const prevInnerWidth = React.useRef(null);
|
|
280
282
|
|
|
281
283
|
const handleGridSizeChange = viewportInnerSize => {
|
|
@@ -285,7 +287,7 @@ export function useGridColumns(apiRef, props) {
|
|
|
285
287
|
}
|
|
286
288
|
};
|
|
287
289
|
|
|
288
|
-
useGridApiEventHandler(apiRef, GridEvents.
|
|
290
|
+
useGridApiEventHandler(apiRef, GridEvents.pipeProcessorRegister, handlepipeProcessorRegister);
|
|
289
291
|
useGridApiEventHandler(apiRef, GridEvents.viewportInnerSizeChange, handleGridSizeChange);
|
|
290
292
|
useGridApiOptionHandler(apiRef, GridEvents.columnVisibilityChange, props.onColumnVisibilityChange);
|
|
291
293
|
/**
|
|
@@ -302,17 +304,24 @@ export function useGridColumns(apiRef, props) {
|
|
|
302
304
|
}
|
|
303
305
|
|
|
304
306
|
logger.info(`GridColumns have changed, new length ${props.columns.length}`);
|
|
307
|
+
|
|
308
|
+
if (previousColumnsProp.current === props.columns && previousColumnTypesProp.current === columnTypes) {
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
|
|
305
312
|
const columnsState = createColumnsState({
|
|
306
313
|
apiRef,
|
|
307
|
-
|
|
314
|
+
columnTypes,
|
|
308
315
|
initialState: undefined,
|
|
309
316
|
// If the user provides a model, we don't want to set it in the state here because it has it's dedicated `useEffect` which calls `setColumnVisibilityModel`
|
|
310
|
-
shouldRegenColumnVisibilityModelFromColumns: !isUsingColumnVisibilityModel,
|
|
317
|
+
shouldRegenColumnVisibilityModelFromColumns: !isUsingColumnVisibilityModel.current,
|
|
311
318
|
columnsToUpsert: props.columns,
|
|
312
319
|
keepOnlyColumnsToUpsert: true
|
|
313
320
|
});
|
|
321
|
+
previousColumnsProp.current = props.columns;
|
|
322
|
+
previousColumnTypesProp.current = columnTypes;
|
|
314
323
|
setGridColumnsState(columnsState);
|
|
315
|
-
}, [logger, apiRef, setGridColumnsState, props.columns,
|
|
324
|
+
}, [logger, apiRef, setGridColumnsState, props.columns, columnTypes]);
|
|
316
325
|
React.useEffect(() => {
|
|
317
326
|
if (props.columnVisibilityModel !== undefined) {
|
|
318
327
|
apiRef.current.setColumnVisibilityModel(props.columnVisibilityModel);
|
|
@@ -132,7 +132,8 @@ export function useGridDimensions(apiRef, props) {
|
|
|
132
132
|
const dimensionsApi = {
|
|
133
133
|
resize,
|
|
134
134
|
getRootDimensions,
|
|
135
|
-
unstable_getViewportPageSize: getViewportPageSize
|
|
135
|
+
unstable_getViewportPageSize: getViewportPageSize,
|
|
136
|
+
unstable_updateGridDimensionsRef: updateGridDimensionsRef
|
|
136
137
|
};
|
|
137
138
|
useGridApiMethod(apiRef, dimensionsApi, 'GridDimensionsApi');
|
|
138
139
|
const debounceResize = React.useMemo(() => debounce(resize, 60), [resize]);
|
|
@@ -6,10 +6,13 @@ import { GridEditModes, GridCellModes } from '../../../models/gridEditRowModel';
|
|
|
6
6
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
7
7
|
import { gridEditRowsStateSelector } from './gridEditRowsSelector';
|
|
8
8
|
import { isPrintableKey } from '../../../utils/keyboardUtils';
|
|
9
|
+
import { buildWarning } from '../../../utils/warning';
|
|
9
10
|
import { GridCellEditStartReasons, GridCellEditStopReasons } from '../../../models/params/gridEditCellParams';
|
|
11
|
+
const missingOnProcessRowUpdateErrorWarning = buildWarning(['MUI: A call to `processRowUpdate` threw an error which was not handled because `onProcessRowUpdateError` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError` prop, e.g. `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see http://mui.com/components/data-grid/editing/#persistence.'], 'error');
|
|
10
12
|
export const useGridCellEditing = (apiRef, props) => {
|
|
11
13
|
const {
|
|
12
|
-
processRowUpdate
|
|
14
|
+
processRowUpdate,
|
|
15
|
+
onProcessRowUpdateError
|
|
13
16
|
} = props;
|
|
14
17
|
|
|
15
18
|
const runIfEditModeIsCell = callback => (...args) => {
|
|
@@ -240,17 +243,29 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
240
243
|
});
|
|
241
244
|
|
|
242
245
|
if (processRowUpdate) {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
246
|
+
const handleError = errorThrown => {
|
|
247
|
+
if (onProcessRowUpdateError) {
|
|
248
|
+
onProcessRowUpdateError(errorThrown);
|
|
249
|
+
} else {
|
|
250
|
+
missingOnProcessRowUpdateErrorWarning();
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
try {
|
|
255
|
+
Promise.resolve(processRowUpdate(rowUpdate, row)).then(finalRowUpdate => {
|
|
256
|
+
apiRef.current.updateRows([finalRowUpdate]);
|
|
257
|
+
updateFocusedCellIfNeeded();
|
|
258
|
+
updateOrDeleteFieldState(id, field, null);
|
|
259
|
+
}).catch(handleError);
|
|
260
|
+
} catch (errorThrown) {
|
|
261
|
+
handleError(errorThrown);
|
|
262
|
+
}
|
|
248
263
|
} else {
|
|
249
264
|
apiRef.current.updateRows([rowUpdate]);
|
|
250
265
|
updateFocusedCellIfNeeded();
|
|
251
266
|
updateOrDeleteFieldState(id, field, null);
|
|
252
267
|
}
|
|
253
|
-
}, [apiRef, processRowUpdate, throwIfNotInMode, updateOrDeleteFieldState]);
|
|
268
|
+
}, [apiRef, onProcessRowUpdateError, processRowUpdate, throwIfNotInMode, updateOrDeleteFieldState]);
|
|
254
269
|
const setCellEditingEditCellValue = React.useCallback(async params => {
|
|
255
270
|
const {
|
|
256
271
|
id,
|
|
@@ -9,12 +9,15 @@ import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
|
9
9
|
import { gridEditRowsStateSelector } from './gridEditRowsSelector';
|
|
10
10
|
import { isPrintableKey } from '../../../utils/keyboardUtils';
|
|
11
11
|
import { gridColumnFieldsSelector } from '../columns/gridColumnsSelector';
|
|
12
|
+
import { buildWarning } from '../../../utils/warning';
|
|
12
13
|
import { GridRowEditStopReasons, GridRowEditStartReasons } from '../../../models/params/gridRowParams';
|
|
14
|
+
const missingOnProcessRowUpdateErrorWarning = buildWarning(['MUI: A call to `processRowUpdate` threw an error which was not handled because `onProcessRowUpdateError` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError` prop, e.g. `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see http://mui.com/components/data-grid/editing/#persistence.'], 'error');
|
|
13
15
|
export const useGridRowEditing = (apiRef, props) => {
|
|
14
16
|
const focusTimeout = React.useRef(null);
|
|
15
17
|
const nextFocusedCell = React.useRef(null);
|
|
16
18
|
const {
|
|
17
|
-
processRowUpdate
|
|
19
|
+
processRowUpdate,
|
|
20
|
+
onProcessRowUpdateError
|
|
18
21
|
} = props;
|
|
19
22
|
|
|
20
23
|
const runIfEditModeIsRow = callback => (...args) => {
|
|
@@ -347,17 +350,29 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
347
350
|
});
|
|
348
351
|
|
|
349
352
|
if (processRowUpdate) {
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
353
|
+
const handleError = errorThrown => {
|
|
354
|
+
if (onProcessRowUpdateError) {
|
|
355
|
+
onProcessRowUpdateError(errorThrown);
|
|
356
|
+
} else {
|
|
357
|
+
missingOnProcessRowUpdateErrorWarning();
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
try {
|
|
362
|
+
Promise.resolve(processRowUpdate(rowUpdate, row)).then(finalRowUpdate => {
|
|
363
|
+
apiRef.current.updateRows([finalRowUpdate]);
|
|
364
|
+
updateFocusedCellIfNeeded();
|
|
365
|
+
updateOrDeleteRowState(id, null);
|
|
366
|
+
}).catch(handleError);
|
|
367
|
+
} catch (errorThrown) {
|
|
368
|
+
handleError(errorThrown);
|
|
369
|
+
}
|
|
355
370
|
} else {
|
|
356
371
|
apiRef.current.updateRows([rowUpdate]);
|
|
357
372
|
updateFocusedCellIfNeeded();
|
|
358
373
|
updateOrDeleteRowState(id, null);
|
|
359
374
|
}
|
|
360
|
-
}, [apiRef, processRowUpdate, throwIfNotInMode, updateOrDeleteRowState]);
|
|
375
|
+
}, [apiRef, onProcessRowUpdateError, processRowUpdate, throwIfNotInMode, updateOrDeleteRowState]);
|
|
361
376
|
const setRowEditingEditCellValue = React.useCallback(params => {
|
|
362
377
|
const {
|
|
363
378
|
id,
|
|
@@ -17,6 +17,8 @@ export function useGridEvents(apiRef, props) {
|
|
|
17
17
|
useGridApiOptionHandler(apiRef, GridEvents.cellDoubleClick, props.onCellDoubleClick);
|
|
18
18
|
useGridApiOptionHandler(apiRef, GridEvents.cellKeyDown, props.onCellKeyDown);
|
|
19
19
|
useGridApiOptionHandler(apiRef, GridEvents.cellFocusOut, props.onCellFocusOut);
|
|
20
|
+
useGridApiOptionHandler(apiRef, GridEvents.preferencePanelClose, props.onPreferencePanelClose);
|
|
21
|
+
useGridApiOptionHandler(apiRef, GridEvents.preferencePanelOpen, props.onPreferencePanelOpen);
|
|
20
22
|
useGridApiOptionHandler(apiRef, GridEvents.rowDoubleClick, props.onRowDoubleClick);
|
|
21
23
|
useGridApiOptionHandler(apiRef, GridEvents.rowClick, props.onRowClick);
|
|
22
24
|
useGridApiOptionHandler(apiRef, GridEvents.componentError, props.onError);
|
|
@@ -11,7 +11,7 @@ import { getDefaultGridFilterModel } from './gridFilterState';
|
|
|
11
11
|
import { gridFilterModelSelector, gridVisibleSortedRowEntriesSelector } from './gridFilterSelector';
|
|
12
12
|
import { useFirstRender } from '../../utils/useFirstRender';
|
|
13
13
|
import { gridRowIdsSelector } from '../rows';
|
|
14
|
-
import {
|
|
14
|
+
import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
|
|
15
15
|
import { GRID_DEFAULT_STRATEGY, useGridRegisterStrategyProcessor } from '../../core/strategyProcessing';
|
|
16
16
|
import { buildAggregatedFilterApplier, sanitizeFilterModel, mergeStateWithFilterModel } from './gridFilterUtils';
|
|
17
17
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -213,9 +213,9 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
213
213
|
filteredDescendantCountLookup: {}
|
|
214
214
|
};
|
|
215
215
|
}, [apiRef, props.filterMode]);
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
216
|
+
useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
|
|
217
|
+
useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
|
|
218
|
+
useGridRegisterPipeProcessor(apiRef, 'preferencePanel', preferencePanelPreProcessing);
|
|
219
219
|
useGridRegisterStrategyProcessor(apiRef, GRID_DEFAULT_STRATEGY, 'filtering', flatFilteringMethod);
|
|
220
220
|
/**
|
|
221
221
|
* EVENTS
|
|
@@ -7,13 +7,12 @@ import { gridVisibleSortedRowEntriesSelector } from '../filter/gridFilterSelecto
|
|
|
7
7
|
import { useGridVisibleRows } from '../../utils/useGridVisibleRows';
|
|
8
8
|
import { GRID_CHECKBOX_SELECTION_COL_DEF } from '../../../colDef/gridCheckboxSelectionColDef';
|
|
9
9
|
import { gridClasses } from '../../../constants/gridClasses';
|
|
10
|
+
import { GridCellModes } from '../../../models/gridEditRowModel';
|
|
11
|
+
import { isNavigationKey } from '../../../utils/keyboardUtils';
|
|
10
12
|
/**
|
|
11
|
-
* @requires useGridPage (state)
|
|
12
|
-
* @requires useGridPageSize (state)
|
|
13
|
-
* @requires useGridFilter (state)
|
|
14
|
-
* @requires useGridColumns (state, method)
|
|
15
|
-
* @requires useGridRows (state, method)
|
|
16
13
|
* @requires useGridSorting (method) - can be after
|
|
14
|
+
* @requires useGridFilter (state) - can be after
|
|
15
|
+
* @requires useGridColumns (state, method) - can be after
|
|
17
16
|
* @requires useGridDimensions (method) - can be after
|
|
18
17
|
* @requires useGridFocus (method) - can be after
|
|
19
18
|
* @requires useGridScroll (method) - can be after
|
|
@@ -111,8 +110,16 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
111
110
|
break;
|
|
112
111
|
}
|
|
113
112
|
|
|
114
|
-
case 'PageDown':
|
|
115
113
|
case ' ':
|
|
114
|
+
{
|
|
115
|
+
if (!event.shiftKey && rowIndexBefore < lastRowIndexInPage) {
|
|
116
|
+
goToCell(colIndexBefore, Math.min(rowIndexBefore + viewportPageSize, lastRowIndexInPage));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
case 'PageDown':
|
|
116
123
|
{
|
|
117
124
|
if (rowIndexBefore < lastRowIndexInPage) {
|
|
118
125
|
goToCell(colIndexBefore, Math.min(rowIndexBefore + viewportPageSize, lastRowIndexInPage));
|
|
@@ -265,6 +272,20 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
265
272
|
event.preventDefault();
|
|
266
273
|
}
|
|
267
274
|
}, [apiRef, currentPage, goToCell, goToHeader]);
|
|
275
|
+
const handleCellKeyDown = React.useCallback((params, event) => {
|
|
276
|
+
// Ignore portal
|
|
277
|
+
if (!event.currentTarget.contains(event.target)) {
|
|
278
|
+
return;
|
|
279
|
+
} // Get the most recent params because the cell mode may have changed by another listener
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
const cellParams = apiRef.current.getCellParams(params.id, params.field);
|
|
283
|
+
|
|
284
|
+
if (cellParams.cellMode !== GridCellModes.Edit && isNavigationKey(event.key)) {
|
|
285
|
+
apiRef.current.publishEvent(GridEvents.cellNavigationKeyDown, cellParams, event);
|
|
286
|
+
}
|
|
287
|
+
}, [apiRef]);
|
|
268
288
|
useGridApiEventHandler(apiRef, GridEvents.cellNavigationKeyDown, handleCellNavigationKeyDown);
|
|
269
289
|
useGridApiEventHandler(apiRef, GridEvents.columnHeaderKeyDown, handleColumnHeaderKeyDown);
|
|
290
|
+
useGridApiEventHandler(apiRef, GridEvents.cellKeyDown, handleCellKeyDown);
|
|
270
291
|
};
|
|
@@ -3,8 +3,8 @@ import * as React from 'react';
|
|
|
3
3
|
import { useGridLogger, useGridSelector, useGridApiMethod, useGridApiEventHandler } from '../../utils';
|
|
4
4
|
import { GridEvents } from '../../../models/events';
|
|
5
5
|
import { gridVisibleTopLevelRowCountSelector } from '../filter';
|
|
6
|
-
import { gridPageSelector } from './gridPaginationSelector';
|
|
7
|
-
import {
|
|
6
|
+
import { gridPageSelector, gridPageSizeSelector } from './gridPaginationSelector';
|
|
7
|
+
import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
|
|
8
8
|
import { buildWarning } from '../../../utils/warning';
|
|
9
9
|
export const getPageCount = (rowCount, pageSize) => {
|
|
10
10
|
if (pageSize > 0 && rowCount > 0) {
|
|
@@ -85,8 +85,8 @@ export const useGridPage = (apiRef, props) => {
|
|
|
85
85
|
apiRef.current.setState(mergeStateWithPage(page));
|
|
86
86
|
return params;
|
|
87
87
|
}, [apiRef]);
|
|
88
|
-
|
|
89
|
-
|
|
88
|
+
useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
|
|
89
|
+
useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
|
|
90
90
|
/**
|
|
91
91
|
* EVENTS
|
|
92
92
|
*/
|
|
@@ -104,7 +104,12 @@ export const useGridPage = (apiRef, props) => {
|
|
|
104
104
|
apiRef.current.forceUpdate();
|
|
105
105
|
};
|
|
106
106
|
|
|
107
|
+
const handlePageChange = () => apiRef.current.scrollToIndexes({
|
|
108
|
+
rowIndex: gridPageSelector(apiRef) * gridPageSizeSelector(apiRef)
|
|
109
|
+
});
|
|
110
|
+
|
|
107
111
|
useGridApiEventHandler(apiRef, GridEvents.pageSizeChange, handlePageSizeChange);
|
|
112
|
+
useGridApiEventHandler(apiRef, GridEvents.pageChange, handlePageChange);
|
|
108
113
|
/**
|
|
109
114
|
* EFFECTS
|
|
110
115
|
*/
|
|
@@ -4,7 +4,7 @@ import { GridEvents } from '../../../models/events';
|
|
|
4
4
|
import { useGridLogger, useGridApiMethod, useGridApiEventHandler, useGridSelector } from '../../utils';
|
|
5
5
|
import { gridPageSizeSelector } from './gridPaginationSelector';
|
|
6
6
|
import { gridDensityRowHeightSelector } from '../density';
|
|
7
|
-
import {
|
|
7
|
+
import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
|
|
8
8
|
export const defaultPageSize = autoPageSize => autoPageSize ? 0 : 100;
|
|
9
9
|
|
|
10
10
|
const mergeStateWithPageSize = pageSize => state => _extends({}, state, {
|
|
@@ -78,8 +78,8 @@ export const useGridPageSize = (apiRef, props) => {
|
|
|
78
78
|
|
|
79
79
|
return params;
|
|
80
80
|
}, [apiRef]);
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
|
|
82
|
+
useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
|
|
83
83
|
/**
|
|
84
84
|
* EVENTS
|
|
85
85
|
*/
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
import { GridEvents } from '../../../models/events';
|
|
3
4
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
4
5
|
import { useGridLogger } from '../../utils/useGridLogger';
|
|
5
|
-
import {
|
|
6
|
+
import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
|
|
6
7
|
import { gridPreferencePanelStateSelector } from './gridPreferencePanelSelector';
|
|
8
|
+
import { useGridSelector } from '../../utils/useGridSelector';
|
|
7
9
|
export const preferencePanelStateInitializer = (state, props) => _extends({}, state, {
|
|
8
10
|
preferencePanel: props.initialState?.preferencePanel ?? {
|
|
9
11
|
open: false
|
|
@@ -15,6 +17,7 @@ export const preferencePanelStateInitializer = (state, props) => _extends({}, st
|
|
|
15
17
|
|
|
16
18
|
export const useGridPreferencesPanel = apiRef => {
|
|
17
19
|
const logger = useGridLogger(apiRef, 'useGridPreferencesPanel');
|
|
20
|
+
const preferencePanelState = useGridSelector(apiRef, gridPreferencePanelStateSelector);
|
|
18
21
|
const hideTimeout = React.useRef();
|
|
19
22
|
const immediateTimeout = React.useRef();
|
|
20
23
|
/**
|
|
@@ -23,13 +26,20 @@ export const useGridPreferencesPanel = apiRef => {
|
|
|
23
26
|
|
|
24
27
|
const hidePreferences = React.useCallback(() => {
|
|
25
28
|
logger.debug('Hiding Preferences Panel');
|
|
29
|
+
|
|
30
|
+
if (preferencePanelState.openedPanelValue) {
|
|
31
|
+
apiRef.current.publishEvent(GridEvents.preferencePanelClose, {
|
|
32
|
+
openedPanelValue: preferencePanelState.openedPanelValue
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
|
|
26
36
|
apiRef.current.setState(state => _extends({}, state, {
|
|
27
37
|
preferencePanel: {
|
|
28
38
|
open: false
|
|
29
39
|
}
|
|
30
40
|
}));
|
|
31
41
|
apiRef.current.forceUpdate();
|
|
32
|
-
}, [apiRef, logger]); // This is to prevent the preferences from closing when you open a select box or another panel,
|
|
42
|
+
}, [apiRef, logger, preferencePanelState.openedPanelValue]); // This is to prevent the preferences from closing when you open a select box or another panel,
|
|
33
43
|
// The issue is in MUI core V4 => Fixed in V5
|
|
34
44
|
|
|
35
45
|
const doNotHidePanel = React.useCallback(() => {
|
|
@@ -49,8 +59,11 @@ export const useGridPreferencesPanel = apiRef => {
|
|
|
49
59
|
openedPanelValue: newValue
|
|
50
60
|
})
|
|
51
61
|
}));
|
|
62
|
+
apiRef.current.publishEvent(GridEvents.preferencePanelOpen, {
|
|
63
|
+
openedPanelValue: newValue
|
|
64
|
+
});
|
|
52
65
|
apiRef.current.forceUpdate();
|
|
53
|
-
}, [doNotHidePanel, apiRef
|
|
66
|
+
}, [logger, doNotHidePanel, apiRef]);
|
|
54
67
|
useGridApiMethod(apiRef, {
|
|
55
68
|
showPreferences,
|
|
56
69
|
hidePreferences: hidePreferencesDelayed
|
|
@@ -81,8 +94,8 @@ export const useGridPreferencesPanel = apiRef => {
|
|
|
81
94
|
|
|
82
95
|
return params;
|
|
83
96
|
}, [apiRef]);
|
|
84
|
-
|
|
85
|
-
|
|
97
|
+
useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
|
|
98
|
+
useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
|
|
86
99
|
/**
|
|
87
100
|
* EFFECTS
|
|
88
101
|
*/
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A helper function to check if the id provided is valid.
|
|
3
|
+
* @param {GridRowId} id Id as [[GridRowId]].
|
|
4
|
+
* @param {GridRowModel | Partial<GridRowModel>} row Row as [[GridRowModel]].
|
|
5
|
+
* @param {string} detailErrorMessage A custom error message to display for invalid IDs
|
|
6
|
+
*/
|
|
7
|
+
export function checkGridRowIdIsValid(id, row, detailErrorMessage = 'A row was provided without id in the rows prop:') {
|
|
8
|
+
if (id == null) {
|
|
9
|
+
throw new Error(['MUI: The data grid component requires all rows to have a unique `id` property.', 'Alternatively, you can use the `getRowId` prop to specify a custom id for each row.', detailErrorMessage, JSON.stringify(row)].join('\n'));
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { GridEvents } from '../../../models/events';
|
|
4
|
-
import { checkGridRowIdIsValid } from '../../../models/gridRows';
|
|
5
4
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
6
5
|
import { useGridLogger } from '../../utils/useGridLogger';
|
|
7
6
|
import { gridRowCountSelector, gridRowsLookupSelector, gridRowTreeSelector, gridRowIdsSelector, gridRowGroupingNameSelector } from './gridRowsSelector';
|
|
8
7
|
import { GridSignature, useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
|
|
9
8
|
import { useGridVisibleRows } from '../../utils/useGridVisibleRows';
|
|
9
|
+
import { checkGridRowIdIsValid } from './gridRowsUtils';
|
|
10
10
|
|
|
11
11
|
function getGridRowId(rowModel, getRowId, detailErrorMessage) {
|
|
12
12
|
const id = getRowId ? getRowId(rowModel) : rowModel.id;
|
|
@@ -70,7 +70,7 @@ export const useGridRowsMeta = (apiRef, props) => {
|
|
|
70
70
|
initialHeights.spacingBottom = spacing.bottom ?? 0;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
const sizes = apiRef.current.
|
|
73
|
+
const sizes = apiRef.current.unstable_applyPipeProcessors('rowHeight', initialHeights, row);
|
|
74
74
|
const finalRowHeight = Object.values(sizes).reduce((acc2, value) => acc2 + value, 0);
|
|
75
75
|
rowsHeightLookup.current[row.id] = {
|
|
76
76
|
value: baseRowHeight,
|
|
@@ -108,14 +108,14 @@ export const useGridRowsMeta = (apiRef, props) => {
|
|
|
108
108
|
React.useEffect(() => {
|
|
109
109
|
hydrateRowsMeta();
|
|
110
110
|
}, [rowHeight, filterState, paginationState, sortingState, hydrateRowsMeta]);
|
|
111
|
-
const
|
|
111
|
+
const handlepipeProcessorRegister = React.useCallback(name => {
|
|
112
112
|
if (name !== 'rowHeight') {
|
|
113
113
|
return;
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
hydrateRowsMeta();
|
|
117
117
|
}, [hydrateRowsMeta]);
|
|
118
|
-
useGridApiEventHandler(apiRef, GridEvents.
|
|
118
|
+
useGridApiEventHandler(apiRef, GridEvents.pipeProcessorRegister, handlepipeProcessorRegister);
|
|
119
119
|
const rowsMetaApi = {
|
|
120
120
|
unstable_getRowHeight: getTargetRowHeight,
|
|
121
121
|
unstable_getRowInternalSizes: getRowInternalSizes,
|
|
@@ -4,8 +4,7 @@ import { gridColumnPositionsSelector, gridVisibleColumnDefinitionsSelector } fro
|
|
|
4
4
|
import { gridPageSelector, gridPageSizeSelector } from '../pagination/gridPaginationSelector';
|
|
5
5
|
import { gridRowCountSelector } from '../rows/gridRowsSelector';
|
|
6
6
|
import { gridRowsMetaSelector } from '../rows/gridRowsMetaSelector';
|
|
7
|
-
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
8
|
-
import { useGridNativeEventListener } from '../../utils/useGridNativeEventListener'; // Logic copied from https://www.w3.org/TR/wai-aria-practices/examples/listbox/js/listbox.js
|
|
7
|
+
import { useGridApiMethod } from '../../utils/useGridApiMethod'; // Logic copied from https://www.w3.org/TR/wai-aria-practices/examples/listbox/js/listbox.js
|
|
9
8
|
// Similar to https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView
|
|
10
9
|
|
|
11
10
|
function scrollIntoView(dimensions) {
|
|
@@ -42,8 +41,9 @@ export const useGridScroll = (apiRef, props) => {
|
|
|
42
41
|
const scrollToIndexes = React.useCallback(params => {
|
|
43
42
|
const totalRowCount = gridRowCountSelector(apiRef);
|
|
44
43
|
const visibleColumns = gridVisibleColumnDefinitionsSelector(apiRef);
|
|
44
|
+
const scrollToHeader = params.rowIndex == null;
|
|
45
45
|
|
|
46
|
-
if (totalRowCount === 0 || visibleColumns.length === 0) {
|
|
46
|
+
if (!scrollToHeader && totalRowCount === 0 || visibleColumns.length === 0) {
|
|
47
47
|
return false;
|
|
48
48
|
}
|
|
49
49
|
|
|
@@ -74,7 +74,7 @@ export const useGridScroll = (apiRef, props) => {
|
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
scrollCoordinates = apiRef.current.
|
|
77
|
+
scrollCoordinates = apiRef.current.unstable_applyPipeProcessors('scrollToIndexes', scrollCoordinates, params);
|
|
78
78
|
|
|
79
79
|
if (typeof scrollCoordinates.left !== undefined || typeof scrollCoordinates.top !== undefined) {
|
|
80
80
|
apiRef.current.scroll(scrollCoordinates);
|
|
@@ -116,9 +116,4 @@ export const useGridScroll = (apiRef, props) => {
|
|
|
116
116
|
getScrollPosition
|
|
117
117
|
};
|
|
118
118
|
useGridApiMethod(apiRef, scrollApi, 'GridScrollApi');
|
|
119
|
-
const preventScroll = React.useCallback(event => {
|
|
120
|
-
event.target.scrollLeft = 0;
|
|
121
|
-
event.target.scrollTop = 0;
|
|
122
|
-
}, []);
|
|
123
|
-
useGridNativeEventListener(apiRef, () => apiRef.current?.renderingZoneRef?.current?.parentElement, 'scroll', preventScroll);
|
|
124
119
|
};
|