@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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import { DEFAULT_GRID_COL_TYPE_KEY, getGridDefaultColumnTypes } from '../../../
|
|
2
|
+
import { DEFAULT_GRID_COL_TYPE_KEY, getGridDefaultColumnTypes } from '../../../colDef';
|
|
3
3
|
import { gridColumnsSelector, gridColumnVisibilityModelSelector } from './gridColumnsSelector';
|
|
4
4
|
import { clamp } from '../../../utils/utils';
|
|
5
5
|
export const COLUMNS_DIMENSION_PROPERTIES = ['maxWidth', 'minWidth', 'width', 'flex'];
|
|
@@ -243,7 +243,7 @@ export const createColumnsState = ({
|
|
|
243
243
|
apiRef,
|
|
244
244
|
columnsToUpsert,
|
|
245
245
|
initialState,
|
|
246
|
-
|
|
246
|
+
columnTypes,
|
|
247
247
|
currentColumnVisibilityModel = gridColumnVisibilityModelSelector(apiRef),
|
|
248
248
|
shouldRegenColumnVisibilityModelFromColumns,
|
|
249
249
|
keepOnlyColumnsToUpsert = false
|
|
@@ -253,7 +253,7 @@ export const createColumnsState = ({
|
|
|
253
253
|
const isInsideStateInitializer = !apiRef.current.state.columns;
|
|
254
254
|
let columnsStateWithoutColumnVisibilityModel;
|
|
255
255
|
|
|
256
|
-
if (isInsideStateInitializer
|
|
256
|
+
if (isInsideStateInitializer) {
|
|
257
257
|
columnsStateWithoutColumnVisibilityModel = {
|
|
258
258
|
all: [],
|
|
259
259
|
lookup: {}
|
|
@@ -261,33 +261,65 @@ export const createColumnsState = ({
|
|
|
261
261
|
} else {
|
|
262
262
|
const currentState = gridColumnsSelector(apiRef.current.state);
|
|
263
263
|
columnsStateWithoutColumnVisibilityModel = {
|
|
264
|
-
all: [...currentState.all],
|
|
265
|
-
lookup: _extends({}, currentState.lookup)
|
|
264
|
+
all: keepOnlyColumnsToUpsert ? [] : [...currentState.all],
|
|
265
|
+
lookup: _extends({}, currentState.lookup) // Will be cleaned later if keepOnlyColumnsToUpsert=true
|
|
266
|
+
|
|
266
267
|
};
|
|
267
268
|
}
|
|
268
269
|
|
|
270
|
+
let columnsToKeep = {};
|
|
271
|
+
|
|
272
|
+
if (keepOnlyColumnsToUpsert && !isInsideStateInitializer) {
|
|
273
|
+
columnsToKeep = Object.keys(columnsStateWithoutColumnVisibilityModel.lookup).reduce((acc, key) => _extends({}, acc, {
|
|
274
|
+
[key]: false
|
|
275
|
+
}), {});
|
|
276
|
+
}
|
|
277
|
+
|
|
269
278
|
const columnsToUpsertLookup = {};
|
|
270
279
|
columnsToUpsert.forEach(newColumn => {
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
280
|
+
const {
|
|
281
|
+
field
|
|
282
|
+
} = newColumn;
|
|
283
|
+
columnsToUpsertLookup[field] = true;
|
|
284
|
+
columnsToKeep[field] = true;
|
|
285
|
+
let existingState = columnsStateWithoutColumnVisibilityModel.lookup[field];
|
|
286
|
+
|
|
287
|
+
if (existingState == null) {
|
|
274
288
|
// New Column
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
289
|
+
existingState = _extends({}, getGridColDef(columnTypes, newColumn.type), {
|
|
290
|
+
// TODO v6: Inline `getGridColDef`
|
|
291
|
+
field,
|
|
292
|
+
hasBeenResized: false
|
|
293
|
+
});
|
|
294
|
+
columnsStateWithoutColumnVisibilityModel.all.push(field);
|
|
295
|
+
} else if (keepOnlyColumnsToUpsert) {
|
|
296
|
+
columnsStateWithoutColumnVisibilityModel.all.push(field);
|
|
297
|
+
}
|
|
279
298
|
|
|
280
|
-
|
|
281
|
-
mergedColumn.hasBeenResized = true;
|
|
282
|
-
}
|
|
299
|
+
let hasValidDimension = false;
|
|
283
300
|
|
|
284
|
-
|
|
301
|
+
if (!existingState.hasBeenResized) {
|
|
302
|
+
hasValidDimension = COLUMNS_DIMENSION_PROPERTIES.some(key => newColumn[key] !== undefined);
|
|
285
303
|
}
|
|
304
|
+
|
|
305
|
+
columnsStateWithoutColumnVisibilityModel.lookup[field] = _extends({}, existingState, {
|
|
306
|
+
hide: newColumn.hide == null ? false : newColumn.hide
|
|
307
|
+
}, newColumn, {
|
|
308
|
+
hasBeenResized: existingState.hasBeenResized || hasValidDimension
|
|
309
|
+
});
|
|
286
310
|
});
|
|
287
311
|
|
|
312
|
+
if (keepOnlyColumnsToUpsert && !isInsideStateInitializer) {
|
|
313
|
+
Object.keys(columnsStateWithoutColumnVisibilityModel.lookup).forEach(field => {
|
|
314
|
+
if (!columnsToKeep[field]) {
|
|
315
|
+
delete columnsStateWithoutColumnVisibilityModel.lookup[field];
|
|
316
|
+
}
|
|
317
|
+
});
|
|
318
|
+
}
|
|
319
|
+
|
|
288
320
|
const columnsLookupBeforePreProcessing = _extends({}, columnsStateWithoutColumnVisibilityModel.lookup);
|
|
289
321
|
|
|
290
|
-
const columnsStateWithPreProcessing = apiRef.current.
|
|
322
|
+
const columnsStateWithPreProcessing = apiRef.current.unstable_applyPipeProcessors('hydrateColumns', columnsStateWithoutColumnVisibilityModel); // TODO v6: remove the sync between the columns `hide` option and the model.
|
|
291
323
|
|
|
292
324
|
let columnVisibilityModel = {};
|
|
293
325
|
|
|
@@ -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";
|
|
@@ -16,7 +16,7 @@ export const columnsStateInitializer = (state, props, apiRef) => {
|
|
|
16
16
|
const columnsTypes = computeColumnTypes(props.columnTypes);
|
|
17
17
|
const columnsState = createColumnsState({
|
|
18
18
|
apiRef,
|
|
19
|
-
columnsTypes,
|
|
19
|
+
columnTypes: columnsTypes,
|
|
20
20
|
columnsToUpsert: props.columns,
|
|
21
21
|
initialState: (_props$initialState2 = props.initialState) == null ? void 0 : _props$initialState2.columns,
|
|
22
22
|
shouldRegenColumnVisibilityModelFromColumns: !isUsingColumnVisibilityModel,
|
|
@@ -37,13 +37,15 @@ export function useGridColumns(apiRef, props) {
|
|
|
37
37
|
var _props$initialState4, _props$initialState4$, _props$componentsProp2;
|
|
38
38
|
|
|
39
39
|
const logger = useGridLogger(apiRef, 'useGridColumns');
|
|
40
|
-
const
|
|
40
|
+
const columnTypes = React.useMemo(() => computeColumnTypes(props.columnTypes), [props.columnTypes]);
|
|
41
|
+
const previousColumnsProp = React.useRef(props.columns);
|
|
42
|
+
const previousColumnTypesProp = React.useRef(columnTypes);
|
|
41
43
|
/**
|
|
42
44
|
* If `initialState.columns.columnVisibilityModel` or `columnVisibilityModel` was defined during the 1st render, we are directly updating the model
|
|
43
45
|
* 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`
|
|
44
46
|
*/
|
|
45
47
|
|
|
46
|
-
const isUsingColumnVisibilityModel = React.useRef(!!props.columnVisibilityModel || !!((_props$initialState4 = props.initialState) != null && (_props$initialState4$ = _props$initialState4.columns) != null && _props$initialState4$.columnVisibilityModel))
|
|
48
|
+
const isUsingColumnVisibilityModel = React.useRef(!!props.columnVisibilityModel || !!((_props$initialState4 = props.initialState) != null && (_props$initialState4$ = _props$initialState4.columns) != null && _props$initialState4$.columnVisibilityModel));
|
|
47
49
|
apiRef.current.unstable_updateControlState({
|
|
48
50
|
stateId: 'visibleColumns',
|
|
49
51
|
propModel: props.columnVisibilityModel,
|
|
@@ -80,7 +82,7 @@ export function useGridColumns(apiRef, props) {
|
|
|
80
82
|
apiRef.current.setState(state => _extends({}, state, {
|
|
81
83
|
columns: createColumnsState({
|
|
82
84
|
apiRef,
|
|
83
|
-
|
|
85
|
+
columnTypes,
|
|
84
86
|
columnsToUpsert: [],
|
|
85
87
|
initialState: undefined,
|
|
86
88
|
shouldRegenColumnVisibilityModelFromColumns: false,
|
|
@@ -90,24 +92,24 @@ export function useGridColumns(apiRef, props) {
|
|
|
90
92
|
}));
|
|
91
93
|
apiRef.current.forceUpdate();
|
|
92
94
|
}
|
|
93
|
-
}, [apiRef,
|
|
95
|
+
}, [apiRef, columnTypes]);
|
|
94
96
|
const updateColumns = React.useCallback(columns => {
|
|
95
97
|
const columnsState = createColumnsState({
|
|
96
98
|
apiRef,
|
|
97
|
-
|
|
99
|
+
columnTypes,
|
|
98
100
|
columnsToUpsert: columns,
|
|
99
101
|
initialState: undefined,
|
|
100
102
|
shouldRegenColumnVisibilityModelFromColumns: true,
|
|
101
103
|
keepOnlyColumnsToUpsert: false
|
|
102
104
|
});
|
|
103
105
|
setGridColumnsState(columnsState);
|
|
104
|
-
}, [apiRef, setGridColumnsState,
|
|
106
|
+
}, [apiRef, setGridColumnsState, columnTypes]);
|
|
105
107
|
const updateColumn = React.useCallback(column => apiRef.current.updateColumns([column]), [apiRef]);
|
|
106
108
|
const setColumnVisibility = React.useCallback((field, isVisible) => {
|
|
107
109
|
// We keep updating the `hide` option of `GridColDef` when not controlling the model to avoid any breaking change.
|
|
108
110
|
// `updateColumns` take care of updating the model itself if needs be.
|
|
109
111
|
// TODO v6: stop using the `hide` field even when the model is not defined
|
|
110
|
-
if (isUsingColumnVisibilityModel) {
|
|
112
|
+
if (isUsingColumnVisibilityModel.current) {
|
|
111
113
|
var _columnVisibilityMode;
|
|
112
114
|
|
|
113
115
|
const columnVisibilityModel = gridColumnVisibilityModelSelector(apiRef);
|
|
@@ -135,7 +137,7 @@ export function useGridColumns(apiRef, props) {
|
|
|
135
137
|
};
|
|
136
138
|
apiRef.current.publishEvent(GridEvents.columnVisibilityChange, params);
|
|
137
139
|
}
|
|
138
|
-
}, [apiRef
|
|
140
|
+
}, [apiRef]);
|
|
139
141
|
const setColumnIndex = React.useCallback((field, targetIndexPosition) => {
|
|
140
142
|
const allColumns = gridColumnFieldsSelector(apiRef);
|
|
141
143
|
const oldIndexPosition = allColumns.findIndex(col => col === field);
|
|
@@ -196,7 +198,7 @@ export function useGridColumns(apiRef, props) {
|
|
|
196
198
|
const stateExportPreProcessing = React.useCallback(prevState => {
|
|
197
199
|
const columnsStateToExport = {};
|
|
198
200
|
|
|
199
|
-
if (isUsingColumnVisibilityModel) {
|
|
201
|
+
if (isUsingColumnVisibilityModel.current) {
|
|
200
202
|
const columnVisibilityModelToExport = gridColumnVisibilityModelSelector(apiRef);
|
|
201
203
|
const hasHiddenColumns = Object.values(columnVisibilityModelToExport).some(value => value === false);
|
|
202
204
|
|
|
@@ -225,11 +227,11 @@ export function useGridColumns(apiRef, props) {
|
|
|
225
227
|
return _extends({}, prevState, {
|
|
226
228
|
columns: columnsStateToExport
|
|
227
229
|
});
|
|
228
|
-
}, [apiRef
|
|
230
|
+
}, [apiRef]);
|
|
229
231
|
const stateRestorePreProcessing = React.useCallback((params, context) => {
|
|
230
232
|
var _context$stateToResto;
|
|
231
233
|
|
|
232
|
-
const columnVisibilityModelToImport = isUsingColumnVisibilityModel ? (_context$stateToResto = context.stateToRestore.columns) == null ? void 0 : _context$stateToResto.columnVisibilityModel : undefined;
|
|
234
|
+
const columnVisibilityModelToImport = isUsingColumnVisibilityModel.current ? (_context$stateToResto = context.stateToRestore.columns) == null ? void 0 : _context$stateToResto.columnVisibilityModel : undefined;
|
|
233
235
|
const initialState = context.stateToRestore.columns;
|
|
234
236
|
|
|
235
237
|
if (columnVisibilityModelToImport == null && initialState == null) {
|
|
@@ -238,10 +240,10 @@ export function useGridColumns(apiRef, props) {
|
|
|
238
240
|
|
|
239
241
|
const columnsState = createColumnsState({
|
|
240
242
|
apiRef,
|
|
241
|
-
|
|
243
|
+
columnTypes,
|
|
242
244
|
columnsToUpsert: [],
|
|
243
245
|
initialState,
|
|
244
|
-
shouldRegenColumnVisibilityModelFromColumns: !isUsingColumnVisibilityModel,
|
|
246
|
+
shouldRegenColumnVisibilityModelFromColumns: !isUsingColumnVisibilityModel.current,
|
|
245
247
|
currentColumnVisibilityModel: columnVisibilityModelToImport,
|
|
246
248
|
keepOnlyColumnsToUpsert: false
|
|
247
249
|
});
|
|
@@ -252,7 +254,7 @@ export function useGridColumns(apiRef, props) {
|
|
|
252
254
|
}
|
|
253
255
|
|
|
254
256
|
return params;
|
|
255
|
-
}, [apiRef,
|
|
257
|
+
}, [apiRef, columnTypes]);
|
|
256
258
|
const preferencePanelPreProcessing = React.useCallback((initialValue, value) => {
|
|
257
259
|
if (value === GridPreferencePanelsValue.columns) {
|
|
258
260
|
var _props$componentsProp;
|
|
@@ -263,14 +265,14 @@ export function useGridColumns(apiRef, props) {
|
|
|
263
265
|
|
|
264
266
|
return initialValue;
|
|
265
267
|
}, [props.components.ColumnsPanel, (_props$componentsProp2 = props.componentsProps) == null ? void 0 : _props$componentsProp2.columnsPanel]);
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
268
|
+
useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
|
|
269
|
+
useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
|
|
270
|
+
useGridRegisterPipeProcessor(apiRef, 'preferencePanel', preferencePanelPreProcessing);
|
|
269
271
|
/**
|
|
270
272
|
* EVENTS
|
|
271
273
|
*/
|
|
272
274
|
|
|
273
|
-
const
|
|
275
|
+
const handlepipeProcessorRegister = React.useCallback(name => {
|
|
274
276
|
if (name !== 'hydrateColumns') {
|
|
275
277
|
return;
|
|
276
278
|
}
|
|
@@ -278,14 +280,14 @@ export function useGridColumns(apiRef, props) {
|
|
|
278
280
|
logger.info(`Columns pre-processing have changed, regenerating the columns`);
|
|
279
281
|
const columnsState = createColumnsState({
|
|
280
282
|
apiRef,
|
|
281
|
-
|
|
283
|
+
columnTypes,
|
|
282
284
|
columnsToUpsert: [],
|
|
283
285
|
initialState: undefined,
|
|
284
|
-
shouldRegenColumnVisibilityModelFromColumns: !isUsingColumnVisibilityModel,
|
|
286
|
+
shouldRegenColumnVisibilityModelFromColumns: !isUsingColumnVisibilityModel.current,
|
|
285
287
|
keepOnlyColumnsToUpsert: false
|
|
286
288
|
});
|
|
287
289
|
setGridColumnsState(columnsState);
|
|
288
|
-
}, [apiRef, logger, setGridColumnsState,
|
|
290
|
+
}, [apiRef, logger, setGridColumnsState, columnTypes]);
|
|
289
291
|
const prevInnerWidth = React.useRef(null);
|
|
290
292
|
|
|
291
293
|
const handleGridSizeChange = viewportInnerSize => {
|
|
@@ -295,7 +297,7 @@ export function useGridColumns(apiRef, props) {
|
|
|
295
297
|
}
|
|
296
298
|
};
|
|
297
299
|
|
|
298
|
-
useGridApiEventHandler(apiRef, GridEvents.
|
|
300
|
+
useGridApiEventHandler(apiRef, GridEvents.pipeProcessorRegister, handlepipeProcessorRegister);
|
|
299
301
|
useGridApiEventHandler(apiRef, GridEvents.viewportInnerSizeChange, handleGridSizeChange);
|
|
300
302
|
useGridApiOptionHandler(apiRef, GridEvents.columnVisibilityChange, props.onColumnVisibilityChange);
|
|
301
303
|
/**
|
|
@@ -312,17 +314,24 @@ export function useGridColumns(apiRef, props) {
|
|
|
312
314
|
}
|
|
313
315
|
|
|
314
316
|
logger.info(`GridColumns have changed, new length ${props.columns.length}`);
|
|
317
|
+
|
|
318
|
+
if (previousColumnsProp.current === props.columns && previousColumnTypesProp.current === columnTypes) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
|
|
315
322
|
const columnsState = createColumnsState({
|
|
316
323
|
apiRef,
|
|
317
|
-
|
|
324
|
+
columnTypes,
|
|
318
325
|
initialState: undefined,
|
|
319
326
|
// 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`
|
|
320
|
-
shouldRegenColumnVisibilityModelFromColumns: !isUsingColumnVisibilityModel,
|
|
327
|
+
shouldRegenColumnVisibilityModelFromColumns: !isUsingColumnVisibilityModel.current,
|
|
321
328
|
columnsToUpsert: props.columns,
|
|
322
329
|
keepOnlyColumnsToUpsert: true
|
|
323
330
|
});
|
|
331
|
+
previousColumnsProp.current = props.columns;
|
|
332
|
+
previousColumnTypesProp.current = columnTypes;
|
|
324
333
|
setGridColumnsState(columnsState);
|
|
325
|
-
}, [logger, apiRef, setGridColumnsState, props.columns,
|
|
334
|
+
}, [logger, apiRef, setGridColumnsState, props.columns, columnTypes]);
|
|
326
335
|
React.useEffect(() => {
|
|
327
336
|
if (props.columnVisibilityModel !== undefined) {
|
|
328
337
|
apiRef.current.setColumnVisibilityModel(props.columnVisibilityModel);
|
|
@@ -33,4 +33,9 @@ export interface GridDimensionsApi {
|
|
|
33
33
|
* @ignore - do not document.
|
|
34
34
|
*/
|
|
35
35
|
unstable_getViewportPageSize: () => number;
|
|
36
|
+
/**
|
|
37
|
+
* Forces a recalculation of all dimensions.
|
|
38
|
+
* @ignore - do not document.
|
|
39
|
+
*/
|
|
40
|
+
unstable_updateGridDimensionsRef: () => void;
|
|
36
41
|
}
|
|
@@ -134,7 +134,8 @@ export function useGridDimensions(apiRef, props) {
|
|
|
134
134
|
const dimensionsApi = {
|
|
135
135
|
resize,
|
|
136
136
|
getRootDimensions,
|
|
137
|
-
unstable_getViewportPageSize: getViewportPageSize
|
|
137
|
+
unstable_getViewportPageSize: getViewportPageSize,
|
|
138
|
+
unstable_updateGridDimensionsRef: updateGridDimensionsRef
|
|
138
139
|
};
|
|
139
140
|
useGridApiMethod(apiRef, dimensionsApi, 'GridDimensionsApi');
|
|
140
141
|
const debounceResize = React.useMemo(() => debounce(resize, 60), [resize]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { GridApiCommunity } from '../../../models/api/gridApiCommunity';
|
|
3
3
|
import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
|
|
4
|
-
export declare const useGridCellEditing: (apiRef: React.MutableRefObject<GridApiCommunity>, props: Pick<DataGridProcessedProps, 'editMode' | 'processRowUpdate' | 'onCellEditStart' | 'onCellEditStop'>) => void;
|
|
4
|
+
export declare const useGridCellEditing: (apiRef: React.MutableRefObject<GridApiCommunity>, props: Pick<DataGridProcessedProps, 'editMode' | 'processRowUpdate' | 'onCellEditStart' | 'onCellEditStop' | 'onProcessRowUpdateError'>) => void;
|
|
@@ -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,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { GridApiCommunity } from '../../../models/api/gridApiCommunity';
|
|
3
3
|
import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
|
|
4
|
-
export declare const useGridRowEditing: (apiRef: React.MutableRefObject<GridApiCommunity>, props: Pick<DataGridProcessedProps, 'editMode' | 'processRowUpdate' | 'onRowEditStart' | 'onRowEditStop'>) => void;
|
|
4
|
+
export declare const useGridRowEditing: (apiRef: React.MutableRefObject<GridApiCommunity>, props: Pick<DataGridProcessedProps, 'editMode' | 'processRowUpdate' | 'onRowEditStart' | 'onRowEditStop' | 'onProcessRowUpdateError'>) => void;
|
|
@@ -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) => {
|
|
@@ -349,17 +352,29 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
349
352
|
});
|
|
350
353
|
|
|
351
354
|
if (processRowUpdate) {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
355
|
+
const handleError = errorThrown => {
|
|
356
|
+
if (onProcessRowUpdateError) {
|
|
357
|
+
onProcessRowUpdateError(errorThrown);
|
|
358
|
+
} else {
|
|
359
|
+
missingOnProcessRowUpdateErrorWarning();
|
|
360
|
+
}
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
try {
|
|
364
|
+
Promise.resolve(processRowUpdate(rowUpdate, row)).then(finalRowUpdate => {
|
|
365
|
+
apiRef.current.updateRows([finalRowUpdate]);
|
|
366
|
+
updateFocusedCellIfNeeded();
|
|
367
|
+
updateOrDeleteRowState(id, null);
|
|
368
|
+
}).catch(handleError);
|
|
369
|
+
} catch (errorThrown) {
|
|
370
|
+
handleError(errorThrown);
|
|
371
|
+
}
|
|
357
372
|
} else {
|
|
358
373
|
apiRef.current.updateRows([rowUpdate]);
|
|
359
374
|
updateFocusedCellIfNeeded();
|
|
360
375
|
updateOrDeleteRowState(id, null);
|
|
361
376
|
}
|
|
362
|
-
}, [apiRef, processRowUpdate, throwIfNotInMode, updateOrDeleteRowState]);
|
|
377
|
+
}, [apiRef, onProcessRowUpdateError, processRowUpdate, throwIfNotInMode, updateOrDeleteRowState]);
|
|
363
378
|
const setRowEditingEditCellValue = React.useCallback(params => {
|
|
364
379
|
const {
|
|
365
380
|
id,
|
|
@@ -5,4 +5,4 @@ import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
|
|
|
5
5
|
* @requires useGridFocus (event) - can be after, async only
|
|
6
6
|
* @requires useGridColumns (event) - can be after, async only
|
|
7
7
|
*/
|
|
8
|
-
export declare function useGridEvents(apiRef: React.MutableRefObject<GridApiCommunity>, props: Pick<DataGridProcessedProps, 'onColumnHeaderClick' | 'onColumnHeaderDoubleClick' | 'onColumnHeaderOver' | 'onColumnHeaderOut' | 'onColumnHeaderEnter' | 'onColumnHeaderLeave' | 'onColumnOrderChange' | 'onCellClick' | 'onCellDoubleClick' | 'onCellKeyDown' | 'onCellFocusOut' | 'onRowDoubleClick' | 'onRowClick' | 'onError' | 'onStateChange'>): void;
|
|
8
|
+
export declare function useGridEvents(apiRef: React.MutableRefObject<GridApiCommunity>, props: Pick<DataGridProcessedProps, 'onColumnHeaderClick' | 'onColumnHeaderDoubleClick' | 'onColumnHeaderOver' | 'onColumnHeaderOut' | 'onColumnHeaderEnter' | 'onColumnHeaderLeave' | 'onColumnOrderChange' | 'onCellClick' | 'onCellDoubleClick' | 'onCellKeyDown' | 'onCellFocusOut' | 'onPreferencePanelClose' | 'onPreferencePanelOpen' | 'onRowDoubleClick' | 'onRowClick' | 'onError' | 'onStateChange'>): void;
|
|
@@ -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);
|
|
@@ -31,9 +31,7 @@ export declare const gridFilteredDescendantCountLookupSelector: import("../../..
|
|
|
31
31
|
*/
|
|
32
32
|
export declare const gridVisibleSortedRowEntriesSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, {
|
|
33
33
|
id: import("../../..").GridRowId;
|
|
34
|
-
model:
|
|
35
|
-
[key: string]: any;
|
|
36
|
-
};
|
|
34
|
+
model: any;
|
|
37
35
|
}[]>;
|
|
38
36
|
/**
|
|
39
37
|
* Get the id of the rows accessible after the filtering process.
|
|
@@ -48,9 +46,7 @@ export declare const gridVisibleSortedRowIdsSelector: import("../../../utils/cre
|
|
|
48
46
|
*/
|
|
49
47
|
export declare const gridFilteredSortedRowEntriesSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, {
|
|
50
48
|
id: import("../../..").GridRowId;
|
|
51
|
-
model:
|
|
52
|
-
[key: string]: any;
|
|
53
|
-
};
|
|
49
|
+
model: any;
|
|
54
50
|
}[]>;
|
|
55
51
|
/**
|
|
56
52
|
* Get the id of the rows accessible after the filtering process.
|
|
@@ -71,9 +67,7 @@ export declare const gridVisibleRowsSelector: import("../../../utils/createSelec
|
|
|
71
67
|
*/
|
|
72
68
|
export declare const gridVisibleSortedTopLevelRowEntriesSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, {
|
|
73
69
|
id: import("../../..").GridRowId;
|
|
74
|
-
model:
|
|
75
|
-
[key: string]: any;
|
|
76
|
-
};
|
|
70
|
+
model: any;
|
|
77
71
|
}[]>;
|
|
78
72
|
/**
|
|
79
73
|
* Get the amount of rows accessible after the filtering process.
|
|
@@ -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";
|
|
@@ -221,9 +221,9 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
221
221
|
filteredDescendantCountLookup: {}
|
|
222
222
|
};
|
|
223
223
|
}, [apiRef, props.filterMode]);
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
224
|
+
useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
|
|
225
|
+
useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
|
|
226
|
+
useGridRegisterPipeProcessor(apiRef, 'preferencePanel', preferencePanelPreProcessing);
|
|
227
227
|
useGridRegisterStrategyProcessor(apiRef, GRID_DEFAULT_STRATEGY, 'filtering', flatFilteringMethod);
|
|
228
228
|
/**
|
|
229
229
|
* EVENTS
|
|
@@ -2,12 +2,9 @@ import * as React from 'react';
|
|
|
2
2
|
import { GridApiCommunity } from '../../../models/api/gridApiCommunity';
|
|
3
3
|
import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
|
|
4
4
|
/**
|
|
5
|
-
* @requires useGridPage (state)
|
|
6
|
-
* @requires useGridPageSize (state)
|
|
7
|
-
* @requires useGridFilter (state)
|
|
8
|
-
* @requires useGridColumns (state, method)
|
|
9
|
-
* @requires useGridRows (state, method)
|
|
10
5
|
* @requires useGridSorting (method) - can be after
|
|
6
|
+
* @requires useGridFilter (state) - can be after
|
|
7
|
+
* @requires useGridColumns (state, method) - can be after
|
|
11
8
|
* @requires useGridDimensions (method) - can be after
|
|
12
9
|
* @requires useGridFocus (method) - can be after
|
|
13
10
|
* @requires useGridScroll (method) - can be after
|
|
@@ -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));
|
|
@@ -267,6 +274,20 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
|
267
274
|
event.preventDefault();
|
|
268
275
|
}
|
|
269
276
|
}, [apiRef, currentPage, goToCell, goToHeader]);
|
|
277
|
+
const handleCellKeyDown = React.useCallback((params, event) => {
|
|
278
|
+
// Ignore portal
|
|
279
|
+
if (!event.currentTarget.contains(event.target)) {
|
|
280
|
+
return;
|
|
281
|
+
} // Get the most recent params because the cell mode may have changed by another listener
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
const cellParams = apiRef.current.getCellParams(params.id, params.field);
|
|
285
|
+
|
|
286
|
+
if (cellParams.cellMode !== GridCellModes.Edit && isNavigationKey(event.key)) {
|
|
287
|
+
apiRef.current.publishEvent(GridEvents.cellNavigationKeyDown, cellParams, event);
|
|
288
|
+
}
|
|
289
|
+
}, [apiRef]);
|
|
270
290
|
useGridApiEventHandler(apiRef, GridEvents.cellNavigationKeyDown, handleCellNavigationKeyDown);
|
|
271
291
|
useGridApiEventHandler(apiRef, GridEvents.columnHeaderKeyDown, handleColumnHeaderKeyDown);
|
|
292
|
+
useGridApiEventHandler(apiRef, GridEvents.cellKeyDown, handleCellKeyDown);
|
|
272
293
|
};
|
|
@@ -33,9 +33,7 @@ export declare const gridPaginationRowRangeSelector: import("../../../utils/crea
|
|
|
33
33
|
*/
|
|
34
34
|
export declare const gridPaginatedVisibleSortedGridRowEntriesSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, {
|
|
35
35
|
id: import("../../..").GridRowId;
|
|
36
|
-
model:
|
|
37
|
-
[key: string]: any;
|
|
38
|
-
};
|
|
36
|
+
model: any;
|
|
39
37
|
}[]>;
|
|
40
38
|
/**
|
|
41
39
|
* Get the id of each row to include in the current page if the pagination is enabled.
|
|
@@ -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) {
|
|
@@ -91,8 +91,8 @@ export const useGridPage = (apiRef, props) => {
|
|
|
91
91
|
apiRef.current.setState(mergeStateWithPage(page));
|
|
92
92
|
return params;
|
|
93
93
|
}, [apiRef]);
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
|
|
95
|
+
useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
|
|
96
96
|
/**
|
|
97
97
|
* EVENTS
|
|
98
98
|
*/
|
|
@@ -110,7 +110,12 @@ export const useGridPage = (apiRef, props) => {
|
|
|
110
110
|
apiRef.current.forceUpdate();
|
|
111
111
|
};
|
|
112
112
|
|
|
113
|
+
const handlePageChange = () => apiRef.current.scrollToIndexes({
|
|
114
|
+
rowIndex: gridPageSelector(apiRef) * gridPageSizeSelector(apiRef)
|
|
115
|
+
});
|
|
116
|
+
|
|
113
117
|
useGridApiEventHandler(apiRef, GridEvents.pageSizeChange, handlePageSizeChange);
|
|
118
|
+
useGridApiEventHandler(apiRef, GridEvents.pageChange, handlePageChange);
|
|
114
119
|
/**
|
|
115
120
|
* EFFECTS
|
|
116
121
|
*/
|