@mui/x-data-grid-pro 8.19.0 → 8.21.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 (71) hide show
  1. package/CHANGELOG.md +174 -0
  2. package/DataGridPro/DataGridPro.js +29 -2
  3. package/components/GridRowReorderCell.js +15 -3
  4. package/components/headerFiltering/GridHeaderFilterCell.js +2 -3
  5. package/esm/DataGridPro/DataGridPro.js +29 -2
  6. package/esm/components/GridRowReorderCell.js +15 -3
  7. package/esm/components/headerFiltering/GridHeaderFilterCell.js +2 -3
  8. package/esm/hooks/features/dataSource/useGridDataSourceBasePro.js +1 -1
  9. package/esm/hooks/features/rowReorder/commonReorderConditions.d.ts +30 -0
  10. package/esm/hooks/features/rowReorder/commonReorderConditions.js +78 -0
  11. package/esm/hooks/features/rowReorder/index.d.ts +2 -1
  12. package/esm/hooks/features/rowReorder/index.js +2 -1
  13. package/esm/hooks/features/rowReorder/models.d.ts +17 -0
  14. package/esm/hooks/features/rowReorder/models.js +1 -0
  15. package/esm/hooks/features/rowReorder/reorderExecutor.d.ts +27 -0
  16. package/esm/hooks/features/rowReorder/reorderExecutor.js +29 -0
  17. package/esm/hooks/features/rowReorder/reorderValidator.d.ts +12 -0
  18. package/esm/hooks/features/rowReorder/reorderValidator.js +14 -0
  19. package/esm/hooks/features/rowReorder/types.d.ts +25 -0
  20. package/esm/hooks/features/rowReorder/types.js +1 -0
  21. package/esm/hooks/features/rowReorder/useGridRowReorder.d.ts +1 -1
  22. package/esm/hooks/features/rowReorder/useGridRowReorder.js +167 -80
  23. package/esm/hooks/features/rowReorder/utils.d.ts +82 -0
  24. package/esm/hooks/features/rowReorder/utils.js +259 -0
  25. package/esm/hooks/features/rows/useGridRowsOverridableMethods.d.ts +7 -0
  26. package/esm/hooks/features/rows/useGridRowsOverridableMethods.js +59 -0
  27. package/esm/hooks/features/treeData/treeDataReorderExecutor.d.ts +11 -0
  28. package/esm/hooks/features/treeData/treeDataReorderExecutor.js +534 -0
  29. package/esm/hooks/features/treeData/treeDataReorderValidator.d.ts +2 -0
  30. package/esm/hooks/features/treeData/treeDataReorderValidator.js +35 -0
  31. package/esm/hooks/features/treeData/useGridTreeData.d.ts +3 -3
  32. package/esm/hooks/features/treeData/useGridTreeData.js +49 -4
  33. package/esm/hooks/features/treeData/utils.d.ts +8 -0
  34. package/esm/hooks/features/treeData/utils.js +96 -0
  35. package/esm/index.js +1 -1
  36. package/esm/internals/index.d.ts +8 -0
  37. package/esm/internals/index.js +6 -0
  38. package/esm/models/dataGridProProps.d.ts +32 -4
  39. package/esm/models/gridRowOrderChangeParams.d.ts +29 -5
  40. package/hooks/features/dataSource/useGridDataSourceBasePro.js +1 -1
  41. package/hooks/features/rowReorder/commonReorderConditions.d.ts +30 -0
  42. package/hooks/features/rowReorder/commonReorderConditions.js +84 -0
  43. package/hooks/features/rowReorder/index.d.ts +2 -1
  44. package/hooks/features/rowReorder/models.d.ts +17 -0
  45. package/hooks/features/rowReorder/models.js +5 -0
  46. package/hooks/features/rowReorder/reorderExecutor.d.ts +27 -0
  47. package/hooks/features/rowReorder/reorderExecutor.js +37 -0
  48. package/hooks/features/rowReorder/reorderValidator.d.ts +12 -0
  49. package/hooks/features/rowReorder/reorderValidator.js +21 -0
  50. package/hooks/features/rowReorder/types.d.ts +25 -0
  51. package/hooks/features/rowReorder/types.js +5 -0
  52. package/hooks/features/rowReorder/useGridRowReorder.d.ts +1 -1
  53. package/hooks/features/rowReorder/useGridRowReorder.js +168 -81
  54. package/hooks/features/rowReorder/utils.d.ts +82 -0
  55. package/hooks/features/rowReorder/utils.js +286 -0
  56. package/hooks/features/rows/useGridRowsOverridableMethods.d.ts +7 -0
  57. package/hooks/features/rows/useGridRowsOverridableMethods.js +67 -0
  58. package/hooks/features/treeData/treeDataReorderExecutor.d.ts +11 -0
  59. package/hooks/features/treeData/treeDataReorderExecutor.js +541 -0
  60. package/hooks/features/treeData/treeDataReorderValidator.d.ts +2 -0
  61. package/hooks/features/treeData/treeDataReorderValidator.js +41 -0
  62. package/hooks/features/treeData/useGridTreeData.d.ts +3 -3
  63. package/hooks/features/treeData/useGridTreeData.js +48 -3
  64. package/hooks/features/treeData/utils.d.ts +8 -0
  65. package/hooks/features/treeData/utils.js +109 -0
  66. package/index.js +1 -1
  67. package/internals/index.d.ts +8 -0
  68. package/internals/index.js +53 -1
  69. package/models/dataGridProProps.d.ts +32 -4
  70. package/models/gridRowOrderChangeParams.d.ts +29 -5
  71. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -5,6 +5,180 @@
