@mui/x-data-grid-pro 5.7.0 → 5.10.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 (143) hide show
  1. package/CHANGELOG.md +241 -53
  2. package/DataGridPro/DataGridPro.d.ts +7 -1
  3. package/DataGridPro/DataGridPro.js +44 -6
  4. package/DataGridPro/useDataGridProComponent.js +8 -4
  5. package/DataGridPro/useDataGridProProps.d.ts +2 -1
  6. package/DataGridPro/useDataGridProProps.js +1 -0
  7. package/LICENSE +12 -0
  8. package/README.md +6 -4
  9. package/components/DataGridProColumnHeaders.js +0 -6
  10. package/components/DataGridProVirtualScroller.js +1 -3
  11. package/components/GridDetailPanelToggleCell.js +15 -4
  12. package/components/GridGroupingCriteriaCell.d.ts +2 -5
  13. package/components/GridGroupingCriteriaCell.js +2 -74
  14. package/components/GridRowReorderCell.d.ts +5 -0
  15. package/components/GridRowReorderCell.js +72 -0
  16. package/components/GridTreeDataGroupingCell.js +15 -4
  17. package/hooks/features/columnPinning/useGridColumnPinning.js +6 -6
  18. package/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +2 -2
  19. package/hooks/features/columnReorder/useGridColumnReorder.js +3 -3
  20. package/hooks/features/columnResize/useGridColumnResize.js +18 -6
  21. package/hooks/features/detailPanel/useGridDetailPanel.js +12 -4
  22. package/hooks/features/detailPanel/useGridDetailPanelCache.js +1 -1
  23. package/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +2 -2
  24. package/hooks/features/index.d.ts +1 -0
  25. package/hooks/features/index.js +1 -0
  26. package/hooks/features/rowGrouping/gridRowGroupingUtils.d.ts +1 -1
  27. package/hooks/features/rowGrouping/useGridRowGrouping.js +6 -8
  28. package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +2 -2
  29. package/hooks/features/rowReorder/gridRowReorderColDef.d.ts +2 -0
  30. package/hooks/features/rowReorder/gridRowReorderColDef.js +18 -0
  31. package/hooks/features/rowReorder/index.d.ts +1 -0
  32. package/hooks/features/rowReorder/index.js +1 -0
  33. package/hooks/features/rowReorder/useGridRowReorder.d.ts +8 -0
  34. package/hooks/features/rowReorder/useGridRowReorder.js +111 -0
  35. package/hooks/features/rowReorder/useGridRowReorderPreProcessors.d.ts +4 -0
  36. package/hooks/features/rowReorder/useGridRowReorderPreProcessors.js +51 -0
  37. package/hooks/features/treeData/useGridTreeData.js +0 -2
  38. package/hooks/features/treeData/useGridTreeDataPreProcessors.js +2 -2
  39. package/index.d.ts +1 -1
  40. package/index.js +2 -2
  41. package/legacy/DataGridPro/DataGridPro.js +44 -6
  42. package/legacy/DataGridPro/useDataGridProComponent.js +8 -4
  43. package/legacy/DataGridPro/useDataGridProProps.js +1 -0
  44. package/legacy/components/DataGridProColumnHeaders.js +0 -6
  45. package/legacy/components/DataGridProVirtualScroller.js +1 -3
  46. package/legacy/components/GridDetailPanelToggleCell.js +15 -4
  47. package/legacy/components/GridGroupingCriteriaCell.js +2 -74
  48. package/legacy/components/GridRowReorderCell.js +74 -0
  49. package/legacy/components/GridTreeDataGroupingCell.js +15 -4
  50. package/legacy/hooks/features/columnPinning/useGridColumnPinning.js +6 -6
  51. package/legacy/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +2 -2
  52. package/legacy/hooks/features/columnReorder/useGridColumnReorder.js +3 -3
  53. package/legacy/hooks/features/columnResize/useGridColumnResize.js +18 -6
  54. package/legacy/hooks/features/detailPanel/useGridDetailPanel.js +12 -4
  55. package/legacy/hooks/features/detailPanel/useGridDetailPanelCache.js +1 -1
  56. package/legacy/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +2 -2
  57. package/legacy/hooks/features/index.js +1 -0
  58. package/legacy/hooks/features/rowGrouping/useGridRowGrouping.js +6 -8
  59. package/legacy/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +2 -2
  60. package/legacy/hooks/features/rowReorder/gridRowReorderColDef.js +20 -0
  61. package/legacy/hooks/features/rowReorder/index.js +1 -0
  62. package/legacy/hooks/features/rowReorder/useGridRowReorder.js +115 -0
  63. package/legacy/hooks/features/rowReorder/useGridRowReorderPreProcessors.js +52 -0
  64. package/legacy/hooks/features/treeData/useGridTreeData.js +0 -2
  65. package/legacy/hooks/features/treeData/useGridTreeDataPreProcessors.js +2 -2
  66. package/legacy/index.js +2 -2
  67. package/legacy/models/gridRowOrderChangeParams.js +1 -0
  68. package/legacy/models/index.js +1 -0
  69. package/legacy/utils/domUtils.js +30 -3
  70. package/legacy/utils/releaseInfo.js +1 -1
  71. package/models/dataGridProProps.d.ts +21 -8
  72. package/models/gridGroupingColDefOverride.d.ts +2 -2
  73. package/models/gridGroupingValueGetterParams.d.ts +1 -1
  74. package/models/gridRowOrderChangeParams.d.ts +18 -0
  75. package/models/gridRowOrderChangeParams.js +1 -0
  76. package/models/index.d.ts +1 -0
  77. package/models/index.js +1 -0
  78. package/modern/DataGridPro/DataGridPro.js +44 -6
  79. package/modern/DataGridPro/useDataGridProComponent.js +8 -4
  80. package/modern/DataGridPro/useDataGridProProps.js +1 -0
  81. package/modern/components/DataGridProColumnHeaders.js +0 -6
  82. package/modern/components/DataGridProVirtualScroller.js +1 -3
  83. package/modern/components/GridDetailPanelToggleCell.js +15 -4
  84. package/modern/components/GridGroupingCriteriaCell.js +2 -74
  85. package/modern/components/GridRowReorderCell.js +72 -0
  86. package/modern/components/GridTreeDataGroupingCell.js +15 -4
  87. package/modern/hooks/features/columnPinning/useGridColumnPinning.js +6 -6
  88. package/modern/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +2 -2
  89. package/modern/hooks/features/columnReorder/useGridColumnReorder.js +3 -3
  90. package/modern/hooks/features/columnResize/useGridColumnResize.js +18 -6
  91. package/modern/hooks/features/detailPanel/useGridDetailPanel.js +12 -4
  92. package/modern/hooks/features/detailPanel/useGridDetailPanelCache.js +1 -1
  93. package/modern/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +2 -2
  94. package/modern/hooks/features/index.js +1 -0
  95. package/modern/hooks/features/rowGrouping/useGridRowGrouping.js +6 -8
  96. package/modern/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +2 -2
  97. package/modern/hooks/features/rowReorder/gridRowReorderColDef.js +18 -0
  98. package/modern/hooks/features/rowReorder/index.js +1 -0
  99. package/modern/hooks/features/rowReorder/useGridRowReorder.js +111 -0
  100. package/modern/hooks/features/rowReorder/useGridRowReorderPreProcessors.js +51 -0
  101. package/modern/hooks/features/treeData/useGridTreeData.js +0 -2
  102. package/modern/hooks/features/treeData/useGridTreeDataPreProcessors.js +2 -2
  103. package/modern/index.js +2 -2
  104. package/modern/models/gridRowOrderChangeParams.js +1 -0
  105. package/modern/models/index.js +1 -0
  106. package/modern/utils/domUtils.js +30 -3
  107. package/modern/utils/releaseInfo.js +1 -1
  108. package/node/DataGridPro/DataGridPro.js +44 -6
  109. package/node/DataGridPro/useDataGridProComponent.js +9 -3
  110. package/node/DataGridPro/useDataGridProProps.js +1 -0
  111. package/node/components/DataGridProColumnHeaders.js +0 -6
  112. package/node/components/DataGridProVirtualScroller.js +1 -3
  113. package/node/components/GridDetailPanelToggleCell.js +15 -4
  114. package/node/components/GridGroupingCriteriaCell.js +1 -72
  115. package/node/components/GridRowReorderCell.js +92 -0
  116. package/node/components/GridTreeDataGroupingCell.js +15 -4
  117. package/node/hooks/features/columnPinning/useGridColumnPinning.js +5 -5
  118. package/node/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +1 -1
  119. package/node/hooks/features/columnReorder/useGridColumnReorder.js +3 -3
  120. package/node/hooks/features/columnResize/useGridColumnResize.js +18 -6
  121. package/node/hooks/features/detailPanel/useGridDetailPanel.js +11 -3
  122. package/node/hooks/features/detailPanel/useGridDetailPanelCache.js +1 -1
  123. package/node/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +1 -1
  124. package/node/hooks/features/index.js +13 -0
  125. package/node/hooks/features/rowGrouping/useGridRowGrouping.js +5 -7
  126. package/node/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +1 -1
  127. package/node/hooks/features/rowReorder/gridRowReorderColDef.js +31 -0
  128. package/node/hooks/features/rowReorder/index.js +18 -0
  129. package/node/hooks/features/rowReorder/useGridRowReorder.js +126 -0
  130. package/node/hooks/features/rowReorder/useGridRowReorderPreProcessors.js +70 -0
  131. package/node/hooks/features/treeData/useGridTreeData.js +0 -2
  132. package/node/hooks/features/treeData/useGridTreeDataPreProcessors.js +1 -1
  133. package/node/index.js +9 -9
  134. package/node/models/gridRowOrderChangeParams.js +5 -0
  135. package/node/models/index.js +13 -0
  136. package/node/utils/domUtils.js +30 -3
  137. package/node/utils/releaseInfo.js +1 -1
  138. package/package.json +7 -7
  139. package/typeOverloads/modules.d.ts +10 -7
  140. package/typeOverloads/reexports.d.ts +1 -1
  141. package/utils/domUtils.d.ts +2 -1
  142. package/utils/domUtils.js +30 -3
  143. package/utils/releaseInfo.js +1 -1
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import { GridEvents, useGridSelector, useGridApiEventHandler, useGridApiMethod } from '@mui/x-data-grid';
4
- import { useGridRegisterPreProcessor } from '@mui/x-data-grid/internals';
4
+ import { useGridRegisterPipeProcessor } from '@mui/x-data-grid/internals';
5
5
  import { GRID_DETAIL_PANEL_TOGGLE_FIELD } from './gridDetailPanelToggleColDef';
