@mui/x-data-grid 8.10.2 → 8.11.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.
Files changed (84) hide show
  1. package/CHANGELOG.md +140 -13
  2. package/DataGrid/DataGrid.js +4 -2
  3. package/DataGrid/useDataGridComponent.d.ts +2 -1
  4. package/DataGrid/useDataGridComponent.js +2 -2
  5. package/colDef/gridDateColDef.js +7 -0
  6. package/components/GridColumnSortButton.js +1 -2
  7. package/components/GridColumnUnsortedIcon.d.ts +2 -3
  8. package/components/GridRow.js +11 -5
  9. package/components/cell/GridActionsCell.js +8 -4
  10. package/components/columnHeaders/GridColumnGroupHeader.js +13 -1
  11. package/components/columnHeaders/GridColumnHeaderItem.js +12 -3
  12. package/components/columnHeaders/GridGenericColumnHeaderItem.js +0 -14
  13. package/components/columnsManagement/GridColumnsManagement.js +7 -2
  14. package/components/containers/GridRootStyles.js +19 -6
  15. package/components/menu/columnMenu/menuItems/GridColumnMenuSortItem.js +3 -2
  16. package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.d.ts +1 -1
  17. package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +6 -9
  18. package/components/panel/filterPanel/GridFilterInputSingleSelect.js +4 -10
  19. package/components/virtualization/GridVirtualScrollerRenderZone.js +3 -10
  20. package/esm/DataGrid/DataGrid.js +4 -2
  21. package/esm/DataGrid/useDataGridComponent.d.ts +2 -1
  22. package/esm/DataGrid/useDataGridComponent.js +2 -2
  23. package/esm/colDef/gridDateColDef.js +7 -0
  24. package/esm/components/GridColumnSortButton.js +1 -2
  25. package/esm/components/GridColumnUnsortedIcon.d.ts +2 -3
  26. package/esm/components/GridRow.js +12 -6
  27. package/esm/components/cell/GridActionsCell.js +8 -4
  28. package/esm/components/columnHeaders/GridColumnGroupHeader.js +13 -1
  29. package/esm/components/columnHeaders/GridColumnHeaderItem.js +12 -3
  30. package/esm/components/columnHeaders/GridGenericColumnHeaderItem.js +0 -14
  31. package/esm/components/columnsManagement/GridColumnsManagement.js +6 -1
  32. package/esm/components/containers/GridRootStyles.js +19 -6
  33. package/esm/components/menu/columnMenu/menuItems/GridColumnMenuSortItem.js +3 -2
  34. package/esm/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.d.ts +1 -1
  35. package/esm/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +6 -9
  36. package/esm/components/panel/filterPanel/GridFilterInputSingleSelect.js +4 -10
  37. package/esm/components/virtualization/GridVirtualScrollerRenderZone.js +3 -10
  38. package/esm/hooks/core/pipeProcessing/gridPipeProcessingApi.d.ts +15 -0
  39. package/esm/hooks/features/editing/useGridCellEditing.js +1 -1
  40. package/esm/hooks/features/editing/useGridRowEditing.js +1 -1
  41. package/esm/hooks/features/filter/gridFilterSelector.d.ts +9 -1
  42. package/esm/hooks/features/filter/gridFilterSelector.js +12 -0
  43. package/esm/hooks/features/pagination/useGridPaginationModel.js +2 -2
  44. package/esm/hooks/features/rows/useGridRows.d.ts +2 -1
  45. package/esm/hooks/features/rows/useGridRows.js +6 -34
  46. package/esm/hooks/features/rows/useGridRowsOverridableMethods.d.ts +6 -0
  47. package/esm/hooks/features/rows/useGridRowsOverridableMethods.js +43 -0
  48. package/esm/hooks/features/scroll/useGridScroll.js +1 -1
  49. package/esm/hooks/utils/useGridConfiguration.d.ts +3 -1
  50. package/esm/index.js +1 -1
  51. package/esm/internals/index.d.ts +2 -1
  52. package/esm/internals/index.js +2 -1
  53. package/esm/material/index.js +2 -0
  54. package/esm/models/api/gridParamsApi.d.ts +3 -3
  55. package/esm/models/colDef/gridColDef.d.ts +4 -2
  56. package/esm/models/configuration/gridConfiguration.d.ts +6 -4
  57. package/esm/models/configuration/gridRowConfiguration.d.ts +11 -1
  58. package/esm/models/gridIconSlotsComponent.d.ts +6 -0
  59. package/esm/models/props/DataGridProps.d.ts +1 -1
  60. package/esm/utils/cleanupTracking/FinalizationRegistryBasedCleanupTracking.js +0 -2
  61. package/hooks/core/pipeProcessing/gridPipeProcessingApi.d.ts +15 -0
  62. package/hooks/features/editing/useGridCellEditing.js +1 -1
  63. package/hooks/features/editing/useGridRowEditing.js +1 -1
  64. package/hooks/features/filter/gridFilterSelector.d.ts +9 -1
  65. package/hooks/features/filter/gridFilterSelector.js +13 -1
  66. package/hooks/features/pagination/useGridPaginationModel.js +2 -2
  67. package/hooks/features/rows/useGridRows.d.ts +2 -1
  68. package/hooks/features/rows/useGridRows.js +6 -34
  69. package/hooks/features/rows/useGridRowsOverridableMethods.d.ts +6 -0
  70. package/hooks/features/rows/useGridRowsOverridableMethods.js +52 -0
  71. package/hooks/features/scroll/useGridScroll.js +1 -1
  72. package/hooks/utils/useGridConfiguration.d.ts +3 -1
  73. package/index.js +1 -1
  74. package/internals/index.d.ts +2 -1
  75. package/internals/index.js +15 -0
  76. package/material/index.js +2 -0
  77. package/models/api/gridParamsApi.d.ts +3 -3
  78. package/models/colDef/gridColDef.d.ts +4 -2
  79. package/models/configuration/gridConfiguration.d.ts +6 -4
  80. package/models/configuration/gridRowConfiguration.d.ts +11 -1
  81. package/models/gridIconSlotsComponent.d.ts +6 -0
  82. package/models/props/DataGridProps.d.ts +1 -1
  83. package/package.json +11 -11
  84. package/utils/cleanupTracking/FinalizationRegistryBasedCleanupTracking.js +0 -2