5
5
  All notable changes to this project will be documented in this file.
6
6
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
7
7
 
8
+ ## 8.21.0
9
+
10
+ _Dec 3, 2025_
11
+
12
+ We'd like to extend a big thank you to the 8 contributors who made this release possible. Here are some highlights ✨:
13
+
14
+ - ✨ Add [tick spacing property](https://mui.com/x/react-charts/axis/#tick-spacing) to charts axis to control the distance between ticks.
15
+
16
+ The following team members contributed to this release:
17
+ @alexfauquette, @bernardobelchior, @ElliottMiller, @Janpot, @JCQuintas, @romgrk, @sai6855, @siriwatknp
18
+
19
+ ### Data Grid
20
+
21
+ #### `@mui/x-data-grid@8.21.0`
22
+
23
+ - [DataGrid] Fix autosizing header width calculation (#20323) @siriwatknp
24
+ - [DataGrid] Virtualizer refactor (#19465) @romgrk
25
+
26
+ #### `@mui/x-data-grid-pro@8.21.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
27
+
28
+ Same changes as in `@mui/x-data-grid@8.21.0`.
29
+
30
+ #### `@mui/x-data-grid-premium@8.21.0` [![premium](https://mui.com/r/x-premium-svg)](https://mui.com/r/x-premium-svg-link 'Premium plan')
31
+
32
+ Same changes as in `@mui/x-data-grid-pro@8.21.0`, plus:
33
+
34
+ - [DataGridPremium] Prevent pasting to non-editable cells (#20333) @ElliottMiller
35
+
36
+ ### Date and Time Pickers
37
+
38
+ #### `@mui/x-date-pickers@8.21.0`
39
+
40
+ Internal changes.
41
+
42
+ #### `@mui/x-date-pickers-pro@8.21.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
43
+
44
+ Same changes as in `@mui/x-date-pickers@8.21.0`.
45
+
46
+ ### Charts
47
+
48
+ #### `@mui/x-charts@8.21.0`
49
+
50
+ - [charts] Fix string measuring types (#20454) @bernardobelchior
51
+ - [charts] Fix typo in performance note for CustomLineMarks demo (#20529) @sai6855
52
+ - [charts] Introduce the notion of series with positions (#20461) @alexfauquette
53
+ - [charts] Migrate from sinon to Vitest mocking utilities for x-charts\* packages (#20444) @Copilot
54
+ - [charts] Move series-level values to series computed data in bar plot (#20467) @bernardobelchior
55
+ - [charts] Refactor bar chart components in preparation for range bar chart (#20521) @bernardobelchior
56
+ - [charts] Remove unnecessary `any` types (#20527) @sai6855
57
+ - [charts] Remove unused `drawingArea` from `findClosestPoints` (#20471) @bernardobelchior
58
+ - [charts] Revert `useIsHydrated` to default=false (#20511) @JCQuintas
59
+ - [charts] Support tooltip anchor position for radar (#20422) @alexfauquette
60
+ - [charts] Add tick spacing property (#20282) @bernardobelchior
61
+ - [charts] Fix Vitest lint error (#20550) @bernardobelchior
62
+ - [charts] Fix infinite loop when highlighting pie slices or scatter points (#20549) @bernardobelchior
63
+
64
+ #### `@mui/x-charts-pro@8.21.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
65
+
66
+ Same changes as in `@mui/x-charts@8.21.0`, plus:
67
+
68
+ - [charts-pro] Add support for `anchor="node"` on Sankey tooltip (#20462) @alexfauquette
69
+
70
+ #### `@mui/x-charts-premium@8.21.0` [![premium](https://mui.com/r/x-premium-svg)](https://mui.com/r/x-premium-svg-link 'Premium plan')
71
+
72
+ Same changes as in `@mui/x-charts-pro@8.21.0`.
73
+
74
+ ### Tree View
75
+
76
+ #### `@mui/x-tree-view@8.21.0`
77
+
78
+ Internal changes.
79
+
80
+ #### `@mui/x-tree-view-pro@8.21.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
81
+
82
+ Same changes as in `@mui/x-tree-view@8.21.0`.
83
+
84
+ ### Codemod
85
+
86
+ #### `@mui/x-codemod@8.21.0`
87
+
88
+ Internal changes.
89
+
90
+ ### Docs
91
+
92
+ - [docs] Migrate to `next/font` for fonts loading (#20407) @Copilot
93
+
94
+ ### Core
95
+
96
+ - [code-infra] Enable vitest eslint plugin (#20530) @Janpot
97
+ - [code-infra] Fix missing font loading for local fonts (#20480) @Janpot
98
+ - [internal] Performance: use raw `useSyncExternalStore` (#20447) @romgrk
99
+ - [code-infra] Enable `vitest/expect-expect` and `vitest/no-standalone-expect` rules for x-charts packages (#20535) @Copilot
100
+
101
+ ### Miscellaneous
102
+
103
+ - Bump @types/d3-sankey to ^0.12.5 (#20489) @renovate[bot]
104
+ - Bump @types/react to 19.2.7 (#20490) @renovate[bot]
105
+ - Bump @types/yargs to ^17.0.35 (#20491) @renovate[bot]
106
+ - Bump Vite & Vitest to ^4.0.14 (#20500) @renovate[bot]
107
+ - Bump csstype to ^3.2.3 (#20493) @renovate[bot]
108
+ - Bump es-toolkit to ^1.42.0 (#20494) @renovate[bot]
109
+ - Bump eslint to ^8.48.0 (#20495) @renovate[bot]
110
+ - Bump lerna to ^9.0.3 (#20496) @renovate[bot]
111
+ - Bump lucide-react to ^0.555.0 (#20502) @renovate[bot]
112
+ - Bump playwright monorepo (#20503) @renovate[bot]
113
+ - Bump pnpm to 10.24.0 (#20504) @renovate[bot]
114
+ - Bump react monorepo (#20340) @renovate[bot]
115
+ - Bump react-hook-form to ^7.66.1 (#20497) @renovate[bot]
116
+ - Bump rimraf to ^6.1.2 (#20498) @renovate[bot]
117
+ - Bump webpack-bundle-analyzer to ^5.0.1 (#20508) @renovate[bot]
118
+ - Bump next to ^15.5.6 [SECURITY] (#20555) @renovate[bot]
119
+
120
+ ## 8.20.0
121
+
122
+ _Nov 26, 2025_
123
+
124
+ We'd like to extend a big thank you to the 8 contributors who made this release possible. Here are some highlights ✨:
125
+
126
+ - 🔃 Data Grid tree data now supports row reordering. See the [Drag-and-drop tree data reordering](https://mui.com/x/react-data-grid/tree-data/#drag-and-drop-tree-data-reordering) section for more details.
127
+ - 🐞 Bugfixes
128
+
129
+ The following team members contributed to this release:
130
+ @alexfauquette, @arminmeh, @bernardobelchior, @cherniavskii, @siriwatknp, @JCQuintas, @MBilalShafi, @prakhargupta1
131
+
132
+ ### Data Grid
133
+
134
+ #### `@mui/x-data-grid@8.20.0`
135
+
136
+ - [DataGrid] Fix RTL virtualization to display columns when viewport width is larger than the grid (#20409) @siriwatknp
137
+ - [DataGrid] Fix row range selection (#20442) @arminmeh
138
+ - [DataGrid] Initialize data grid core packages (#20276) @cherniavskii
139
+ - [DataGrid] Improve accessibility of the sort icon (#20430) @arminmeh
140
+ - [DataGrid] Use `viewport` as a boundary for the `BasePopper` flip (#20311) @arminmeh
141
+
142
+ #### `@mui/x-data-grid-pro@8.20.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
143
+
144
+ Same changes as in `@mui/x-data-grid@8.20.0`, plus:
145
+
146
+ - [DataGridPro] Avoid automatic scroll back to the focused header filter after it leaves the viewport (#20416) @arminmeh
147
+ - [DataGridPro] Tree data row reordering (#19401) @MBilalShafi
148
+
149
+ #### `@mui/x-data-grid-premium@8.20.0` [![premium](https://mui.com/r/x-premium-svg)](https://mui.com/r/x-premium-svg-link 'Premium plan')
150
+
151
+ Same changes as in `@mui/x-data-grid-pro@8.20.0`.
152
+
153
+ ### Charts
154
+
155
+ #### `@mui/x-charts@8.20.0`
156
+
157
+ - [charts] Fix item tooltip position with node anchor (#20421) @alexfauquette
158
+ - [charts] Fix radar item tooltip closing bug (#20429) @alexfauquette
159
+ - [charts] Move series processing to selector (#20388) @JCQuintas
160
+ - [charts] Prevent pointer out from removing controlled highlight (#20385) @alexfauquette
161
+
162
+ #### `@mui/x-charts-pro@8.20.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
163
+
164
+ Same changes as in `@mui/x-charts@8.20.0`, plus:
165
+
166
+ - [charts-pro] Fix Content-Security-Policy nonce not being correctly set on export (#20395) @bernardobelchior
167
+ - [charts-pro] Improve vertical zoom slider thumb on mobile (#20439) @bernardobelchior
168
+ - [charts-pro] Provide arguments to the `AreaPlotRoot` styled component (#20414) @arminmeh
169
+ - [charts-pro] Remove grid outside the drawing area (#20412) @alexfauquette
170
+
171
+ #### `@mui/x-charts-premium@8.20.0` [![premium](https://mui.com/r/x-premium-svg)](https://mui.com/r/x-premium-svg-link 'Premium plan')
172
+
173
+ Same changes as in `@mui/x-charts-pro@8.20.0`, plus:
174
+
175
+ - [charts-premium] Add explicit return type to `ChartsRenderer` for better compatibility with React 18 (#20413) @arminmeh
176
+
177
+ ### Docs
178
+
179
+ - [docs] Add `llms.txt` link to the sidebar (#20312) @siriwatknp
180
+ - [docs] Add a line chart demo for the Overview section (#20239) @prakhargupta1
181
+
8
182
  ## 8.19.0
9
183
 
10
184
  _Nov 20, 2025_
@@ -15,6 +15,7 @@ var _xDataGrid = require("@mui/x-data-grid");
15
15
  var _internals = require("@mui/x-data-grid/internals");
16
16
  var _material = require("@mui/x-data-grid/material");
17
17
  var _forwardRef = require("@mui/x-internals/forwardRef");
18
+ var _useGridRowsOverridableMethods = require("../hooks/features/rows/useGridRowsOverridableMethods");
18
19
  var _useDataGridProComponent = require("./useDataGridProComponent");
19
20
  var _useDataGridProProps = require("./useDataGridProProps");
20
21
  var _propValidation = require("../internals/propValidation");
@@ -26,14 +27,14 @@ const configuration = {
26
27
  useCSSVariables: _material.useMaterialCSSVariables,
27
28
  useGridAriaAttributes: _useGridAriaAttributes.useGridAriaAttributesPro,
28
29
  useGridRowAriaAttributes: _useGridRowAriaAttributes.useGridRowAriaAttributesPro,
29
- useGridRowsOverridableMethods: _internals.useGridRowsOverridableMethods,
30
+ useGridRowsOverridableMethods: _useGridRowsOverridableMethods.useGridRowsOverridableMethods,
30
31
  useGridParamsOverridableMethods: _internals.useGridParamsOverridableMethods,
31
32
  useIsCellEditable: _internals.useIsCellEditable,
32
33
  useCellAggregationResult: () => null,
33
34
  useFilterValueGetter: apiRef => apiRef.current.getRowValue
34
35
  }
35
36
  };
36
- const releaseInfo = "MTc2MzU5NjgwMDAwMA==";
37
+ const releaseInfo = "MTc2NDgwNjQwMDAwMA==";
37
38
  const watermark = /*#__PURE__*/(0, _jsxRuntime.jsx)(_xLicense.Watermark, {
38
39
  packageName: "x-data-grid-pro",
39
40
  releaseInfo: releaseInfo
@@ -468,12 +469,29 @@ DataGridProRaw.propTypes = {
468
469
  * @returns {boolean} A boolean indicating if the group is expanded.
469
470
  */
470
471
  isGroupExpandedByDefault: _propTypes.default.func,
472
+ /**
473
+ * Indicates whether a row is reorderable.
474
+ * @param {object} params With all properties from the row.
475
+ * @param {R} params.row The row model of the row that the current cell belongs to.
476
+ * @param {GridTreeNode} params.rowNode The node of the row that the current cell belongs to.
477
+ * @returns {boolean} A boolean indicating if the row is reorderable.
478
+ */
479
+ isRowReorderable: _propTypes.default.func,
471
480
  /**
472
481
  * Determines if a row can be selected.
473
482
  * @param {GridRowParams} params With all properties from [[GridRowParams]].
474
483
  * @returns {boolean} A boolean indicating if the row is selectable.
475
484
  */
476
485
  isRowSelectable: _propTypes.default.func,
486
+ /**
487
+ * Indicates if a row reorder attempt is valid.
488
+ * Can be used to disable certain row reorder operations based on the context.
489
+ * The internal validation is still applied, preventing unsupported use-cases.
490
+ * Use `isValidRowReorder()` to add additional validation rules to the default ones.
491
+ * @param {ReorderValidationContext} context The context object containing all information about the reorder operation.
492
+ * @returns {boolean} A boolean indicating if the reorder operation should go through.
493
+ */
494
+ isValidRowReorder: _propTypes.default.func,
477
495
  /**
478
496
  * If `true`, moving the mouse pointer outside the grid before releasing the mouse button
479
497
  * in a column re-order action will not cause the column to jump back to its original position.
@@ -990,6 +1008,15 @@ DataGridProRaw.propTypes = {
990
1008
  * @default 80
991
1009
  */
992
1010
  scrollEndThreshold: _propTypes.default.number,
1011
+ /**
1012
+ * Updates the tree path in a row model.
1013
+ * Used when reordering rows across different parents in tree data.
1014
+ * @template R
1015
+ * @param {string[]} path The new path for the row.
1016
+ * @param {R} row The row model to update.
1017
+ * @returns {R} The updated row model with the new path.
1018
+ */
1019
+ setTreeDataPath: _propTypes.default.func,
993
1020
  /**
994
1021
  * If `true`, vertical borders will be displayed between cells.
995
1022
  * @default false
@@ -44,9 +44,21 @@ function GridRowReorderCell(params) {
44
44
  params.row.__reorder__ || (params.rowNode.type === 'group' ? params.rowNode.groupingKey ?? params.id : params.id);
45
45
  const cellRef = React.useRef(null);
46
46
  const listenerNodeRef = React.useRef(null);
47
-
48
- // TODO: remove sortModel and treeData checks once row reorder is compatible
49
- const isDraggable = React.useMemo(() => !!rootProps.rowReordering && !sortModel.length && !rootProps.treeData && Object.keys(editRowsState).length === 0, [rootProps.rowReordering, sortModel, rootProps.treeData, editRowsState]);
47
+ const isRowReorderable = rootProps.isRowReorderable;
48
+ // TODO: remove sortModel check once row reorder is compatible
49
+ const isDraggable = React.useMemo(() => {
50
+ const baseCondition = !!rootProps.rowReordering && !sortModel.length && Object.keys(editRowsState).length === 0;
51
+ if (!baseCondition) {
52
+ return false;
53
+ }
54
+ if (isRowReorderable) {
55
+ return isRowReorderable({
56
+ row: params.row,
57
+ rowNode: params.rowNode
58
+ });
59
+ }
60
+ return true;
61
+ }, [rootProps.rowReordering, isRowReorderable, sortModel, editRowsState, params.row, params.rowNode]);
50
62
  const ownerState = {
51
63
  isDraggable,
52
64
  classes: rootProps.classes
@@ -150,10 +150,9 @@ const GridHeaderFilterCell = (0, _forwardRef.forwardRef)((props, ref) => {
150
150
  focusableElement = inputRef.current;
151
151
  }
152
152
  const elementToFocus = focusableElement || cellRef.current;
153
+ const scrollPosition = apiRef.current.getScrollPosition();
153
154
  elementToFocus?.focus();
154
- if (apiRef.current.columnHeadersContainerRef.current) {
155
- apiRef.current.columnHeadersContainerRef.current.scrollLeft = 0;
156
- }
155
+ apiRef.current.scroll(scrollPosition);
157
156
  }
158
157
  }, [InputComponent, apiRef, hasFocus, isEditing, isMenuOpen]);
159
158
  const onKeyDown = React.useCallback(event => {
@@ -5,9 +5,10 @@ import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { useLicenseVerifier, Watermark } from '@mui/x-license';
7
7
  import { GridRoot, GridContextProvider } from '@mui/x-data-grid';
8
- import { validateProps, useGridApiInitialization, useGridRowsOverridableMethods, useGridParamsOverridableMethods, useIsCellEditable } from '@mui/x-data-grid/internals';
8
+ import { validateProps, useGridApiInitialization, useGridParamsOverridableMethods, useIsCellEditable } from '@mui/x-data-grid/internals';
9
9
  import { useMaterialCSSVariables } from '@mui/x-data-grid/material';
10
10
  import { forwardRef } from '@mui/x-internals/forwardRef';
11
+ import { useGridRowsOverridableMethods } from "../hooks/features/rows/useGridRowsOverridableMethods.js";
11
12
  import { useDataGridProComponent } from "./useDataGridProComponent.js";
12
13
  import { useDataGridProProps } from "./useDataGridProProps.js";
13
14
  import { propValidatorsDataGridPro } from "../internals/propValidation.js";
@@ -26,7 +27,7 @@ const configuration = {
26
27
  useFilterValueGetter: apiRef => apiRef.current.getRowValue
27
28
  }
28
29
  };
29
- const releaseInfo = "MTc2MzU5NjgwMDAwMA==";
30
+ const releaseInfo = "MTc2NDgwNjQwMDAwMA==";
30
31
  const watermark = /*#__PURE__*/_jsx(Watermark, {
31
32
  packageName: "x-data-grid-pro",
32
33
  releaseInfo: releaseInfo
@@ -461,12 +462,29 @@ DataGridProRaw.propTypes = {
461
462
  * @returns {boolean} A boolean indicating if the group is expanded.
462
463
  */
463
464
  isGroupExpandedByDefault: PropTypes.func,
465
+ /**
466
+ * Indicates whether a row is reorderable.
467
+ * @param {object} params With all properties from the row.
468
+ * @param {R} params.row The row model of the row that the current cell belongs to.
469
+ * @param {GridTreeNode} params.rowNode The node of the row that the current cell belongs to.
470
+ * @returns {boolean} A boolean indicating if the row is reorderable.
471
+ */
472
+ isRowReorderable: PropTypes.func,
464
473
  /**
465
474
  * Determines if a row can be selected.
466
475
  * @param {GridRowParams} params With all properties from [[GridRowParams]].
467
476
  * @returns {boolean} A boolean indicating if the row is selectable.
468
477
  */
469
478
  isRowSelectable: PropTypes.func,
479
+ /**
480
+ * Indicates if a row reorder attempt is valid.
481
+ * Can be used to disable certain row reorder operations based on the context.
482
+ * The internal validation is still applied, preventing unsupported use-cases.
483
+ * Use `isValidRowReorder()` to add additional validation rules to the default ones.
484
+ * @param {ReorderValidationContext} context The context object containing all information about the reorder operation.
485
+ * @returns {boolean} A boolean indicating if the reorder operation should go through.
486
+ */
487
+ isValidRowReorder: PropTypes.func,
470
488
  /**
471
489
  * If `true`, moving the mouse pointer outside the grid before releasing the mouse button
472
490
  * in a column re-order action will not cause the column to jump back to its original position.
@@ -983,6 +1001,15 @@ DataGridProRaw.propTypes = {
983
1001
  * @default 80
984
1002
  */
985
1003
  scrollEndThreshold: PropTypes.number,
1004
+ /**
1005
+ * Updates the tree path in a row model.
1006
+ * Used when reordering rows across different parents in tree data.
1007
+ * @template R
1008
+ * @param {string[]} path The new path for the row.
1009
+ * @param {R} row The row model to update.
1010
+ * @returns {R} The updated row model with the new path.
1011
+ */
1012
+ setTreeDataPath: PropTypes.func,
986
1013
  /**
987
1014
  * If `true`, vertical borders will be displayed between cells.
988
1015
  * @default false
@@ -35,9 +35,21 @@ function GridRowReorderCell(params) {
35
35
  params.row.__reorder__ || (params.rowNode.type === 'group' ? params.rowNode.groupingKey ?? params.id : params.id);
36
36
  const cellRef = React.useRef(null);
37
37
  const listenerNodeRef = React.useRef(null);
38
-
39
- // TODO: remove sortModel and treeData checks once row reorder is compatible
40
- const isDraggable = React.useMemo(() => !!rootProps.rowReordering && !sortModel.length && !rootProps.treeData && Object.keys(editRowsState).length === 0, [rootProps.rowReordering, sortModel, rootProps.treeData, editRowsState]);
38
+ const isRowReorderable = rootProps.isRowReorderable;
39
+ // TODO: remove sortModel check once row reorder is compatible
40
+ const isDraggable = React.useMemo(() => {
41
+ const baseCondition = !!rootProps.rowReordering && !sortModel.length && Object.keys(editRowsState).length === 0;
42
+ if (!baseCondition) {
43
+ return false;
44
+ }
45
+ if (isRowReorderable) {
46
+ return isRowReorderable({
47
+ row: params.row,
48
+ rowNode: params.rowNode
49
+ });
50
+ }
51
+ return true;
52
+ }, [rootProps.rowReordering, isRowReorderable, sortModel, editRowsState, params.row, params.rowNode]);
41
53
  const ownerState = {
42
54
  isDraggable,
43
55
  classes: rootProps.classes
@@ -143,10 +143,9 @@ const GridHeaderFilterCell = forwardRef((props, ref) => {
143
143
  focusableElement = inputRef.current;
144
144
  }
145
145
  const elementToFocus = focusableElement || cellRef.current;
146
+ const scrollPosition = apiRef.current.getScrollPosition();
146
147
  elementToFocus?.focus();
147
- if (apiRef.current.columnHeadersContainerRef.current) {
148
- apiRef.current.columnHeadersContainerRef.current.scrollLeft = 0;
149
- }
148
+ apiRef.current.scroll(scrollPosition);
150
149
  }
151
150
  }, [InputComponent, apiRef, hasFocus, isEditing, isMenuOpen]);
152
151
  const onKeyDown = React.useCallback(event => {
@@ -134,7 +134,7 @@ export const useGridDataSourceBasePro = (apiRef, props, options = {}) => {
134
134
  params: fetchParams,
135
135
  cause: childrenFetchError
136
136
  }));
137
- } else if (process.env.NODE_ENV !== 'production') {
137
+ } else {
138
138
  warnOnce(['MUI X: A call to `dataSource.getRows()` threw an error which was not handled because `onDataSourceError()` is missing.', 'To handle the error pass a callback to the `onDataSourceError` prop, for example `<DataGrid onDataSourceError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/server-side-data/#error-handling.'], 'error');
139
139
  }
140
140
  } finally {
@@ -0,0 +1,30 @@
1
+ import type { ReorderValidationContext as Ctx } from "./models.js";
2
+ /**
3
+ * Reusable validation conditions for row reordering validation
4
+ */
5
+ export declare const commonReorderConditions: {
6
+ isGroupToGroup: (ctx: Ctx) => boolean;
7
+ isLeafToLeaf: (ctx: Ctx) => boolean;
8
+ isLeafToGroup: (ctx: Ctx) => boolean;
9
+ isGroupToLeaf: (ctx: Ctx) => boolean;
10
+ isDropAbove: (ctx: Ctx) => boolean;
11
+ isDropBelow: (ctx: Ctx) => boolean;
12
+ sameDepth: (ctx: Ctx) => boolean;
13
+ sourceDepthGreater: (ctx: Ctx) => boolean;
14
+ targetDepthIsSourceMinusOne: (ctx: Ctx) => boolean;
15
+ sameParent: (ctx: Ctx) => boolean;
16
+ targetGroupExpanded: (ctx: Ctx) => boolean;
17
+ targetGroupCollapsed: (ctx: Ctx) => boolean;
18
+ hasPrevNode: (ctx: Ctx) => boolean;
19
+ hasNextNode: (ctx: Ctx) => boolean;
20
+ prevIsLeaf: (ctx: Ctx) => boolean;
21
+ prevIsGroup: (ctx: Ctx) => boolean;
22
+ nextIsLeaf: (ctx: Ctx) => boolean;
23
+ nextIsGroup: (ctx: Ctx) => boolean;
24
+ prevDepthEquals: (ctx: Ctx, depth: number) => boolean;
25
+ prevDepthEqualsSource: (ctx: Ctx) => boolean;
26
+ prevBelongsToSource: (ctx: Ctx) => boolean;
27
+ isAdjacentPosition: (ctx: Ctx) => boolean;
28
+ targetFirstChildIsGroupWithSourceDepth: (ctx: Ctx) => boolean;
29
+ targetFirstChildDepthEqualsSource: (ctx: Ctx) => boolean;
30
+ };
@@ -0,0 +1,78 @@
1
+ import { gridExpandedSortedRowIndexLookupSelector, gridRowTreeSelector } from '@mui/x-data-grid';
2
+ /**
3
+ * Reusable validation conditions for row reordering validation
4
+ */
5
+ export const commonReorderConditions = {
6
+ // Node type checks
7
+ isGroupToGroup: ctx => ctx.sourceNode.type === 'group' && ctx.targetNode.type === 'group',
8
+ isLeafToLeaf: ctx => ctx.sourceNode.type === 'leaf' && ctx.targetNode.type === 'leaf',
9
+ isLeafToGroup: ctx => ctx.sourceNode.type === 'leaf' && ctx.targetNode.type === 'group',
10
+ isGroupToLeaf: ctx => ctx.sourceNode.type === 'group' && ctx.targetNode.type === 'leaf',
11
+ // Drop position checks
12
+ isDropAbove: ctx => ctx.dropPosition === 'above',
13
+ isDropBelow: ctx => ctx.dropPosition === 'below',
14
+ // Depth checks
15
+ sameDepth: ctx => ctx.sourceNode.depth === ctx.targetNode.depth,
16
+ sourceDepthGreater: ctx => ctx.sourceNode.depth > ctx.targetNode.depth,
17
+ targetDepthIsSourceMinusOne: ctx => ctx.targetNode.depth === ctx.sourceNode.depth - 1,
18
+ // Parent checks
19
+ sameParent: ctx => ctx.sourceNode.parent === ctx.targetNode.parent,
20
+ // Node state checks
21
+ targetGroupExpanded: ctx => (ctx.targetNode.type === 'group' && ctx.targetNode.childrenExpanded) ?? false,
22
+ targetGroupCollapsed: ctx => ctx.targetNode.type === 'group' && !ctx.targetNode.childrenExpanded,
23
+ // Previous/Next node checks
24
+ hasPrevNode: ctx => ctx.prevNode !== null,
25
+ hasNextNode: ctx => ctx.nextNode !== null,
26
+ prevIsLeaf: ctx => ctx.prevNode?.type === 'leaf',
27
+ prevIsGroup: ctx => ctx.prevNode?.type === 'group',
28
+ nextIsLeaf: ctx => ctx.nextNode?.type === 'leaf',
29
+ nextIsGroup: ctx => ctx.nextNode?.type === 'group',
30
+ prevDepthEquals: (ctx, depth) => ctx.prevNode?.depth === depth,
31
+ prevDepthEqualsSource: ctx => ctx.prevNode?.depth === ctx.sourceNode.depth,
32
+ // Complex checks
33
+ prevBelongsToSource: ctx => {
34
+ if (!ctx.prevNode) {
35
+ return false;
36
+ }
37
+ // Check if prevNode.parent OR any of its ancestors === sourceNode.id
38
+ let currentId = ctx.prevNode.parent;
39
+ while (currentId) {
40
+ if (currentId === ctx.sourceNode.id) {
41
+ return true;
42
+ }
43
+ const node = gridRowTreeSelector(ctx.apiRef)[currentId];
44
+ if (!node) {
45
+ break;
46
+ }
47
+ currentId = node.parent;
48
+ }
49
+ return false;
50
+ },
51
+ // Position checks
52
+ isAdjacentPosition: ctx => {
53
+ const expandedSortedRowIndexLookup = gridExpandedSortedRowIndexLookupSelector(ctx.apiRef);
54
+ const sourceRowIndex = expandedSortedRowIndexLookup[ctx.sourceNode.id];
55
+ const targetRowIndex = expandedSortedRowIndexLookup[ctx.targetNode.id];
56
+ const dropPosition = ctx.dropPosition;
57
+ return dropPosition === 'above' && targetRowIndex === sourceRowIndex + 1 || dropPosition === 'below' && targetRowIndex === sourceRowIndex - 1;
58
+ },
59
+ // First child check
60
+ targetFirstChildIsGroupWithSourceDepth: ctx => {
61
+ if (ctx.targetNode.type !== 'group') {
62
+ return false;
63
+ }
64
+ const rowTree = gridRowTreeSelector(ctx.apiRef);
65
+ const targetGroup = ctx.targetNode;
66
+ const firstChild = targetGroup.children?.[0] ? rowTree[targetGroup.children[0]] : null;
67
+ return firstChild?.type === 'group' && firstChild.depth === ctx.sourceNode.depth;
68
+ },
69
+ targetFirstChildDepthEqualsSource: ctx => {
70
+ if (ctx.targetNode.type !== 'group') {
71
+ return false;
72
+ }
73
+ const rowTree = gridRowTreeSelector(ctx.apiRef);
74
+ const targetGroup = ctx.targetNode;
75
+ const firstChild = targetGroup.children?.[0] ? rowTree[targetGroup.children[0]] : null;
76
+ return firstChild ? firstChild.depth === ctx.sourceNode.depth : false;
77
+ }
78
+ };
@@ -1 +1,2 @@
1
- export * from "./gridRowReorderColDef.js";
1
+ export * from "./gridRowReorderColDef.js";
2
+ export type { ReorderValidationContext, IsRowReorderableParams } from "./models.js";
@@ -1 +1,2 @@
1
- export * from "./gridRowReorderColDef.js";
1
+ export * from "./gridRowReorderColDef.js";
2
+ export {};
@@ -0,0 +1,17 @@
1
+ import { GridTreeNode, GridValidRowModel } from '@mui/x-data-grid';
2
+ import type { RefObject } from '@mui/x-internals/types';
3
+ import type { RowReorderDropPosition, RowReorderDragDirection } from '@mui/x-data-grid/internals';
4
+ import type { GridPrivateApiPro } from "../../../models/gridApiPro.js";
5
+ export type IsRowReorderableParams<R extends GridValidRowModel = any> = {
6
+ row: R;
7
+ rowNode: GridTreeNode;
8
+ };
9
+ export type ReorderValidationContext = {
10
+ apiRef: RefObject<GridPrivateApiPro>;
11
+ sourceNode: GridTreeNode;
12
+ targetNode: GridTreeNode;
13
+ prevNode: GridTreeNode | null;
14
+ nextNode: GridTreeNode | null;
15
+ dropPosition: RowReorderDropPosition;
16
+ dragDirection: RowReorderDragDirection;
17
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,27 @@
1
+ import type { ReorderExecutionContext, ReorderOperation } from "./types.js";
2
+ /**
3
+ * Base class for all reorder operations.
4
+ * Provides abstract methods for operation detection and execution.
5
+ */
6
+ export declare abstract class BaseReorderOperation {
7
+ abstract readonly operationType: string;
8
+ /**
9
+ * Detects if this operation can handle the given context.
10
+ */
11
+ abstract detectOperation(ctx: ReorderExecutionContext): ReorderOperation | null;
12
+ /**
13
+ * Executes the detected operation.
14
+ */
15
+ abstract executeOperation(operation: ReorderOperation, ctx: ReorderExecutionContext): Promise<void> | void;
16
+ }
17
+ /**
18
+ * Executor class for handling row reorder operations in grouped data grids.
19
+ *
20
+ * This class coordinates the execution of different reorder operation types,
21
+ * trying each operation in order until one succeeds or all fail.
22
+ */
23
+ export declare class RowReorderExecutor {
24
+ private operations;
25
+ constructor(operations: BaseReorderOperation[]);
26
+ execute(ctx: ReorderExecutionContext): Promise<void>;
27
+ }
@@ -0,0 +1,29 @@
1
+ import { warnOnce } from '@mui/x-internals/warning';
2
+ /**
3
+ * Base class for all reorder operations.
4
+ * Provides abstract methods for operation detection and execution.
5
+ */
6
+ export class BaseReorderOperation {}
7
+
8
+ /**
9
+ * Executor class for handling row reorder operations in grouped data grids.
10
+ *
11
+ * This class coordinates the execution of different reorder operation types,
12
+ * trying each operation in order until one succeeds or all fail.
13
+ */
14
+ export class RowReorderExecutor {
15
+ constructor(operations) {
16
+ this.operations = operations;
17
+ }
18
+ async execute(ctx) {
19
+ for (const operation of this.operations) {
20
+ const detectedOperation = operation.detectOperation(ctx);
21
+ if (detectedOperation) {
22
+ // eslint-disable-next-line no-await-in-loop
23
+ await operation.executeOperation(detectedOperation, ctx);
24
+ return;
25
+ }
26
+ }
27
+ warnOnce(['MUI X: The parameters provided to the API method resulted in a no-op.', 'Consider looking at the documentation at https://mui.com/x/react-data-grid/row-ordering/'], 'warning');
28
+ }
29
+ }
@@ -0,0 +1,12 @@
1
+ import { ReorderValidationContext } from "./models.js";
2
+ export interface ValidationRule {
3
+ name: string;
4
+ applies: (ctx: ReorderValidationContext) => boolean;
5
+ isInvalid: (ctx: ReorderValidationContext) => boolean;
6
+ message?: string;
7
+ }
8
+ export declare class RowReorderValidator {
9
+ private rules;
10
+ constructor(rules: ValidationRule[]);
11
+ validate(context: ReorderValidationContext): boolean;
12
+ }
@@ -0,0 +1,14 @@
1
+ export class RowReorderValidator {
2
+ constructor(rules) {
3
+ this.rules = rules;
4
+ }
5
+ validate(context) {
6
+ // Check all validation rules
7
+ for (const rule of this.rules) {
8
+ if (rule.applies(context) && rule.isInvalid(context)) {
9
+ return false;
10
+ }
11
+ }
12
+ return true;
13
+ }
14
+ }
@@ -0,0 +1,25 @@
1
+ import type { GridRowId, GridTreeNode, GridRowTreeConfig } from '@mui/x-data-grid';
2
+ import type { RefObject } from '@mui/x-internals/types';
3
+ import type { RowReorderDropPosition } from '@mui/x-data-grid/internals';
4
+ import type { GridPrivateApiPro } from "../../../models/gridApiPro.js";
5
+ import type { DataGridProProcessedProps } from "../../../models/dataGridProProps.js";
6
+ export type ReorderOperationType = 'same-parent-swap' | 'cross-parent-leaf' | 'cross-parent-group' | 'drop-on-leaf' | 'drop-on-group';
7
+ export interface ReorderExecutionContext<ApiRef extends GridPrivateApiPro = GridPrivateApiPro> {
8
+ sourceRowId: GridRowId;
9
+ dropPosition: RowReorderDropPosition;
10
+ placeholderIndex: number;
11
+ sortedFilteredRowIds: GridRowId[];
12
+ sortedFilteredRowIndexLookup: Record<GridRowId, number>;
13
+ rowTree: GridRowTreeConfig;
14
+ apiRef: RefObject<ApiRef>;
15
+ processRowUpdate?: DataGridProProcessedProps['processRowUpdate'];
16
+ onProcessRowUpdateError?: DataGridProProcessedProps['onProcessRowUpdateError'];
17
+ setTreeDataPath?: DataGridProProcessedProps['setTreeDataPath'];
18
+ }
19
+ export interface ReorderOperation {
20
+ sourceNode: GridTreeNode;
21
+ targetNode: GridTreeNode;
22
+ actualTargetIndex: number;
23
+ isLastChild: boolean;
24
+ operationType: ReorderOperationType;
25
+ }