6
6
  import { gridDetailPanelExpandedRowIdsSelector, gridDetailPanelExpandedRowsContentCacheSelector, gridDetailPanelExpandedRowsHeightCacheSelector } from './gridDetailPanelSelector';
7
7
  export const detailPanelStateInitializer = (state, props) => {
@@ -35,11 +35,19 @@ export const useGridDetailPanel = (apiRef, props) => {
35
35
  apiRef.current.toggleDetailPanel(params.id);
36
36
  }, [apiRef, contentCache, props.getDetailPanelContent]);
37
37
  const handleCellKeyDown = React.useCallback((params, event) => {
38
- if (!event.ctrlKey || event.key !== 'Enter' || props.getDetailPanelContent == null) {
38
+ if (props.getDetailPanelContent == null) {
39
39
  return;
40
40
  }
41
41
 
42
- apiRef.current.toggleDetailPanel(params.id);
42
+ if ((event.ctrlKey || event.metaKey) && event.key === 'Enter') {
43
+ // TODO v6: only support Space on the detail toggle
44
+ apiRef.current.toggleDetailPanel(params.id);
45
+ return;
46
+ }
47
+
48
+ if (params.field === GRID_DETAIL_PANEL_TOGGLE_FIELD && event.key === ' ') {
49
+ apiRef.current.toggleDetailPanel(params.id);
50
+ }
43
51
  }, [apiRef, props.getDetailPanelContent]);
44
52
  useGridApiEventHandler(apiRef, GridEvents.cellClick, handleCellClick);
45
53
  useGridApiEventHandler(apiRef, GridEvents.cellKeyDown, handleCellKeyDown);
@@ -58,7 +66,7 @@ export const useGridDetailPanel = (apiRef, props) => {
58
66
 
59
67
  });