@@ -174,4 +174,16 @@ export const gridFilterActiveItemsLookupSelector = createSelectorMemoized(gridFi
174
174
  return res;
175
175
  }, {});
176
176
  return result;
177
+ });
178
+
179
+ /**
180
+ * Get the index lookup for expanded (visible) rows only.
181
+ * Does not include collapsed children.
182
+ * @ignore - do not document.
183
+ */
184
+ export const gridExpandedSortedRowIndexLookupSelector = createSelectorMemoized(gridExpandedSortedRowIdsSelector, expandedSortedIds => {
185
+ return expandedSortedIds.reduce((acc, id, index) => {
186
+ acc[id] = index;
187
+ return acc;
188
+ }, Object.create(null));
177
189
  });
@@ -219,13 +219,13 @@ export const useGridPaginationModel = (apiRef, props) => {
219
219
  React.useEffect(() => {
220
220
  apiRef.current.setState(state => {
221
221
  const isEnabled = props.pagination === true;
222
- if (state.pagination.paginationMode === props.paginationMode || state.pagination.enabled === isEnabled) {
222
+ if (state.pagination.paginationMode === props.paginationMode && state.pagination.enabled === isEnabled) {
223
223
  return state;
224
224
  }
225
225
  return _extends({}, state, {
226
226
  pagination: _extends({}, state.pagination, {
227
227
  paginationMode: props.paginationMode,
228
- enabled: props.pagination === true
228
+ enabled: isEnabled
229
229
  })
230
230
  });
231
231
  });
@@ -2,5 +2,6 @@ import { RefObject } from '@mui/x-internals/types';
2
2
  import { DataGridProcessedProps } from "../../../models/props/DataGridProps.js";
3
3
  import { GridPrivateApiCommunity } from "../../../models/api/gridApiCommunity.js";
4
4
  import { GridStateInitializer } from "../../utils/useGridInitializeState.js";
5
+ import type { GridConfiguration } from "../../../models/configuration/gridConfiguration.js";
5
6
  export declare const rowsStateInitializer: GridStateInitializer<Pick<DataGridProcessedProps, 'dataSource' | 'rows' | 'rowCount' | 'getRowId' | 'loading'>>;
6
- export declare const useGridRows: (apiRef: RefObject<GridPrivateApiCommunity>, props: Pick<DataGridProcessedProps, "rows" | "getRowId" | "rowCount" | "throttleRowsMs" | "signature" | "pagination" | "paginationMode" | "loading" | "dataSource">) => void;
7
+ export declare const useGridRows: (apiRef: RefObject<GridPrivateApiCommunity>, props: Pick<DataGridProcessedProps, "rows" | "getRowId" | "rowCount" | "throttleRowsMs" | "signature" | "pagination" | "paginationMode" | "loading" | "dataSource" | "processRowUpdate" | "onProcessRowUpdateError">, configuration: GridConfiguration) => void;
@@ -36,7 +36,7 @@ export const rowsStateInitializer = (state, props, apiRef) => {
36
36
  })
37
37
  });
38
38
  };
