@mui/x-data-grid-pro 5.9.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.
- package/CHANGELOG.md +36 -0
- package/DataGridPro/DataGridPro.js +14 -0
- package/DataGridPro/useDataGridProComponent.js +4 -0
- package/DataGridPro/useDataGridProProps.js +1 -0
- package/README.md +5 -3
- package/components/DataGridProVirtualScroller.js +1 -0
- package/components/GridRowReorderCell.d.ts +5 -0
- package/components/GridRowReorderCell.js +72 -0
- package/hooks/features/columnReorder/useGridColumnReorder.js +2 -2
- package/hooks/features/index.d.ts +1 -0
- package/hooks/features/index.js +1 -0
- package/hooks/features/rowReorder/gridRowReorderColDef.d.ts +2 -0
- package/hooks/features/rowReorder/gridRowReorderColDef.js +18 -0
- package/hooks/features/rowReorder/index.d.ts +1 -0
- package/hooks/features/rowReorder/index.js +1 -0
- package/hooks/features/rowReorder/useGridRowReorder.d.ts +8 -0
- package/hooks/features/rowReorder/useGridRowReorder.js +111 -0
- package/hooks/features/rowReorder/useGridRowReorderPreProcessors.d.ts +4 -0
- package/hooks/features/rowReorder/useGridRowReorderPreProcessors.js +51 -0
- package/index.js +1 -1
- package/legacy/DataGridPro/DataGridPro.js +14 -0
- package/legacy/DataGridPro/useDataGridProComponent.js +4 -0
- package/legacy/DataGridPro/useDataGridProProps.js +1 -0
- package/legacy/components/DataGridProVirtualScroller.js +1 -0
- package/legacy/components/GridRowReorderCell.js +74 -0
- package/legacy/hooks/features/columnReorder/useGridColumnReorder.js +2 -2
- package/legacy/hooks/features/index.js +1 -0
- package/legacy/hooks/features/rowReorder/gridRowReorderColDef.js +20 -0
- package/legacy/hooks/features/rowReorder/index.js +1 -0
- package/legacy/hooks/features/rowReorder/useGridRowReorder.js +115 -0
- package/legacy/hooks/features/rowReorder/useGridRowReorderPreProcessors.js +52 -0
- package/legacy/index.js +1 -1
- package/legacy/models/gridRowOrderChangeParams.js +1 -0
- package/legacy/models/index.js +1 -0
- package/legacy/utils/releaseInfo.js +1 -1
- package/models/dataGridProProps.d.ts +12 -0
- package/models/gridRowOrderChangeParams.d.ts +18 -0
- package/models/gridRowOrderChangeParams.js +1 -0
- package/models/index.d.ts +1 -0
- package/models/index.js +1 -0
- package/modern/DataGridPro/DataGridPro.js +14 -0
- package/modern/DataGridPro/useDataGridProComponent.js +4 -0
- package/modern/DataGridPro/useDataGridProProps.js +1 -0
- package/modern/components/DataGridProVirtualScroller.js +1 -0
- package/modern/components/GridRowReorderCell.js +72 -0
- package/modern/hooks/features/columnReorder/useGridColumnReorder.js +2 -2
- package/modern/hooks/features/index.js +1 -0
- package/modern/hooks/features/rowReorder/gridRowReorderColDef.js +18 -0
- package/modern/hooks/features/rowReorder/index.js +1 -0
- package/modern/hooks/features/rowReorder/useGridRowReorder.js +111 -0
- package/modern/hooks/features/rowReorder/useGridRowReorderPreProcessors.js +51 -0
- package/modern/index.js +1 -1
- package/modern/models/gridRowOrderChangeParams.js +1 -0
- package/modern/models/index.js +1 -0
- package/modern/utils/releaseInfo.js +1 -1
- package/node/DataGridPro/DataGridPro.js +14 -0
- package/node/DataGridPro/useDataGridProComponent.js +6 -0
- package/node/DataGridPro/useDataGridProProps.js +1 -0
- package/node/components/DataGridProVirtualScroller.js +1 -0
- package/node/components/GridRowReorderCell.js +92 -0
- package/node/hooks/features/columnReorder/useGridColumnReorder.js +2 -2
- package/node/hooks/features/index.js +13 -0
- package/node/hooks/features/rowReorder/gridRowReorderColDef.js +31 -0
- package/node/hooks/features/rowReorder/index.js +18 -0
- package/node/hooks/features/rowReorder/useGridRowReorder.js +126 -0
- package/node/hooks/features/rowReorder/useGridRowReorderPreProcessors.js +70 -0
- package/node/index.js +1 -1
- package/node/models/gridRowOrderChangeParams.js +5 -0
- package/node/models/index.js +13 -0
- package/node/utils/releaseInfo.js +1 -1
- package/package.json +4 -4
- package/typeOverloads/modules.d.ts +4 -1
- package/utils/releaseInfo.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,42 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## v5.10.0
|
|
7
|
+
|
|
8
|
+
_Apr 25, 2022_
|
|
9
|
+
|
|
10
|
+
We'd like to offer a big thanks to the 6 contributors who made this release possible. Here are some highlights ✨:
|
|
11
|
+
|
|
12
|
+
- 🎁 Introduce [Row reorder](https://mui.com/x/react-data-grid/rows/#row-reorder) (#4034) @DanailH
|
|
13
|
+
|
|
14
|
+
<img src="https://user-images.githubusercontent.com/5858539/165091263-23472fbb-a989-44b8-849a-d2185adfe13b.gif" width="800">
|
|
15
|
+
|
|
16
|
+
- 🐞 Bug fixes
|
|
17
|
+
|
|
18
|
+
### `@mui/x-data-grid@v5.10.0` / `@mui/x-data-grid-pro@v5.10.0`
|
|
19
|
+
|
|
20
|
+
- [DataGrid] Don't close column menu when updating rows (#4498) @m4theushw
|
|
21
|
+
- [DataGridPro] Introduce row reorder (#4034) @DanailH
|
|
22
|
+
|
|
23
|
+
### `@mui/x-date-pickers@5.0.0-alpha.2` / `@mui/x-date-pickers-pro@5.0.0-alpha.2`
|
|
24
|
+
|
|
25
|
+
- [pickers] Pass `PaperProps` to `DesktopWrapper` component (#4584) @alexfauquette
|
|
26
|
+
- [TimePicker] Fix bug when time picker clear value (#4582) @alexfauquette
|
|
27
|
+
- [DateRangePicker] Fix missing `clearable` and `clearText` props (#4511) @zigang93
|
|
28
|
+
|
|
29
|
+
### Docs
|
|
30
|
+
|
|
31
|
+
- [docs] Add plan in the nav bar for pro-only and premium-only pages (#4591) @flaviendelangle
|
|
32
|
+
- [docs] Clarify where to install the license (#4452) @oliviertassinari
|
|
33
|
+
- [docs] Fix CodeSandbox links for demo with pickers (#4570) @alexfauquette
|
|
34
|
+
- [docs] Include date-fns dependency when opening demos in CodeSandbox (#4508) @m4theushw
|
|
35
|
+
- [docs] Split the 'Group & Pivot' page (#4441) @flaviendelangle
|
|
36
|
+
|
|
37
|
+
### Core
|
|
38
|
+
|
|
39
|
+
- [core] Fix the README of the X packages (#4590) @flaviendelangle
|
|
40
|
+
- [test] Fix test to not depend on screen resolution (#4587) @m4theushw
|
|
41
|
+
|
|
6
42
|
## v5.9.0
|
|
7
43
|
|
|
8
44
|
_Apr 14, 2022_
|
|
@@ -740,6 +740,14 @@ DataGridProRaw.propTypes = {
|
|
|
740
740
|
*/
|
|
741
741
|
onRowGroupingModelChange: PropTypes.func,
|
|
742
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
|
+
|
|
743
751
|
/**
|
|
744
752
|
* Callback fired when scrolling to the bottom of the grid viewport.
|
|
745
753
|
* @param {GridRowScrollEndParams} params With all properties from [[GridRowScrollEndParams]].
|
|
@@ -846,6 +854,12 @@ DataGridProRaw.propTypes = {
|
|
|
846
854
|
*/
|
|
847
855
|
rowHeight: PropTypes.number,
|
|
848
856
|
|
|
857
|
+
/**
|
|
858
|
+
* If `true`, the reordering of rows is enabled.
|
|
859
|
+
* @default false
|
|
860
|
+
*/
|
|
861
|
+
rowReordering: PropTypes.bool,
|
|
862
|
+
|
|
849
863
|
/**
|
|
850
864
|
* Set of rows of type [[GridRowsProp]].
|
|
851
865
|
*/
|
|
@@ -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 const useDataGridProComponent = (inputApiRef, props) => {
|
|
16
18
|
var _props$experimentalFe, _props$experimentalFe2;
|
|
17
19
|
|
|
@@ -21,6 +23,7 @@ export const useDataGridProComponent = (inputApiRef, props) => {
|
|
|
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
|
|
@@ -71,6 +74,7 @@ export const useDataGridProComponent = (inputApiRef, props) => {
|
|
|
71
74
|
useGridColumnResize(apiRef, props);
|
|
72
75
|
useGridPagination(apiRef, props);
|
|
73
76
|
useGridRowsMeta(apiRef, props);
|
|
77
|
+
useGridRowReorder(apiRef, props);
|
|
74
78
|
useGridScroll(apiRef, props);
|
|
75
79
|
useGridInfiniteLoader(apiRef, props);
|
|
76
80
|
useGridColumnMenu(apiRef);
|
|
@@ -15,6 +15,7 @@ export const DATA_GRID_PRO_PROPS_DEFAULT_VALUES = _extends({}, DATA_GRID_PROPS_D
|
|
|
15
15
|
disableChildrenFiltering: false,
|
|
16
16
|
disableChildrenSorting: false,
|
|
17
17
|
rowGroupingColumnMode: 'single',
|
|
18
|
+
rowReordering: false,
|
|
18
19
|
getDetailPanelHeight: () => 500
|
|
19
20
|
});
|
|
20
21
|
export const useDataGridProProps = inProps => {
|
package/README.md
CHANGED
|
@@ -15,12 +15,14 @@ npm install @mui/x-data-grid-pro
|
|
|
15
15
|
yarn add @mui/x-data-grid-pro
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
This component has
|
|
18
|
+
This component has the following peer dependencies that you will need to install as well.
|
|
19
19
|
|
|
20
20
|
```json
|
|
21
21
|
"peerDependencies": {
|
|
22
|
-
"@mui/material": "^5.
|
|
23
|
-
"
|
|
22
|
+
"@mui/material": "^5.2.8",
|
|
23
|
+
"@mui/system": "^5.2.8",
|
|
24
|
+
"react": "^17.0.2 || ^18.0.0",
|
|
25
|
+
"react-dom": "^17.0.2 || ^18.0.0"
|
|
24
26
|
},
|
|
25
27
|
```
|
|
26
28
|
|
|
@@ -175,6 +175,7 @@ const DataGridProVirtualScroller = /*#__PURE__*/React.forwardRef(function DataGr
|
|
|
175
175
|
}, [renderContext, updateRenderZonePosition]);
|
|
176
176
|
useGridApiEventHandler(apiRef, GridEvents.columnWidthChange, refreshRenderZonePosition);
|
|
177
177
|
useGridApiEventHandler(apiRef, GridEvents.columnOrderChange, refreshRenderZonePosition);
|
|
178
|
+
useGridApiEventHandler(apiRef, GridEvents.rowOrderChange, refreshRenderZonePosition);
|
|
178
179
|
const leftRenderContext = renderContext && leftPinnedColumns.length > 0 ? _extends({}, renderContext, {
|
|
179
180
|
firstColumnIndex: 0,
|
|
180
181
|
lastColumnIndex: leftPinnedColumns.length
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { GridRenderCellParams } from '@mui/x-data-grid';
|
|
3
|
+
declare const GridRowReorderCell: (params: GridRenderCellParams) => JSX.Element;
|
|
4
|
+
export { GridRowReorderCell };
|
|
5
|
+
export declare const renderRowReorderCell: (params: GridRenderCellParams) => JSX.Element;
|
|
@@ -0,0 +1,72 @@
|
|
|
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 { GridEvents, gridRowTreeDepthSelector, gridSortModelSelector, useGridApiContext, useGridSelector, getDataGridUtilityClass, gridEditRowsStateSelector } from '@mui/x-data-grid';
|
|
5
|
+
import { useGridRootProps } from '../hooks/utils/useGridRootProps';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
|
+
|
|
9
|
+
const useUtilityClasses = ownerState => {
|
|
10
|
+
const {
|
|
11
|
+
isDraggable,
|
|
12
|
+
classes
|
|
13
|
+
} = ownerState;
|
|
14
|
+
const slots = {
|
|
15
|
+
root: ['rowReorderCell', isDraggable && 'rowReorderCell--draggable'],
|
|
16
|
+
placeholder: ['rowReorderCellPlaceholder']
|
|
17
|
+
};
|
|
18
|
+
return composeClasses(slots, getDataGridUtilityClass, classes);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const GridRowReorderCell = params => {
|
|
22
|
+
const apiRef = useGridApiContext();
|
|
23
|
+
const rootProps = useGridRootProps();
|
|
24
|
+
const sortModel = useGridSelector(apiRef, gridSortModelSelector);
|
|
25
|
+
const treeDepth = useGridSelector(apiRef, gridRowTreeDepthSelector);
|
|
26
|
+
const editRowsState = useGridSelector(apiRef, gridEditRowsStateSelector); // eslint-disable-next-line no-underscore-dangle
|
|
27
|
+
|
|
28
|
+
const cellValue = params.row.__reorder__ || params.id; // TODO: remove sortModel and treeDepth checks once row reorder is compatible
|
|
29
|
+
|
|
30
|
+
const isDraggable = !!rootProps.rowReordering && !sortModel.length && treeDepth === 1 && Object.keys(editRowsState).length === 0;
|
|
31
|
+
const ownerState = {
|
|
32
|
+
isDraggable,
|
|
33
|
+
classes: rootProps.classes
|
|
34
|
+
};
|
|
35
|
+
const classes = useUtilityClasses(ownerState);
|
|
36
|
+
const publish = React.useCallback((eventName, propHandler) => event => {
|
|
37
|
+
// Ignore portal
|
|
38
|
+
// The target is not an element when triggered by a Select inside the cell
|
|
39
|
+
// See https://github.com/mui/material-ui/issues/10534
|
|
40
|
+
if (event.target.nodeType === 1 && !event.currentTarget.contains(event.target)) {
|
|
41
|
+
return;
|
|
42
|
+
} // The row might have been deleted
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
if (!apiRef.current.getRow(params.row.id)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
apiRef.current.publishEvent(eventName, apiRef.current.getRowParams(params.row.id), event);
|
|
50
|
+
|
|
51
|
+
if (propHandler) {
|
|
52
|
+
propHandler(event);
|
|
53
|
+
}
|
|
54
|
+
}, [apiRef, params.row.id]);
|
|
55
|
+
const draggableEventHandlers = {
|
|
56
|
+
onDragStart: publish(GridEvents.rowDragStart),
|
|
57
|
+
onDragOver: publish(GridEvents.rowDragOver),
|
|
58
|
+
onDragEnd: publish(GridEvents.rowDragEnd)
|
|
59
|
+
};
|
|
60
|
+
return /*#__PURE__*/_jsxs("div", _extends({
|
|
61
|
+
className: classes.root,
|
|
62
|
+
draggable: isDraggable
|
|
63
|
+
}, draggableEventHandlers, {
|
|
64
|
+
children: [/*#__PURE__*/_jsx(rootProps.components.RowReorderIcon, {}), /*#__PURE__*/_jsx("div", {
|
|
65
|
+
className: classes.placeholder,
|
|
66
|
+
children: cellValue
|
|
67
|
+
})]
|
|
68
|
+
}));
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export { GridRowReorderCell };
|
|
72
|
+
export const renderRowReorderCell = params => /*#__PURE__*/_jsx(GridRowReorderCell, _extends({}, params));
|
|
@@ -50,7 +50,7 @@ export const useGridColumnReorder = (apiRef, props) => {
|
|
|
50
50
|
clearTimeout(removeDnDStylesTimeout.current);
|
|
51
51
|
};
|
|
52
52
|
}, []);
|
|
53
|
-
const
|
|
53
|
+
const handleDragStart = React.useCallback((params, event) => {
|
|
54
54
|
if (props.disableColumnReorder || params.colDef.disableReorder) {
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
@@ -156,7 +156,7 @@ export const useGridColumnReorder = (apiRef, props) => {
|
|
|
156
156
|
}));
|
|
157
157
|
apiRef.current.forceUpdate();
|
|
158
158
|
}, [props.disableColumnReorder, logger, apiRef]);
|
|
159
|
-
useGridApiEventHandler(apiRef, GridEvents.columnHeaderDragStart,
|
|
159
|
+
useGridApiEventHandler(apiRef, GridEvents.columnHeaderDragStart, handleDragStart);
|
|
160
160
|
useGridApiEventHandler(apiRef, GridEvents.columnHeaderDragEnter, handleDragEnter);
|
|
161
161
|
useGridApiEventHandler(apiRef, GridEvents.columnHeaderDragOver, handleDragOver);
|
|
162
162
|
useGridApiEventHandler(apiRef, GridEvents.columnHeaderDragEnd, handleDragEnd);
|
package/hooks/features/index.js
CHANGED
|
@@ -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
|
+
};
|
package/index.js
CHANGED
|
@@ -740,6 +740,14 @@ DataGridProRaw.propTypes = {
|
|
|
740
740
|
*/
|
|
741
741
|
onRowGroupingModelChange: PropTypes.func,
|
|
742
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
|
+
|
|
743
751
|
/**
|
|
744
752
|
* Callback fired when scrolling to the bottom of the grid viewport.
|
|
745
753
|
* @param {GridRowScrollEndParams} params With all properties from [[GridRowScrollEndParams]].
|
|
@@ -846,6 +854,12 @@ DataGridProRaw.propTypes = {
|
|
|
846
854
|
*/
|
|
847
855
|
rowHeight: PropTypes.number,
|
|
848
856
|
|
|
857
|
+
/**
|
|
858
|
+
* If `true`, the reordering of rows is enabled.
|
|
859
|
+
* @default false
|
|
860
|
+
*/
|
|
861
|
+
rowReordering: PropTypes.bool,
|
|
862
|
+
|
|
849
863
|
/**
|
|
850
864
|
* Set of rows of type [[GridRowsProp]].
|
|
851
865
|
*/
|
|
@@ -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
|
|
@@ -71,6 +74,7 @@ export var useDataGridProComponent = function useDataGridProComponent(inputApiRe
|
|
|
71
74
|
useGridColumnResize(apiRef, props);
|
|
72
75
|
useGridPagination(apiRef, props);
|
|
73
76
|
useGridRowsMeta(apiRef, props);
|
|
77
|
+
useGridRowReorder(apiRef, props);
|
|
74
78
|
useGridScroll(apiRef, props);
|
|
75
79
|
useGridInfiniteLoader(apiRef, props);
|
|
76
80
|
useGridColumnMenu(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
|
}
|
|
@@ -192,6 +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
|
+
useGridApiEventHandler(apiRef, GridEvents.rowOrderChange, refreshRenderZonePosition);
|
|
195
196
|
var leftRenderContext = renderContext && leftPinnedColumns.length > 0 ? _extends({}, renderContext, {
|
|
196
197
|
firstColumnIndex: 0,
|
|
197
198
|
lastColumnIndex: leftPinnedColumns.length
|
|
@@ -0,0 +1,74 @@
|
|
|
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 { GridEvents, gridRowTreeDepthSelector, gridSortModelSelector, useGridApiContext, useGridSelector, getDataGridUtilityClass, gridEditRowsStateSelector } from '@mui/x-data-grid';
|
|
5
|
+
import { useGridRootProps } from '../hooks/utils/useGridRootProps';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
|
+
|
|
9
|
+
var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
10
|
+
var isDraggable = ownerState.isDraggable,
|
|
11
|
+
classes = ownerState.classes;
|
|
12
|
+
var slots = {
|
|
13
|
+
root: ['rowReorderCell', isDraggable && 'rowReorderCell--draggable'],
|
|
14
|
+
placeholder: ['rowReorderCellPlaceholder']
|
|
15
|
+
};
|
|
16
|
+
return composeClasses(slots, getDataGridUtilityClass, classes);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
var GridRowReorderCell = function GridRowReorderCell(params) {
|
|
20
|
+
var apiRef = useGridApiContext();
|
|
21
|
+
var rootProps = useGridRootProps();
|
|
22
|
+
var sortModel = useGridSelector(apiRef, gridSortModelSelector);
|
|
23
|
+
var treeDepth = useGridSelector(apiRef, gridRowTreeDepthSelector);
|
|
24
|
+
var editRowsState = useGridSelector(apiRef, gridEditRowsStateSelector); // eslint-disable-next-line no-underscore-dangle
|
|
25
|
+
|
|
26
|
+
var cellValue = params.row.__reorder__ || params.id; // TODO: remove sortModel and treeDepth checks once row reorder is compatible
|
|
27
|
+
|
|
28
|
+
var isDraggable = !!rootProps.rowReordering && !sortModel.length && treeDepth === 1 && Object.keys(editRowsState).length === 0;
|
|
29
|
+
var ownerState = {
|
|
30
|
+
isDraggable: isDraggable,
|
|
31
|
+
classes: rootProps.classes
|
|
32
|
+
};
|
|
33
|
+
var classes = useUtilityClasses(ownerState);
|
|
34
|
+
var publish = React.useCallback(function (eventName, propHandler) {
|
|
35
|
+
return function (event) {
|
|
36
|
+
// Ignore portal
|
|
37
|
+
// The target is not an element when triggered by a Select inside the cell
|
|
38
|
+
// See https://github.com/mui/material-ui/issues/10534
|
|
39
|
+
if (event.target.nodeType === 1 && !event.currentTarget.contains(event.target)) {
|
|
40
|
+
return;
|
|
41
|
+
} // The row might have been deleted
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
if (!apiRef.current.getRow(params.row.id)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
apiRef.current.publishEvent(eventName, apiRef.current.getRowParams(params.row.id), event);
|
|
49
|
+
|
|
50
|
+
if (propHandler) {
|
|
51
|
+
propHandler(event);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}, [apiRef, params.row.id]);
|
|
55
|
+
var draggableEventHandlers = {
|
|
56
|
+
onDragStart: publish(GridEvents.rowDragStart),
|
|
57
|
+
onDragOver: publish(GridEvents.rowDragOver),
|
|
58
|
+
onDragEnd: publish(GridEvents.rowDragEnd)
|
|
59
|
+
};
|
|
60
|
+
return /*#__PURE__*/_jsxs("div", _extends({
|
|
61
|
+
className: classes.root,
|
|
62
|
+
draggable: isDraggable
|
|
63
|
+
}, draggableEventHandlers, {
|
|
64
|
+
children: [/*#__PURE__*/_jsx(rootProps.components.RowReorderIcon, {}), /*#__PURE__*/_jsx("div", {
|
|
65
|
+
className: classes.placeholder,
|
|
66
|
+
children: cellValue
|
|
67
|
+
})]
|
|
68
|
+
}));
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export { GridRowReorderCell };
|
|
72
|
+
export var renderRowReorderCell = function renderRowReorderCell(params) {
|
|
73
|
+
return /*#__PURE__*/_jsx(GridRowReorderCell, _extends({}, params));
|
|
74
|
+
};
|
|
@@ -52,7 +52,7 @@ export var useGridColumnReorder = function useGridColumnReorder(apiRef, props) {
|
|
|
52
52
|
clearTimeout(removeDnDStylesTimeout.current);
|
|
53
53
|
};
|
|
54
54
|
}, []);
|
|
55
|
-
var
|
|
55
|
+
var handleDragStart = React.useCallback(function (params, event) {
|
|
56
56
|
if (props.disableColumnReorder || params.colDef.disableReorder) {
|
|
57
57
|
return;
|
|
58
58
|
}
|
|
@@ -162,7 +162,7 @@ export var useGridColumnReorder = function useGridColumnReorder(apiRef, props) {
|
|
|
162
162
|
});
|
|
163
163
|
apiRef.current.forceUpdate();
|
|
164
164
|
}, [props.disableColumnReorder, logger, apiRef]);
|
|
165
|
-
useGridApiEventHandler(apiRef, GridEvents.columnHeaderDragStart,
|
|
165
|
+
useGridApiEventHandler(apiRef, GridEvents.columnHeaderDragStart, handleDragStart);
|
|
166
166
|
useGridApiEventHandler(apiRef, GridEvents.columnHeaderDragEnter, handleDragEnter);
|
|
167
167
|
useGridApiEventHandler(apiRef, GridEvents.columnHeaderDragOver, handleDragOver);
|
|
168
168
|
useGridApiEventHandler(apiRef, GridEvents.columnHeaderDragEnd, handleDragEnd);
|