60
68
  }, [apiRef, expandedRowIds]);
61
- useGridRegisterPreProcessor(apiRef, 'rowHeight', addDetailHeight);
69
+ useGridRegisterPipeProcessor(apiRef, 'rowHeight', addDetailHeight);
62
70
  apiRef.current.unstable_updateControlState({
63
71
  stateId: 'detailPanels',
64
72
  propModel: props.detailPanelExpandedRowIds,
@@ -39,7 +39,7 @@ export const useGridDetailPanelCache = (apiRef, props) => {
39
39
  });
40
40
  apiRef.current.forceUpdate();
41
41
  }, [apiRef, props.getDetailPanelContent, props.getDetailPanelHeight]);
42
- useGridApiEventHandler(apiRef, GridEvents.visibleRowsSet, updateCaches);
42
+ useGridApiEventHandler(apiRef, GridEvents.sortedRowsSet, updateCaches);
43
43
  const isFirstRender = React.useRef(true);
44
44
 
45
45
  if (isFirstRender.current) {
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { useGridRegisterPreProcessor } from '@mui/x-data-grid/internals';
2
+ import { useGridRegisterPipeProcessor } from '@mui/x-data-grid/internals';
3
3
  import { GRID_DETAIL_PANEL_TOGGLE_FIELD, GRID_DETAIL_PANEL_TOGGLE_COL_DEF } from './gridDetailPanelToggleColDef';
4
4
  export const useGridDetailPanelPreProcessors = (apiRef, props) => {
5
5
  const addToggleColumn = React.useCallback(columnsState => {
@@ -24,5 +24,5 @@ export const useGridDetailPanelPreProcessors = (apiRef, props) => {
24
24
  columnsState.lookup[GRID_DETAIL_PANEL_TOGGLE_FIELD] = GRID_DETAIL_PANEL_TOGGLE_COL_DEF;
25
25
  return columnsState;
26
26
  }, [props.getDetailPanelContent]);
27
- useGridRegisterPreProcessor(apiRef, 'hydrateColumns', addToggleColumn);
27
+ useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', addToggleColumn);
28
28
  };
@@ -2,5 +2,6 @@ export * from './columnPinning';
2
2
  export * from './columnReorder';
3
3
  export * from './columnResize';
4
4
  export * from './rowGrouping';
5
+ export * from './rowReorder';
5
6
  export * from './treeData';
6
7
  export * from './detailPanel';
@@ -3,5 +3,6 @@ export * from './columnPinning';
3
3
  export * from './columnReorder';
4
4
  export * from './columnResize';
5
5
  export * from './rowGrouping';
6
+ export * from './rowReorder';
6
7
  export * from './treeData';
7
8
  export * from './detailPanel';
@@ -21,7 +21,7 @@ interface FilterRowTreeFromTreeDataParams {
21
21
  * - It is passing the filter
22
22
  */
23
23
  export declare const filterRowTreeFromGroupingColumns: (params: FilterRowTreeFromTreeDataParams) => Omit<GridFilterState, 'filterModel'>;
24
- export declare const getColDefOverrides: (groupingColDefProp: DataGridProProcessedProps['groupingColDef'], fields: string[]) => import("../../..").GridGroupingColDefOverride | null | undefined;
24
+ export declare const getColDefOverrides: (groupingColDefProp: DataGridProProcessedProps['groupingColDef'], fields: string[]) => import("../../..").GridGroupingColDefOverride<any> | null | undefined;
25
25
  export declare const mergeStateWithRowGroupingModel: (rowGroupingModel: GridRowGroupingModel) => (state: GridStatePro) => GridStatePro;
26
26
  export declare const setStrategyAvailability: (apiRef: React.MutableRefObject<GridApiPro>, disableRowGrouping: boolean) => void;
27
27
  export {};
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import Divider from '@mui/material/Divider';
4
4
  import { GridEvents, useGridApiEventHandler, useGridApiMethod, gridFilteredDescendantCountLookupSelector } from '@mui/x-data-grid';
5
- import { useGridRegisterPreProcessor, isDeepEqual } from '@mui/x-data-grid/internals';
5
+ import { useGridRegisterPipeProcessor, isDeepEqual } from '@mui/x-data-grid/internals';
6
6
  import { gridRowGroupingModelSelector, gridRowGroupingSanitizedModelSelector, gridRowGroupingStateSelector } from './gridRowGroupingSelector';
7
7
  import { getRowGroupingFieldFromGroupingCriteria, ROW_GROUPING_STRATEGY, isGroupingColumn, mergeStateWithRowGroupingModel, setStrategyAvailability } from './gridRowGroupingUtils';
8
8
  import { GridRowGroupableColumnMenuItems } from '../../../components/GridRowGroupableColumnMenuItems';
@@ -143,9 +143,9 @@ export const useGridRowGrouping = (apiRef, props) => {
143
143
 
144
144
  return params;
145
145
  }, [apiRef, props.disableRowGrouping]);
146
- useGridRegisterPreProcessor(apiRef, 'columnMenu', addColumnMenuButtons);
147
- useGridRegisterPreProcessor(apiRef, 'exportState', stateExportPreProcessing);
148
- useGridRegisterPreProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
146
+ useGridRegisterPipeProcessor(apiRef, 'columnMenu', addColumnMenuButtons);
147
+ useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
148
+ useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
149
149
  /**
150
150
  * EVENTS
151
151
  */
@@ -177,10 +177,8 @@ export const useGridRowGrouping = (apiRef, props) => {
177
177
  rowGrouping: _extends({}, state.rowGrouping, {
178
178
  unstable_sanitizedModelOnLastRowTreeCreation: rowGroupingModel
179
179
  })
180
- })); // Refresh the column pre-processing
181
- // TODO: Add a clean way to re-run a pipe processing without faking a change
182
-
183
- apiRef.current.updateColumns([]);
180
+ }));
181
+ apiRef.current.unstable_requestPipeProcessorsApplication('hydrateColumns');
184
182
  setStrategyAvailability(apiRef, props.disableRowGrouping); // Refresh the row tree creation strategy processing