39
- export const useGridRows = (apiRef, props) => {
39
+ export const useGridRows = (apiRef, props, configuration) => {
40
40
  if (process.env.NODE_ENV !== 'production') {
41
41
  try {
42
42
  // Freeze the `rows` prop so developers have a fast failure if they try to use Array.prototype.push().
@@ -49,6 +49,11 @@ export const useGridRows = (apiRef, props) => {
49
49
  const lastUpdateMs = React.useRef(Date.now());
50
50
  const lastRowCount = React.useRef(props.rowCount);
51
51
  const timeout = useTimeout();
52
+
53
+ // Get overridable methods from configuration
54
+ const {
55
+ setRowIndex
56
+ } = configuration.hooks.useGridRowsOverridableMethods(apiRef, props);
52
57
  const getRow = React.useCallback(id => {
53
58
  const model = gridRowsLookupSelector(apiRef)[id];
54
59
  if (model) {
@@ -226,39 +231,6 @@ export const useGridRows = (apiRef, props) => {
226
231
  }
227
232
  return children;
228
233
  }, [apiRef]);
229
- const setRowIndex = React.useCallback((rowId, targetIndex) => {
230
- const node = gridRowNodeSelector(apiRef, rowId);
231
- if (!node) {
232
- throw new Error(`MUI X: No row with id #${rowId} found.`);
233
- }
234
- if (node.parent !== GRID_ROOT_GROUP_ID) {
235
- throw new Error(`MUI X: The row reordering do not support reordering of grouped rows yet.`);
236
- }
237
- if (node.type !== 'leaf') {
238
- throw new Error(`MUI X: The row reordering do not support reordering of footer or grouping rows.`);
239
- }
240
- apiRef.current.setState(state => {
241
- const group = gridRowTreeSelector(apiRef)[GRID_ROOT_GROUP_ID];
242
- const allRows = group.children;
243
- const oldIndex = allRows.findIndex(row => row === rowId);
244
- if (oldIndex === -1 || oldIndex === targetIndex) {
245
- return state;
246
- }
247
- logger.debug(`Moving row ${rowId} to index ${targetIndex}`);
248
- const updatedRows = [...allRows];
249
- updatedRows.splice(targetIndex, 0, updatedRows.splice(oldIndex, 1)[0]);
250
- return _extends({}, state, {
251
- rows: _extends({}, state.rows, {
252
- tree: _extends({}, state.rows.tree, {
253
- [GRID_ROOT_GROUP_ID]: _extends({}, group, {
254
- children: updatedRows
255
- })
256
- })
257
- })
258
- });
259
- });
260
- apiRef.current.publishEvent('rowsSet');
261
- }, [apiRef, logger]);
262
234
  const replaceRows = React.useCallback((firstRowToRender, newRows) => {
263
235
  if (props.signature === GridSignature.DataGrid && newRows.length > 1) {
264
236
  throw new Error(['MUI X: You cannot replace rows using `apiRef.current.unstable_replaceRows` on the DataGrid.', 'You need to upgrade to DataGridPro or DataGridPremium component to unlock this feature.'].join('\n'));
@@ -0,0 +1,6 @@
1
+ import { RefObject } from '@mui/x-internals/types';
2
+ import { GridRowId } from "../../../models/gridRows.js";
3
+ import { GridPrivateApiCommunity } from "../../../models/api/gridApiCommunity.js";
4
+ export declare const useGridRowsOverridableMethods: (apiRef: RefObject<GridPrivateApiCommunity>) => {
5
+ setRowIndex: (rowId: GridRowId, targetIndex: number) => void;
6
+ };
@@ -0,0 +1,43 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import * as React from 'react';
3
+ import { gridRowTreeSelector, gridRowNodeSelector } from "./gridRowsSelector.js";
4
+ import { GRID_ROOT_GROUP_ID } from "./gridRowsUtils.js";
5
+ export const useGridRowsOverridableMethods = apiRef => {
6
+ const setRowIndex = React.useCallback((rowId, targetIndex) => {
7
+ const node = gridRowNodeSelector(apiRef, rowId);
8
+ if (!node) {
9
+ throw new Error(`MUI X: No row with id #${rowId} found.`);
10
+ }
11
+
12
+ // TODO: Remove irrelevant checks
13
+ if (node.parent !== GRID_ROOT_GROUP_ID) {
14
+ throw new Error(`MUI X: The row reordering do not support reordering of grouped rows yet.`);
15
+ }
16
+ if (node.type !== 'leaf') {
17
+ throw new Error(`MUI X: The row reordering do not support reordering of footer or grouping rows.`);
18
+ }
19
+ apiRef.current.setState(state => {
20
+ const group = gridRowTreeSelector(apiRef)[GRID_ROOT_GROUP_ID];
21
+ const allRows = group.children;
22
+ const oldIndex = allRows.findIndex(row => row === rowId);
23
+ if (oldIndex === -1 || oldIndex === targetIndex) {
24
+ return state;
25
+ }
26
+ const updatedRows = [...allRows];
27
+ updatedRows.splice(targetIndex, 0, updatedRows.splice(oldIndex, 1)[0]);
28
+ return _extends({}, state, {
29
+ rows: _extends({}, state.rows, {
30
+ tree: _extends({}, state.rows.tree, {
31
+ [GRID_ROOT_GROUP_ID]: _extends({}, group, {
32
+ children: updatedRows
33
+ })
34
+ })
35
+ })
36
+ });
37
+ });
38
+ apiRef.current.publishEvent('rowsSet');
39
+ }, [apiRef]);
40
+ return {
41
+ setRowIndex
42
+ };
43
+ };
@@ -93,7 +93,7 @@ export const useGridScroll = (apiRef, props) => {
93
93
  });
94
94
  }
95
95
  scrollCoordinates = apiRef.current.unstable_applyPipeProcessors('scrollToIndexes', scrollCoordinates, params);
96
- if (typeof scrollCoordinates.left !== undefined || typeof scrollCoordinates.top !== undefined) {
96
+ if (typeof scrollCoordinates.left !== 'undefined' || typeof scrollCoordinates.top !== 'undefined') {
97
97
  apiRef.current.scroll(scrollCoordinates);
98
98
  return true;
99
99
  }
@@ -1,2 +1,4 @@
1
1
  import { GridConfiguration } from "../../models/configuration/gridConfiguration.js";
2
- export declare const useGridConfiguration: () => GridConfiguration;
2
+ import type { GridPrivateApiCommon } from "../../models/api/gridApiCommon.js";
3
+ import type { GridPrivateApiCommunity } from "../../models/api/gridApiCommunity.js";
4
+ export declare const useGridConfiguration: <Api extends GridPrivateApiCommon = GridPrivateApiCommunity>() => GridConfiguration<Api>;
package/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid v8.10.2
2
+ * @mui/x-data-grid v8.11.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -41,7 +41,7 @@ export { useGridPrintExport } from "../hooks/features/export/useGridPrintExport.
41
41
  export { useGridFilter, filterStateInitializer } from "../hooks/features/filter/useGridFilter.js";
42
42
  export { defaultGridFilterLookup } from "../hooks/features/filter/gridFilterState.js";
43
43
  export { passFilterLogic } from "../hooks/features/filter/gridFilterUtils.js";
44
- export { gridFilteredChildrenCountLookupSelector, gridExpandedSortedRowTreeLevelPositionLookupSelector } from "../hooks/features/filter/gridFilterSelector.js";
44
+ export { gridFilteredChildrenCountLookupSelector, gridExpandedSortedRowTreeLevelPositionLookupSelector, gridExpandedSortedRowIndexLookupSelector } from "../hooks/features/filter/gridFilterSelector.js";
45
45
  export { isSingleSelectColDef } from "../components/panel/filterPanel/filterPanelUtils.js";
46
46
  export type { GridAggregatedFilterItemApplier, GridAggregatedFilterItemApplierResult } from "../hooks/features/filter/gridFilterState.js";
47
47
  export { useGridFocus, focusStateInitializer } from "../hooks/features/focus/useGridFocus.js";
@@ -54,6 +54,7 @@ export { useGridRows, rowsStateInitializer } from "../hooks/features/rows/useGri
54
54
  export { useGridRowSpanning, rowSpanningStateInitializer } from "../hooks/features/rows/useGridRowSpanning.js";
55
55
  export { useGridAriaAttributes } from "../hooks/utils/useGridAriaAttributes.js";
56
56
  export { useGridRowAriaAttributes } from "../hooks/features/rows/useGridRowAriaAttributes.js";
57
+ export { useGridRowsOverridableMethods } from "../hooks/features/rows/useGridRowsOverridableMethods.js";
57
58
  export { useGridRowsPreProcessors } from "../hooks/features/rows/useGridRowsPreProcessors.js";
58
59
  export type { GridRowTreeCreationParams, GridRowTreeCreationValue, GridHydrateRowsValue, GridRowsPartialUpdates, GridRowsPartialUpdateAction, GridTreeDepths, GridRowTreeUpdatedGroupsManager, GridRowTreeUpdateGroupAction, GridPinnedRowsState } from "../hooks/features/rows/gridRowsInterfaces.js";
59
60
  export { getTreeNodeDescendants, buildRootGroup } from "../hooks/features/rows/gridRowsUtils.js";
@@ -31,7 +31,7 @@ export { useGridPrintExport } from "../hooks/features/export/useGridPrintExport.
31
31
  export { useGridFilter, filterStateInitializer } from "../hooks/features/filter/useGridFilter.js";
32
32
  export { defaultGridFilterLookup } from "../hooks/features/filter/gridFilterState.js";
33
33
  export { passFilterLogic } from "../hooks/features/filter/gridFilterUtils.js";
34
- export { gridFilteredChildrenCountLookupSelector, gridExpandedSortedRowTreeLevelPositionLookupSelector } from "../hooks/features/filter/gridFilterSelector.js";
34
+ export { gridFilteredChildrenCountLookupSelector, gridExpandedSortedRowTreeLevelPositionLookupSelector, gridExpandedSortedRowIndexLookupSelector } from "../hooks/features/filter/gridFilterSelector.js";
35
35
  export { isSingleSelectColDef } from "../components/panel/filterPanel/filterPanelUtils.js";
36
36
  export { useGridFocus, focusStateInitializer } from "../hooks/features/focus/useGridFocus.js";
37
37
  export { useGridKeyboardNavigation } from "../hooks/features/keyboardNavigation/useGridKeyboardNavigation.js";
@@ -43,6 +43,7 @@ export { useGridRows, rowsStateInitializer } from "../hooks/features/rows/useGri
43
43
  export { useGridRowSpanning, rowSpanningStateInitializer } from "../hooks/features/rows/useGridRowSpanning.js";
44
44
  export { useGridAriaAttributes } from "../hooks/utils/useGridAriaAttributes.js";
45
45
  export { useGridRowAriaAttributes } from "../hooks/features/rows/useGridRowAriaAttributes.js";
46
+ export { useGridRowsOverridableMethods } from "../hooks/features/rows/useGridRowsOverridableMethods.js";
46
47
  export { useGridRowsPreProcessors } from "../hooks/features/rows/useGridRowsPreProcessors.js";
47
48
  export { getTreeNodeDescendants, buildRootGroup } from "../hooks/features/rows/gridRowsUtils.js";
48
49
  export { useGridRowsMeta, rowsMetaStateInitializer } from "../hooks/features/rows/useGridRowsMeta.js";
@@ -58,6 +58,7 @@ import MUIInputLabel from '@mui/material/InputLabel';
58
58
  import MUISkeleton from '@mui/material/Skeleton';
59
59
  import { forwardRef } from '@mui/x-internals/forwardRef';
60
60
  import { GridAddIcon, GridArrowDownwardIcon, GridArrowUpwardIcon, GridCheckIcon, GridCloseIcon, GridColumnIcon, GridDragIcon, GridExpandMoreIcon, GridFilterAltIcon, GridFilterListIcon, GridKeyboardArrowRight, GridMoreVertIcon, GridRemoveIcon, GridSearchIcon, GridSeparatorIcon, GridTableRowsIcon, GridTripleDotsVerticalIcon, GridViewHeadlineIcon, GridViewStreamIcon, GridVisibilityOffIcon, GridViewColumnIcon, GridClearIcon, GridLoadIcon, GridDeleteForeverIcon, GridDownloadIcon } from "./icons/index.js";
61
+ import { GridColumnUnsortedIcon } from "../components/GridColumnUnsortedIcon.js";
61
62
  import { useGridApiContext } from "../hooks/utils/useGridApiContext.js";
62
63
  import { useGridRootProps } from "../hooks/utils/useGridRootProps.js";
63
64
  import "./augmentation.js";
@@ -663,6 +664,7 @@ const iconSlots = {
663
664
  filterPanelDeleteIcon: GridCloseIcon,
664
665
  columnFilteredIcon: GridFilterAltIcon,
665
666
  columnSelectorIcon: GridColumnIcon,
667
+ columnUnsortedIcon: GridColumnUnsortedIcon,
666
668
  columnSortedAscendingIcon: GridArrowUpwardIcon,
667
669
  columnSortedDescendingIcon: GridArrowDownwardIcon,
668
670
  columnResizeIcon: GridSeparatorIcon,
@@ -13,7 +13,7 @@ export interface GridParamsApi {
13
13
  * @param {string} field The column field.
14
14
  * @returns {v} The cell value.
15
15
  */
16
- getCellValue: <V extends any = any>(id: GridRowId, field: string) => V;
16
+ getCellValue: <V = any>(id: GridRowId, field: string) => V;
17
17
  /**
18
18
  * Gets the cell value.
19
19
  * Use it instead of `getCellValue` for better performance if you have `row` and `colDef`.
@@ -23,7 +23,7 @@ export interface GridParamsApi {
23
23
  * @returns {v} The cell value.
24
24
  * @ignore - do not document
25
25
  */
26
- getRowValue: <V extends any = any>(row: GridRowModel, colDef: GridColDef) => V;
26
+ getRowValue: <V = any>(row: GridRowModel, colDef: GridColDef) => V;
27
27
  /**
28
28
  * Gets the cell formatted value
29
29
  * Use it instead of `getCellParams` for better performance if you only need the formatted value.
@@ -33,7 +33,7 @@ export interface GridParamsApi {
33
33
  * @returns {v} The cell value.
34
34
  * @ignore - do not document
35
35
  */
36
- getRowFormattedValue: <V extends any = any>(row: GridRowModel, colDef: GridColDef) => V;
36
+ getRowFormattedValue: <V = any>(row: GridRowModel, colDef: GridColDef) => V;
37
37
  /**
38
38
  * Gets the [[GridCellParams]] object that is passed as argument in events.
39
39
  * @param {GridRowId} id The id of the row.
@@ -279,14 +279,16 @@ export interface GridSingleSelectColDef<R extends GridValidRowModel = any, V = a
279
279
  * Used to determine the label displayed for a given value option.
280
280
  * @param {ValueOptions} value The current value option.
281
281
  * @returns {string} The text to be displayed.
282
+ * @default {defaultGetOptionLabel}
282
283
  */
283
- getOptionLabel?: (value: ValueOptions) => string;
284
+ getOptionLabel: (value: ValueOptions) => string;
284
285
  /**
285
286
  * Used to determine the value used for a value option.
286
287
  * @param {ValueOptions} value The current value option.
287
288
  * @returns {string} The value to be used.
289
+ * @default {defaultGetOptionValue}
288
290
  */
289
- getOptionValue?: (value: ValueOptions) => any;
291
+ getOptionValue: (value: ValueOptions) => any;
290
292
  }
291
293
  /**
292
294
  * Column Definition interface.
@@ -1,11 +1,13 @@
1
1
  import * as React from 'react';
2
- import { GridRowAriaAttributesInternalHook } from "./gridRowConfiguration.js";
2
+ import { GridRowAriaAttributesInternalHook, GridRowsOverridableMethodsInternalHook } from "./gridRowConfiguration.js";
3
3
  import type { GridCSSVariablesInterface } from "../../constants/cssVariables.js";
4
4
  import type { GridRowId } from "../gridRows.js";
5
+ import type { GridPrivateApiCommon } from "../api/gridApiCommon.js";
6
+ import type { GridPrivateApiCommunity } from "../api/gridApiCommunity.js";
5
7
  export interface GridAriaAttributesInternalHook {
6
8
  useGridAriaAttributes: () => React.HTMLAttributes<HTMLElement>;
7
9
  }
8
- export interface GridInternalHook extends GridAriaAttributesInternalHook, GridRowAriaAttributesInternalHook {
10
+ export interface GridInternalHook<Api> extends GridAriaAttributesInternalHook, GridRowAriaAttributesInternalHook, GridRowsOverridableMethodsInternalHook<Api> {
9
11
  useCSSVariables: () => {
10
12
  id: string;
11
13
  variables: GridCSSVariablesInterface;
@@ -15,6 +17,6 @@ export interface GridInternalHook extends GridAriaAttributesInternalHook, GridRo
15
17
  value: any;
16
18
  } | null;
17
19
  }
18
- export interface GridConfiguration {
19
- hooks: GridInternalHook;
20
+ export interface GridConfiguration<Api extends GridPrivateApiCommon = GridPrivateApiCommunity> {
21
+ hooks: GridInternalHook<Api>;
20
22
  }
@@ -1,5 +1,7 @@
1
1
  import * as React from 'react';
2
- import { GridTreeNode } from "../gridRows.js";
2
+ import { RefObject } from '@mui/x-internals/types';
3
+ import { GridTreeNode, GridRowId } from "../gridRows.js";
4
+ import { DataGridProcessedProps } from "../props/DataGridProps.js";
3
5
  /**
4
6
  * Get the ARIA attributes for a row
5
7
  * @param {GridTreeNode} rowNode The row node
@@ -9,4 +11,12 @@ import { GridTreeNode } from "../gridRows.js";
9
11
  export type GetRowAriaAttributesFn = (rowNode: GridTreeNode, index: number) => React.HTMLAttributes<HTMLElement>;
10
12
  export interface GridRowAriaAttributesInternalHook {
11
13
  useGridRowAriaAttributes: () => GetRowAriaAttributesFn;
14
+ }
15
+ /**
16
+ * Overridable row methods interface, these methods could be overriden in a higher plan package.
17
+ */
18
+ export interface GridRowsOverridableMethodsInternalHook<Api> {
19
+ useGridRowsOverridableMethods: (apiRef: RefObject<Api>, props: Pick<DataGridProcessedProps, 'processRowUpdate' | 'onProcessRowUpdateError' | 'dataSource'>) => {
20
+ setRowIndex: (rowId: GridRowId, targetIndex: number) => void;
21
+ };
12
22
  }
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { IconProps } from "./gridBaseSlots.js";
3
+ import type { GridColumnUnsortedIconProps } from "../components/GridColumnUnsortedIcon.js";
3
4
  /**
4
5
  * Set of icons used in the grid component UI.
5
6
  */
@@ -34,6 +35,11 @@ export interface GridIconSlotsComponent {
34
35
  * @default GridColumnIcon
35
36
  */
36
37
  columnSelectorIcon: React.JSXElementConstructor<IconProps>;
38
+ /**
39
+ * Icon displayed on the side of the column header title when unsorted.
40
+ * @default GridColumnUnsortedIcon
41
+ */
42
+ columnUnsortedIcon: React.JSXElementConstructor<GridColumnUnsortedIconProps> | null;
37
43
  /**
38
44
  * Icon displayed on the side of the column header title when sorted in ascending order.
39
45
  * @default GridArrowUpwardIcon
@@ -787,7 +787,7 @@ export interface DataGridPropsWithoutDefaultValue<R extends GridValidRowModel =
787
787
  rowId: GridRowId;
788
788
  }) => Promise<R> | R;
789
789
  /**
790
- * Callback called when `processRowUpdate` throws an error or rejects.
790
+ * Callback called when `processRowUpdate()` throws an error or rejects.
791
791
  * @param {any} error The error thrown.
792
792
  */
793
793
  onProcessRowUpdateError?: (error: any) => void;
@@ -10,7 +10,5 @@ export class FinalizationRegistryBasedCleanupTracking {
10
10
  unregister(unregisterToken) {
11
11
  this.registry.unregister(unregisterToken);
12
12
  }
13
-
14
- // eslint-disable-next-line class-methods-use-this
15
13
  reset() {}
16
14
  }
@@ -91,6 +91,21 @@ export interface GridPipeProcessingLookup {
91
91
  };
92
92
  context: boolean;
93
93
  };
94
+ /**
95
+ * Does validation of the current reorder operation.
96
+ * If the reorder is valid, it returns the position index of the drop indicator.
97
+ * - For example before first row is `0` and after the last row is `rows.length`.
98
+ * If the reorder is invalid, it returns `-1`.
99
+ */
100
+ getRowReorderTargetIndex: {
101
+ value: number;
102
+ context: {
103
+ sourceRowId: GridRowId;
104
+ targetRowId: GridRowId;
105
+ dropPosition: 'above' | 'below';
106
+ dragDirection: 'up' | 'down';
107
+ };
108
+ };
94
109
  }
95
110
  export type GridPipeProcessor<P extends GridPipeProcessorGroup> = (value: GridPipeProcessingLookup[P]['value'], context: GridPipeProcessingLookup[P] extends {
96
111
  context: any;
@@ -372,7 +372,7 @@ const useGridCellEditing = (apiRef, props) => {
372
372
  if (onProcessRowUpdateError) {
373
373
  onProcessRowUpdateError(errorThrown);
374
374
  } else if (process.env.NODE_ENV !== 'production') {
375
- (0, _warning.warnOnce)(['MUI X: 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, for example `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/persistence/.'], 'error');
375
+ (0, _warning.warnOnce)(['MUI X: 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, for example `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/persistence/.'], 'error');
376
376
  }
377
377
  };
378
378
  try {
@@ -456,7 +456,7 @@ const useGridRowEditing = (apiRef, props) => {
456
456
  if (onProcessRowUpdateError) {
457
457
  onProcessRowUpdateError(errorThrown);
458
458
  } else if (process.env.NODE_ENV !== 'production') {
459
- (0, _warning.warnOnce)(['MUI X: 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, for example `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/persistence/.'], 'error');
459
+ (0, _warning.warnOnce)(['MUI X: 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, for example `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/persistence/.'], 'error');
460
460
  }
461
461
  };
462
462
  try {
@@ -134,4 +134,12 @@ export type GridFilterActiveItemsLookup = {
134
134
  */
135
135
  export declare const gridFilterActiveItemsLookupSelector: (args_0: import("react").RefObject<{
136
136
  state: GridStateCommunity;
137
- } | null>) => GridFilterActiveItemsLookup;
137
+ } | null>) => GridFilterActiveItemsLookup;
138
+ /**
139
+ * Get the index lookup for expanded (visible) rows only.
140
+ * Does not include collapsed children.
141
+ * @ignore - do not document.
142
+ */
143
+ export declare const gridExpandedSortedRowIndexLookupSelector: (args_0: import("react").RefObject<{
144
+ state: GridStateCommunity;
145
+ } | null>) => Record<GridRowId, number>;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.gridVisibleRowsLookupSelector = exports.gridQuickFilterValuesSelector = exports.gridFilteredTopLevelRowCountSelector = exports.gridFilteredSortedTopLevelRowEntriesSelector = exports.gridFilteredSortedRowIdsSelector = exports.gridFilteredSortedRowEntriesSelector = exports.gridFilteredRowsLookupSelector = exports.gridFilteredRowCountSelector = exports.gridFilteredDescendantRowCountSelector = exports.gridFilteredDescendantCountLookupSelector = exports.gridFilteredChildrenCountLookupSelector = exports.gridFilterModelSelector = exports.gridFilterActiveItemsSelector = exports.gridFilterActiveItemsLookupSelector = exports.gridExpandedSortedRowTreeLevelPositionLookupSelector = exports.gridExpandedSortedRowIdsSelector = exports.gridExpandedSortedRowEntriesSelector = exports.gridExpandedRowCountSelector = void 0;
6
+ exports.gridVisibleRowsLookupSelector = exports.gridQuickFilterValuesSelector = exports.gridFilteredTopLevelRowCountSelector = exports.gridFilteredSortedTopLevelRowEntriesSelector = exports.gridFilteredSortedRowIdsSelector = exports.gridFilteredSortedRowEntriesSelector = exports.gridFilteredRowsLookupSelector = exports.gridFilteredRowCountSelector = exports.gridFilteredDescendantRowCountSelector = exports.gridFilteredDescendantCountLookupSelector = exports.gridFilteredChildrenCountLookupSelector = exports.gridFilterModelSelector = exports.gridFilterActiveItemsSelector = exports.gridFilterActiveItemsLookupSelector = exports.gridExpandedSortedRowTreeLevelPositionLookupSelector = exports.gridExpandedSortedRowIndexLookupSelector = exports.gridExpandedSortedRowIdsSelector = exports.gridExpandedSortedRowEntriesSelector = exports.gridExpandedRowCountSelector = void 0;
7
7
  var _isObjectEmpty = require("@mui/x-internals/isObjectEmpty");
8
8
  var _createSelector = require("../../../utils/createSelector");
9
9
  var _gridSortingSelector = require("../sorting/gridSortingSelector");
@@ -179,4 +179,16 @@ const gridFilterActiveItemsLookupSelector = exports.gridFilterActiveItemsLookupS
179
179
  return res;
180
180
  }, {});
181
181
  return result;
182
+ });
183
+
184
+ /**
185
+ * Get the index lookup for expanded (visible) rows only.
186
+ * Does not include collapsed children.
187
+ * @ignore - do not document.
188
+ */
189
+ const gridExpandedSortedRowIndexLookupSelector = exports.gridExpandedSortedRowIndexLookupSelector = (0, _createSelector.createSelectorMemoized)(gridExpandedSortedRowIdsSelector, expandedSortedIds => {
190
+ return expandedSortedIds.reduce((acc, id, index) => {
191
+ acc[id] = index;
192
+ return acc;
193
+ }, Object.create(null));
182
194
  });
@@ -227,13 +227,13 @@ const useGridPaginationModel = (apiRef, props) => {
227
227
  React.useEffect(() => {
228
228
  apiRef.current.setState(state => {
229
229
  const isEnabled = props.pagination === true;
230
- if (state.pagination.paginationMode === props.paginationMode || state.pagination.enabled === isEnabled) {
230
+ if (state.pagination.paginationMode === props.paginationMode && state.pagination.enabled === isEnabled) {
231
231
  return state;
232
232
  }
233
233
  return (0, _extends2.default)({}, state, {
234
234
  pagination: (0, _extends2.default)({}, state.pagination, {
235
235
  paginationMode: props.paginationMode,
236
- enabled: props.pagination === true
236
+ enabled: isEnabled
237
237
  })
238
238
  });
239
239
  });
@@ -2,5 +2,6 @@ import { RefObject } from '@mui/x-internals/types';
2
2
  import { DataGridProcessedProps } from "../../../models/props/DataGridProps.js";
3
3
  import { GridPrivateApiCommunity } from "../../../models/api/gridApiCommunity.js";
4
4
  import { GridStateInitializer } from "../../utils/useGridInitializeState.js";
5
+ import type { GridConfiguration } from "../../../models/configuration/gridConfiguration.js";
5
6
  export declare const rowsStateInitializer: GridStateInitializer<Pick<DataGridProcessedProps, 'dataSource' | 'rows' | 'rowCount' | 'getRowId' | 'loading'>>;
6
- export declare const useGridRows: (apiRef: RefObject<GridPrivateApiCommunity>, props: Pick<DataGridProcessedProps, "rows" | "getRowId" | "rowCount" | "throttleRowsMs" | "signature" | "pagination" | "paginationMode" | "loading" | "dataSource">) => void;
7
+ export declare const useGridRows: (apiRef: RefObject<GridPrivateApiCommunity>, props: Pick<DataGridProcessedProps, "rows" | "getRowId" | "rowCount" | "throttleRowsMs" | "signature" | "pagination" | "paginationMode" | "loading" | "dataSource" | "processRowUpdate" | "onProcessRowUpdateError">, configuration: GridConfiguration) => void;
@@ -44,7 +44,7 @@ const rowsStateInitializer = (state, props, apiRef) => {
44
44
  });
45
45
  };
46
46
  exports.rowsStateInitializer = rowsStateInitializer;
47
- const useGridRows = (apiRef, props) => {
47
+ const useGridRows = (apiRef, props, configuration) => {
48
48
  if (process.env.NODE_ENV !== 'production') {
49
49
  try {
50
50
  // Freeze the `rows` prop so developers have a fast failure if they try to use Array.prototype.push().
@@ -57,6 +57,11 @@ const useGridRows = (apiRef, props) => {
57
57
  const lastUpdateMs = React.useRef(Date.now());
58
58
  const lastRowCount = React.useRef(props.rowCount);
59
59
  const timeout = (0, _useTimeout.useTimeout)();
60
+
61
+ // Get overridable methods from configuration
62
+ const {
63
+ setRowIndex
64
+ } = configuration.hooks.useGridRowsOverridableMethods(apiRef, props);
60
65
  const getRow = React.useCallback(id => {
61
66
  const model = (0, _gridRowsSelector.gridRowsLookupSelector)(apiRef)[id];
62
67
  if (model) {
@@ -234,39 +239,6 @@ const useGridRows = (apiRef, props) => {
234
239
  }
235
240
  return children;
236
241
  }, [apiRef]);
237
- const setRowIndex = React.useCallback((rowId, targetIndex) => {
238
- const node = (0, _gridRowsSelector.gridRowNodeSelector)(apiRef, rowId);
239
- if (!node) {
240
- throw new Error(`MUI X: No row with id #${rowId} found.`);
241
- }
242
- if (node.parent !== _gridRowsUtils.GRID_ROOT_GROUP_ID) {
243
- throw new Error(`MUI X: The row reordering do not support reordering of grouped rows yet.`);
244
- }
245
- if (node.type !== 'leaf') {
246
- throw new Error(`MUI X: The row reordering do not support reordering of footer or grouping rows.`);
247
- }
248
- apiRef.current.setState(state => {
249
- const group = (0, _gridRowsSelector.gridRowTreeSelector)(apiRef)[_gridRowsUtils.GRID_ROOT_GROUP_ID];
250
- const allRows = group.children;
251
- const oldIndex = allRows.findIndex(row => row === rowId);
252
- if (oldIndex === -1 || oldIndex === targetIndex) {
253
- return state;
254
- }
255
- logger.debug(`Moving row ${rowId} to index ${targetIndex}`);
256
- const updatedRows = [...allRows];
257
- updatedRows.splice(targetIndex, 0, updatedRows.splice(oldIndex, 1)[0]);
258
- return (0, _extends2.default)({}, state, {
259
- rows: (0, _extends2.default)({}, state.rows, {
260
- tree: (0, _extends2.default)({}, state.rows.tree, {
261
- [_gridRowsUtils.GRID_ROOT_GROUP_ID]: (0, _extends2.default)({}, group, {
262
- children: updatedRows
263
- })
264
- })
265
- })
266
- });
267
- });
268
- apiRef.current.publishEvent('rowsSet');
269
- }, [apiRef, logger]);
270
242
  const replaceRows = React.useCallback((firstRowToRender, newRows) => {
271
243
  if (props.signature === _signature.GridSignature.DataGrid && newRows.length > 1) {
272
244
  throw new Error(['MUI X: You cannot replace rows using `apiRef.current.unstable_replaceRows` on the DataGrid.', 'You need to upgrade to DataGridPro or DataGridPremium component to unlock this feature.'].join('\n'));
@@ -0,0 +1,6 @@
1
+ import { RefObject } from '@mui/x-internals/types';
2
+ import { GridRowId } from "../../../models/gridRows.js";
3
+ import { GridPrivateApiCommunity } from "../../../models/api/gridApiCommunity.js";
4
+ export declare const useGridRowsOverridableMethods: (apiRef: RefObject<GridPrivateApiCommunity>) => {
5
+ setRowIndex: (rowId: GridRowId, targetIndex: number) => void;
6
+ };
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.useGridRowsOverridableMethods = void 0;
9
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
+ var React = _interopRequireWildcard(require("react"));
11
+ var _gridRowsSelector = require("./gridRowsSelector");
12
+ var _gridRowsUtils = require("./gridRowsUtils");
13
+ const useGridRowsOverridableMethods = apiRef => {
14
+ const setRowIndex = React.useCallback((rowId, targetIndex) => {
15
+ const node = (0, _gridRowsSelector.gridRowNodeSelector)(apiRef, rowId);
16
+ if (!node) {
17
+ throw new Error(`MUI X: No row with id #${rowId} found.`);
18
+ }
19
+
20
+ // TODO: Remove irrelevant checks
21
+ if (node.parent !== _gridRowsUtils.GRID_ROOT_GROUP_ID) {
22
+ throw new Error(`MUI X: The row reordering do not support reordering of grouped rows yet.`);
23
+ }
24
+ if (node.type !== 'leaf') {
25
+ throw new Error(`MUI X: The row reordering do not support reordering of footer or grouping rows.`);
26
+ }
27
+ apiRef.current.setState(state => {
28
+ const group = (0, _gridRowsSelector.gridRowTreeSelector)(apiRef)[_gridRowsUtils.GRID_ROOT_GROUP_ID];
29
+ const allRows = group.children;
30
+ const oldIndex = allRows.findIndex(row => row === rowId);
31
+ if (oldIndex === -1 || oldIndex === targetIndex) {
32
+ return state;
33
+ }
34
+ const updatedRows = [...allRows];
35
+ updatedRows.splice(targetIndex, 0, updatedRows.splice(oldIndex, 1)[0]);
36
+ return (0, _extends2.default)({}, state, {
37
+ rows: (0, _extends2.default)({}, state.rows, {
38
+ tree: (0, _extends2.default)({}, state.rows.tree, {
39
+ [_gridRowsUtils.GRID_ROOT_GROUP_ID]: (0, _extends2.default)({}, group, {
40
+ children: updatedRows
41
+ })
42
+ })
43
+ })
44
+ });
45
+ });
46
+ apiRef.current.publishEvent('rowsSet');
47
+ }, [apiRef]);
48
+ return {
49
+ setRowIndex
50
+ };
51
+ };
52
+ exports.useGridRowsOverridableMethods = useGridRowsOverridableMethods;
@@ -99,7 +99,7 @@ const useGridScroll = (apiRef, props) => {
99
99
  });
100
100
  }
101
101
  scrollCoordinates = apiRef.current.unstable_applyPipeProcessors('scrollToIndexes', scrollCoordinates, params);
102
- if (typeof scrollCoordinates.left !== undefined || typeof scrollCoordinates.top !== undefined) {
102
+ if (typeof scrollCoordinates.left !== 'undefined' || typeof scrollCoordinates.top !== 'undefined') {
103
103
  apiRef.current.scroll(scrollCoordinates);
104
104
  return true;
105
105
  }
@@ -1,2 +1,4 @@
1
1
  import { GridConfiguration } from "../../models/configuration/gridConfiguration.js";
2
- export declare const useGridConfiguration: () => GridConfiguration;
2
+ import type { GridPrivateApiCommon } from "../../models/api/gridApiCommon.js";
3
+ import type { GridPrivateApiCommunity } from "../../models/api/gridApiCommunity.js";
4
+ export declare const useGridConfiguration: <Api extends GridPrivateApiCommon = GridPrivateApiCommunity>() => GridConfiguration<Api>;