185
183
  // TODO: Add a clean way to re-run a strategy processing without publishing a private event
186
184
 
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import { gridColumnLookupSelector, gridRowIdsSelector, gridRowTreeSelector, useFirstRender } from '@mui/x-data-grid';
4
- import { useGridRegisterPreProcessor, useGridRegisterStrategyProcessor } from '@mui/x-data-grid/internals';
4
+ import { useGridRegisterPipeProcessor, useGridRegisterStrategyProcessor } from '@mui/x-data-grid/internals';
5
5
  import { gridRowGroupingModelSelector, gridRowGroupingSanitizedModelSelector } from './gridRowGroupingSelector';
6
6
  import { createGroupingColDefForAllGroupingCriteria, createGroupingColDefForOneGroupingCriteria } from './createGroupingColDef';
7
7
  import { filterRowTreeFromGroupingColumns, getColDefOverrides, ROW_GROUPING_STRATEGY, isGroupingColumn, setStrategyAvailability } from './gridRowGroupingUtils';
@@ -177,7 +177,7 @@ export const useGridRowGroupingPreProcessors = (apiRef, props) => {
177
177
  disableChildrenSorting: false
178
178
  });
179
179
  }, [apiRef]);
180
- useGridRegisterPreProcessor(apiRef, 'hydrateColumns', updateGroupingColumn);
180
+ useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', updateGroupingColumn);
181
181
  useGridRegisterStrategyProcessor(apiRef, ROW_GROUPING_STRATEGY, 'rowTreeCreation', createRowTree);
182
182
  useGridRegisterStrategyProcessor(apiRef, ROW_GROUPING_STRATEGY, 'filtering', filterRows);
183
183
  useGridRegisterStrategyProcessor(apiRef, ROW_GROUPING_STRATEGY, 'sorting', sortRows);
@@ -0,0 +1,2 @@
1
+ import { GridColDef } from '@mui/x-data-grid';
2
+ export declare const GRID_REORDER_COL_DEF: GridColDef;
@@ -0,0 +1,18 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import { GRID_STRING_COL_DEF } from '@mui/x-data-grid';
3
+ import { renderRowReorderCell } from '../../../components/GridRowReorderCell';
4
+ export const GRID_REORDER_COL_DEF = _extends({}, GRID_STRING_COL_DEF, {
5
+ field: '__reorder__',
6
+ type: 'reorder',
7
+ sortable: false,
8
+ filterable: false,
9
+ width: 50,
10
+ align: 'center',
11
+ headerAlign: 'center',
12
+ disableColumnMenu: true,
13
+ disableExport: true,
14
+ disableReorder: true,
15
+ resizable: false,
16
+ renderHeader: () => ' ',
17
+ renderCell: renderRowReorderCell
18
+ });
@@ -0,0 +1 @@
1
+ export * from './gridRowReorderColDef';
@@ -0,0 +1 @@
1
+ export * from './gridRowReorderColDef';
@@ -0,0 +1,8 @@
1
+ import * as React from 'react';
2
+ import { GridApiPro } from '../../../models/gridApiPro';
3
+ import { DataGridProProcessedProps } from '../../../models/dataGridProProps';
4
+ /**
5
+ * Only available in DataGridPro
6
+ * @requires useGridRows (method)
7
+ */
8
+ export declare const useGridRowReorder: (apiRef: React.MutableRefObject<GridApiPro>, props: Pick<DataGridProProcessedProps, 'rowReordering' | 'onRowOrderChange' | 'classes'>) => void;
@@ -0,0 +1,111 @@
1
+ import * as React from 'react';
2
+ import { unstable_composeClasses as composeClasses } from '@mui/material';
3
+ import { useGridLogger, GridEvents, useGridApiEventHandler, getDataGridUtilityClass, useGridSelector, gridSortModelSelector, gridRowTreeDepthSelector, useGridApiOptionHandler, gridEditRowsStateSelector } from '@mui/x-data-grid';
4
+
5
+ const useUtilityClasses = ownerState => {
6
+ const {
7
+ classes
8
+ } = ownerState;
9
+ const slots = {
10
+ rowDragging: ['row--dragging']
11
+ };
12
+ return composeClasses(slots, getDataGridUtilityClass, classes);
13
+ };
14
+ /**
15
+ * Only available in DataGridPro
16
+ * @requires useGridRows (method)
17
+ */
18
+
19
+
20
+ export const useGridRowReorder = (apiRef, props) => {
21
+ const logger = useGridLogger(apiRef, 'useGridRowReorder');
22
+ const sortModel = useGridSelector(apiRef, gridSortModelSelector);
23
+ const treeDepth = useGridSelector(apiRef, gridRowTreeDepthSelector);
24
+ const dragRowNode = React.useRef(null);
25
+ const originRowIndex = React.useRef(null);
26
+ const removeDnDStylesTimeout = React.useRef();
27
+ const ownerState = {
28
+ classes: props.classes
29
+ };
30
+ const classes = useUtilityClasses(ownerState);
31
+ const [dragRowId, setDragRowId] = React.useState('');
32
+ React.useEffect(() => {
33
+ return () => {
34
+ clearTimeout(removeDnDStylesTimeout.current);
35
+ };
36
+ }, []); // TODO: remove sortModel check once row reorder is sorting compatible
37
+ // remove treeDepth once row reorder is tree compatible
38
+
39
+ const isRowReorderDisabled = React.useMemo(() => {
40
+ return !props.rowReordering || !!sortModel.length || treeDepth !== 1;
41
+ }, [props.rowReordering, sortModel, treeDepth]);
42
+ const handleDragStart = React.useCallback((params, event) => {
43
+ // Call the gridEditRowsStateSelector directly to avoid infnite loop
44
+ const editRowsState = gridEditRowsStateSelector(apiRef.current.state);
45
+
46
+ if (isRowReorderDisabled || Object.keys(editRowsState).length !== 0) {
47
+ return;
48
+ }
49
+
50
+ logger.debug(`Start dragging row ${params.id}`); // Prevent drag events propagation.
51
+ // For more information check here https://github.com/mui/mui-x/issues/2680.
52
+
53
+ event.stopPropagation();
54
+ dragRowNode.current = event.currentTarget;
55
+ dragRowNode.current.classList.add(classes.rowDragging);
56
+ setDragRowId(params.id);
57
+ removeDnDStylesTimeout.current = setTimeout(() => {
58
+ dragRowNode.current.classList.remove(classes.rowDragging);
59
+ });
60
+ originRowIndex.current = apiRef.current.getRowIndex(params.id);
61
+ }, [isRowReorderDisabled, classes.rowDragging, logger, apiRef]);
62
+ const handleDragOver = React.useCallback((params, event) => {
63
+ logger.debug(`Dragging over row ${params.id}`);
64
+ event.preventDefault(); // Prevent drag events propagation.
65
+ // For more information check here https://github.com/mui/mui-x/issues/2680.
66
+
67
+ event.stopPropagation();
68
+
69
+ if (params.id !== dragRowId) {
70
+ const targetRowIndex = apiRef.current.getRowIndex(params.id);
71
+ apiRef.current.setRowIndex(dragRowId, targetRowIndex);
72
+ }
73
+ }, [apiRef, logger, dragRowId]);
74
+ const handleDragEnd = React.useCallback((params, event) => {
75
+ // Call the gridEditRowsStateSelector directly to avoid infnite loop
76
+ const editRowsState = gridEditRowsStateSelector(apiRef.current.state);
77
+
78
+ if (isRowReorderDisabled || Object.keys(editRowsState).length !== 0) {
79
+ return;
80
+ }
81
+
82
+ logger.debug('End dragging row');
83
+ event.preventDefault(); // Prevent drag events propagation.
84
+ // For more information check here https://github.com/mui/mui-x/issues/2680.
85
+
86
+ event.stopPropagation();
87
+ clearTimeout(removeDnDStylesTimeout.current);
88
+ dragRowNode.current = null; // Check if the row was dropped outside the grid.
89
+
90
+ if (event.dataTransfer.dropEffect === 'none') {
91
+ // Accessing params.field may contain the wrong field as header elements are reused
92
+ apiRef.current.setRowIndex(dragRowId, originRowIndex.current);
93
+ originRowIndex.current = null;
94
+ } else {
95
+ // Emit the rowOrderChange event only once when the reordering stops.
96
+ const rowOrderChangeParams = {
97
+ row: apiRef.current.getRow(dragRowId),
98
+ targetIndex: apiRef.current.getRowIndex(params.id),
99
+ oldIndex: originRowIndex.current
100
+ };
101
+ apiRef.current.publishEvent(GridEvents.rowOrderChange, rowOrderChangeParams);
102
+ }
103
+
104
+ setDragRowId('');
105
+ }, [isRowReorderDisabled, logger, apiRef, dragRowId]);
106
+ useGridApiEventHandler(apiRef, GridEvents.rowDragStart, handleDragStart);
107
+ useGridApiEventHandler(apiRef, GridEvents.rowDragOver, handleDragOver);
108
+ useGridApiEventHandler(apiRef, GridEvents.rowDragEnd, handleDragEnd);
109
+ useGridApiEventHandler(apiRef, GridEvents.cellDragOver, handleDragOver);
110
+ useGridApiOptionHandler(apiRef, GridEvents.rowOrderChange, props.onRowOrderChange);
111
+ };
@@ -0,0 +1,4 @@
1
+ import * as React from 'react';
2
+ import { GridApiCommunity } from '@mui/x-data-grid/internals';
3
+ import { DataGridProProcessedProps } from '@mui/x-data-grid-pro/models/dataGridProProps';
4
+ export declare const useGridRowReorderPreProcessors: (apiRef: React.MutableRefObject<GridApiCommunity>, props: DataGridProProcessedProps) => void;
@@ -0,0 +1,51 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import * as React from 'react';
3
+ import { unstable_composeClasses as composeClasses } from '@mui/material';
4
+ import { getDataGridUtilityClass } from '@mui/x-data-grid';
5
+ import { useGridRegisterPipeProcessor } from '@mui/x-data-grid/internals';
6
+ import { GRID_REORDER_COL_DEF } from './gridRowReorderColDef';
7
+
8
+ const useUtilityClasses = ownerState => {
9
+ const {
10
+ classes
11
+ } = ownerState;
12
+ return React.useMemo(() => {
13
+ const slots = {
14
+ rowReorderCellContainer: ['rowReorderCellContainer'],
15
+ columnHeaderReorder: ['columnHeaderReorder']
16
+ };
17
+ return composeClasses(slots, getDataGridUtilityClass, classes);
18
+ }, [classes]);
19
+ };
20
+
21
+ export const useGridRowReorderPreProcessors = (apiRef, props) => {
22
+ const ownerState = {
23
+ classes: props.classes
24
+ };
25
+ const classes = useUtilityClasses(ownerState);
26
+ const updateReorderColumn = React.useCallback(columnsState => {
27
+ const reorderColumn = _extends({}, GRID_REORDER_COL_DEF, {
28
+ cellClassName: classes.rowReorderCellContainer,
29
+ headerClassName: classes.columnHeaderReorder,
30
+ headerName: apiRef.current.getLocaleText('rowReorderingHeaderName')
31
+ });
32
+
33
+ const shouldHaveReorderColumn = props.rowReordering;
34
+ const haveReorderColumn = columnsState.lookup[reorderColumn.field] != null;
35
+
36
+ if (shouldHaveReorderColumn && haveReorderColumn) {
37
+ return columnsState;
38
+ }
39
+
40
+ if (shouldHaveReorderColumn && !haveReorderColumn) {
41
+ columnsState.lookup[reorderColumn.field] = reorderColumn;
42
+ columnsState.all = [reorderColumn.field, ...columnsState.all];
43
+ } else if (!shouldHaveReorderColumn && haveReorderColumn) {
44
+ delete columnsState.lookup[reorderColumn.field];
45
+ columnsState.all = columnsState.all.filter(field => field !== reorderColumn.field);
46
+ }
47
+
48
+ return columnsState;
49
+ }, [apiRef, classes, props.rowReordering]);
50
+ useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', updateReorderColumn);
51
+ };
@@ -14,8 +14,6 @@ export const useGridTreeData = apiRef => {
14
14
  if (cellParams.colDef.type === 'treeDataGroup' && event.key === ' ' && !event.shiftKey) {
15
15
  var _gridFilteredDescenda;
16
16
 
17
- event.stopPropagation();
18
- event.preventDefault();
19
17
  const filteredDescendantCount = (_gridFilteredDescenda = gridFilteredDescendantCountLookupSelector(apiRef)[params.id]) != null ? _gridFilteredDescenda : 0;
20
18
 
21
19
  if (filteredDescendantCount === 0) {
@@ -3,7 +3,7 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
3
3
  const _excluded = ["hideDescendantCount"];
4
4
  import * as React from 'react';
5
5
  import { gridRowIdsSelector, gridRowTreeSelector, useFirstRender } from '@mui/x-data-grid';
6
- import { useGridRegisterPreProcessor, useGridRegisterStrategyProcessor } from '@mui/x-data-grid/internals';
6
+ import { useGridRegisterPipeProcessor, useGridRegisterStrategyProcessor } from '@mui/x-data-grid/internals';
7
7
  import { GRID_TREE_DATA_GROUPING_COL_DEF, GRID_TREE_DATA_GROUPING_COL_DEF_FORCED_PROPERTIES } from './gridTreeDataGroupColDef';
8
8
  import { filterRowTreeFromTreeData, TREE_DATA_STRATEGY } from './gridTreeDataUtils';
9
9
  import { GridTreeDataGroupingCell } from '../../../components';
@@ -112,7 +112,7 @@ export const useGridTreeDataPreProcessors = (apiRef, props) => {
112
112
  disableChildrenSorting: props.disableChildrenSorting
113
113
  });
114
114
  }, [apiRef, props.disableChildrenSorting]);
115
- useGridRegisterPreProcessor(apiRef, 'hydrateColumns', updateGroupingColumn);
115
+ useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', updateGroupingColumn);
116
116
  useGridRegisterStrategyProcessor(apiRef, TREE_DATA_STRATEGY, 'rowTreeCreation', createRowTree);
117
117
  useGridRegisterStrategyProcessor(apiRef, TREE_DATA_STRATEGY, 'filtering', filterRows);
118
118
  useGridRegisterStrategyProcessor(apiRef, TREE_DATA_STRATEGY, 'sorting', sortRows);
package/index.d.ts CHANGED
@@ -6,8 +6,8 @@ export * from '@mui/x-data-grid/hooks';
6
6
  export * from '@mui/x-data-grid/locales';
7
7
  export * from '@mui/x-data-grid/models';
8
8
  export * from '@mui/x-data-grid/context';
9
- export * from '@mui/x-data-grid/colDef';
10
9
  export * from '@mui/x-data-grid/utils';
10
+ export * from '@mui/x-data-grid/colDef';
11
11
  export * from './DataGridPro';
12
12
  export * from './hooks';
13
13
  export * from './models';
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.7.0
1
+ /** @license MUI v5.10.0
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -11,8 +11,8 @@ export * from '@mui/x-data-grid/hooks';
11
11
  export * from '@mui/x-data-grid/locales';
12
12
  export * from '@mui/x-data-grid/models';
13
13
  export * from '@mui/x-data-grid/context';
14
- export * from '@mui/x-data-grid/colDef';
15
14
  export * from '@mui/x-data-grid/utils';
15
+ export * from '@mui/x-data-grid/colDef';
16
16
  export * from './DataGridPro';
17
17
  export * from './hooks';
18
18
  export * from './models';
@@ -353,7 +353,8 @@ DataGridProRaw.propTypes = {
353
353
  * Determines the path of a row in the tree data.
354
354
  * For instance, a row with the path ["A", "B"] is the child of the row with the path ["A"].
355
355
  * Note that all paths must contain at least one element.
356
- * @param {GridRowModel} row The row from which we want the path.
356
+ * @template R
357
+ * @param {R} row The row from which we want the path.
357
358
  * @returns {string[]} The path to the row.
358
359
  */
359
360
  getTreeDataPath: PropTypes.func,
@@ -617,7 +618,7 @@ DataGridProRaw.propTypes = {
617
618
  * @param {GridEditCellPropsParams} params With all properties from [[GridEditCellPropsParams]].
618
619
  * @param {MuiEvent<React.SyntheticEvent>} event The event that caused this prop to be called.
619
620
  * @param {GridCallbackDetails} details Additional details for this callback.
620
- * @deprecated use `preProcessEditCellProps` from the [`GridColDef`](/api/data-grid/grid-col-def/)
621
+ * @deprecated use `preProcessEditCellProps` from the [`GridColDef`](/x/api/data-grid/grid-col-def/)
621
622
  */
622
623
  onEditCellPropsChange: PropTypes.func,
623
624
 
@@ -664,6 +665,28 @@ DataGridProRaw.propTypes = {
664
665
  */
665
666
  onPinnedColumnsChange: PropTypes.func,
666
667
 
668
+ /**
669
+ * Callback fired when the preferences panel is closed.
670
+ * @param {GridPreferencePanelParams} params With all properties from [[GridPreferencePanelParams]].
671
+ * @param {MuiEvent<{}>} event The event object.
672
+ * @param {GridCallbackDetails} details Additional details for this callback.
673
+ */
674
+ onPreferencePanelClose: PropTypes.func,
675
+
676
+ /**
677
+ * Callback fired when the preferences panel is opened.
678
+ * @param {GridPreferencePanelParams} params With all properties from [[GridPreferencePanelParams]].
679
+ * @param {MuiEvent<{}>} event The event object.
680
+ * @param {GridCallbackDetails} details Additional details for this callback.
681
+ */
682
+ onPreferencePanelOpen: PropTypes.func,
683
+
684
+ /**
685
+ * Callback called when `processRowUpdate` throws an error or rejects.
686
+ * @param {any} error The error thrown.
687
+ */
688
+ onProcessRowUpdateError: PropTypes.func,
689
+
667
690
  /**
668
691
  * Callback fired when the grid is resized.
669
692
  * @param {ElementSize} containerSize With all properties from [[ElementSize]].
@@ -717,6 +740,14 @@ DataGridProRaw.propTypes = {
717
740
  */
718
741
  onRowGroupingModelChange: PropTypes.func,
719
742
 
743
+ /**
744
+ * Callback fired when a row is being reordered.
745
+ * @param {GridRowOrderChangeParams} params With all properties from [[GridRowOrderChangeParams]].
746
+ * @param {MuiEvent<{}>} event The event object.
747
+ * @param {GridCallbackDetails} details Additional details for this callback.
748
+ */
749
+ onRowOrderChange: PropTypes.func,
750
+
720
751
  /**
721
752
  * Callback fired when scrolling to the bottom of the grid viewport.
722
753
  * @param {GridRowScrollEndParams} params With all properties from [[GridRowScrollEndParams]].
@@ -786,9 +817,10 @@ DataGridProRaw.propTypes = {
786
817
  /**
787
818
  * Callback called before updating a row with new values in the row and cell editing.
788
819
  * Only applied if `props.experimentalFeatures.newEditingApi: true`.
789
- * @param {GridRowModel} newRow Row object with the new values.
790
- * @param {GridRowModel} oldRow Row object with the old values.
791
- * @returns {Promise<GridRowModel> | GridRowModel} The final values to update the row.
820
+ * @template R
821
+ * @param {R} newRow Row object with the new values.
822
+ * @param {R} oldRow Row object with the old values.
823
+ * @returns {Promise<R> | R} The final values to update the row.
792
824
  */
793
825
  processRowUpdate: PropTypes.func,
794
826
 
@@ -822,10 +854,16 @@ DataGridProRaw.propTypes = {
822
854
  */
823
855
  rowHeight: PropTypes.number,
824
856
 
857
+ /**
858
+ * If `true`, the reordering of rows is enabled.
859
+ * @default false
860
+ */
861
+ rowReordering: PropTypes.bool,
862
+
825
863
  /**
826
864
  * Set of rows of type [[GridRowsProp]].
827
865
  */
828
- rows: PropTypes.arrayOf(PropTypes.object).isRequired,
866
+ rows: PropTypes.array.isRequired,
829
867
 
830
868
  /**
831
869
  * Sets the type of space between rows added by `getRowSpacing`.
@@ -1,4 +1,4 @@
1
- import { useGridInitialization, useGridInitializeState, useGridClipboard, useGridColumnMenu, useGridColumns, columnsStateInitializer, useGridDensity, useGridCsvExport, useGridPrintExport, useGridFilter, filterStateInitializer, useGridFocus, useGridKeyboard, useGridKeyboardNavigation, useGridPagination, paginationStateInitializer, useGridPreferencesPanel, useGridEditing_new, useGridEditing_old, editingStateInitializer_old, editingStateInitializer_new, useGridRows, useGridRowsPreProcessors, rowsStateInitializer, useGridRowsMeta, useGridParamsApi, useGridSelection, useGridSorting, sortingStateInitializer, useGridScroll, useGridEvents, useGridDimensions, useGridStatePersistence, useGridSelectionPreProcessors, columnMenuStateInitializer, densityStateInitializer, focusStateInitializer, preferencePanelStateInitializer, rowsMetaStateInitializer, selectionStateInitializer } from '@mui/x-data-grid/internals';
1
+ import { useGridInitialization, useGridInitializeState, useGridClipboard, useGridColumnMenu, useGridColumns, columnsStateInitializer, useGridDensity, useGridCsvExport, useGridPrintExport, useGridFilter, filterStateInitializer, useGridFocus, useGridKeyboardNavigation, useGridPagination, paginationStateInitializer, useGridPreferencesPanel, useGridEditing_new, useGridEditing_old, editingStateInitializer_old, editingStateInitializer_new, useGridRows, useGridRowsPreProcessors, rowsStateInitializer, useGridRowsMeta, useGridParamsApi, useGridSelection, useGridSorting, sortingStateInitializer, useGridScroll, useGridEvents, useGridDimensions, useGridStatePersistence, useGridSelectionPreProcessors, useGridColumnSpanning, columnMenuStateInitializer, densityStateInitializer, focusStateInitializer, preferencePanelStateInitializer, rowsMetaStateInitializer, selectionStateInitializer } from '@mui/x-data-grid/internals';
2
2
  // Pro-only features
3
3
  import { useGridInfiniteLoader } from '../hooks/features/infiniteLoader/useGridInfiniteLoader';
4
4
  import { useGridColumnReorder, columnReorderStateInitializer } from '../hooks/features/columnReorder/useGridColumnReorder';
@@ -12,6 +12,8 @@ import { useGridColumnPinningPreProcessors } from '../hooks/features/columnPinni
12
12
  import { useGridDetailPanel, detailPanelStateInitializer } from '../hooks/features/detailPanel/useGridDetailPanel';
13
13
  import { useGridDetailPanelCache } from '../hooks/features/detailPanel/useGridDetailPanelCache';
14
14
  import { useGridDetailPanelPreProcessors } from '../hooks/features/detailPanel/useGridDetailPanelPreProcessors';
15
+ import { useGridRowReorder } from '../hooks/features/rowReorder/useGridRowReorder';
16
+ import { useGridRowReorderPreProcessors } from '../hooks/features/rowReorder/useGridRowReorderPreProcessors';
15
17
  export var useDataGridProComponent = function useDataGridProComponent(inputApiRef, props) {
16
18
  var _props$experimentalFe, _props$experimentalFe2;
17
19
 
@@ -21,6 +23,7 @@ export var useDataGridProComponent = function useDataGridProComponent(inputApiRe
21
23
  */
22
24
 
23
25
  useGridSelectionPreProcessors(apiRef, props);
26
+ useGridRowReorderPreProcessors(apiRef, props);
24
27
  useGridRowGroupingPreProcessors(apiRef, props);
25
28
  useGridTreeDataPreProcessors(apiRef, props);
26
29
  useGridDetailPanelPreProcessors(apiRef, props); // The column pinning `hydrateColumns` pre-processor must be after every other `hydrateColumns` pre-processors
@@ -51,29 +54,30 @@ export var useDataGridProComponent = function useDataGridProComponent(inputApiRe
51
54
  useGridInitializeState(columnMenuStateInitializer, apiRef, props);
52
55
  useGridRowGrouping(apiRef, props);
53
56
  useGridTreeData(apiRef);
57
+ useGridKeyboardNavigation(apiRef, props);
54
58
  useGridSelection(apiRef, props);
55
59
  useGridDetailPanel(apiRef, props);
56
60
  useGridColumnPinning(apiRef, props);
57
61
  useGridColumns(apiRef, props);
58
62
  useGridRows(apiRef, props);
59
63
  useGridParamsApi(apiRef);
64
+ useGridColumnSpanning(apiRef);
60
65
  useGridDetailPanelCache(apiRef, props);
61
66
  var useGridEditing = (_props$experimentalFe2 = props.experimentalFeatures) != null && _props$experimentalFe2.newEditingApi ? useGridEditing_new : useGridEditing_old;
62
67
  useGridEditing(apiRef, props);
63
68
  useGridFocus(apiRef, props);
64
- useGridSorting(apiRef, props);
65
69
  useGridPreferencesPanel(apiRef);
66
70
  useGridFilter(apiRef, props);
71
+ useGridSorting(apiRef, props);
67
72
  useGridDensity(apiRef, props);
68
73
  useGridColumnReorder(apiRef, props);
69
74
  useGridColumnResize(apiRef, props);
70
75
  useGridPagination(apiRef, props);
71
76
  useGridRowsMeta(apiRef, props);
77
+ useGridRowReorder(apiRef, props);
72
78
  useGridScroll(apiRef, props);
73
79
  useGridInfiniteLoader(apiRef, props);
74
80
  useGridColumnMenu(apiRef);
75
- useGridKeyboard(apiRef);
76
- useGridKeyboardNavigation(apiRef, props);
77
81
  useGridCsvExport(apiRef);
78
82
  useGridPrintExport(apiRef, props);
79
83
  useGridClipboard(apiRef);
@@ -16,6 +16,7 @@ export var DATA_GRID_PRO_PROPS_DEFAULT_VALUES = _extends({}, DATA_GRID_PROPS_DEF
16
16
  disableChildrenFiltering: false,
17
17
  disableChildrenSorting: false,
18
18
  rowGroupingColumnMode: 'single',
19
+ rowReordering: false,
19
20
  getDetailPanelHeight: function getDetailPanelHeight() {
20
21
  return 500;
21
22
  }
@@ -104,7 +104,6 @@ export var DataGridProColumnHeaders = /*#__PURE__*/React.forwardRef(function Dat
104
104
  }),
105
105
  isDragging = _useGridColumnHeaders.isDragging,
106
106
  renderContext = _useGridColumnHeaders.renderContext,
107
- updateInnerPosition = _useGridColumnHeaders.updateInnerPosition,
108
107
  getRootProps = _useGridColumnHeaders.getRootProps,
109
108
  getInnerProps = _useGridColumnHeaders.getInnerProps,
110
109
  getColumns = _useGridColumnHeaders.getColumns;
@@ -115,11 +114,6 @@ export var DataGridProColumnHeaders = /*#__PURE__*/React.forwardRef(function Dat
115
114
  classes: rootProps.classes
116
115
  };
117
116
  var classes = useUtilityClasses(ownerState);
118
- React.useEffect(function () {
119
- if (renderContext) {
120
- updateInnerPosition(renderContext);
121
- }
122
- }, [renderContext, updateInnerPosition]);
123
117
  var leftRenderContext = renderContext && leftPinnedColumns.length ? _extends({}, renderContext, {
124
118
  firstColumnIndex: 0,
125
119
  lastColumnIndex: leftPinnedColumns.length
@@ -192,9 +192,7 @@ var DataGridProVirtualScroller = /*#__PURE__*/React.forwardRef(function DataGrid
192
192
  }, [renderContext, updateRenderZonePosition]);
193
193
  useGridApiEventHandler(apiRef, GridEvents.columnWidthChange, refreshRenderZonePosition);
194
194
  useGridApiEventHandler(apiRef, GridEvents.columnOrderChange, refreshRenderZonePosition);
195
- React.useEffect(function () {
196
- refreshRenderZonePosition();
197
- }, [refreshRenderZonePosition]);
195
+ useGridApiEventHandler(apiRef, GridEvents.rowOrderChange, refreshRenderZonePosition);
198
196
  var leftRenderContext = renderContext && leftPinnedColumns.length > 0 ? _extends({}, renderContext, {
199
197
  firstColumnIndex: 0,
200
198
  lastColumnIndex: leftPinnedColumns.length