@mui/x-data-grid-pro 5.15.3 → 5.16.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 +56 -0
- package/DataGridPro/DataGridPro.js +2 -0
- package/DataGridPro/useDataGridProComponent.js +4 -1
- package/components/DataGridProColumnHeaders.js +25 -13
- package/hooks/features/columnReorder/useGridColumnReorder.js +95 -3
- package/hooks/features/columnResize/useGridColumnResize.js +10 -7
- package/hooks/features/rowPinning/useGridRowPinningPreProcessors.d.ts +4 -4
- package/index.js +1 -1
- package/legacy/DataGridPro/DataGridPro.js +2 -0
- package/legacy/DataGridPro/useDataGridProComponent.js +4 -1
- package/legacy/components/DataGridProColumnHeaders.js +25 -13
- package/legacy/hooks/features/columnReorder/useGridColumnReorder.js +99 -3
- package/legacy/hooks/features/columnResize/useGridColumnResize.js +11 -7
- package/legacy/index.js +1 -1
- package/legacy/utils/domUtils.js +5 -0
- package/legacy/utils/releaseInfo.js +1 -1
- package/modern/DataGridPro/DataGridPro.js +2 -0
- package/modern/DataGridPro/useDataGridProComponent.js +4 -1
- package/modern/components/DataGridProColumnHeaders.js +25 -13
- package/modern/hooks/features/columnReorder/useGridColumnReorder.js +83 -3
- package/modern/hooks/features/columnResize/useGridColumnResize.js +5 -2
- package/modern/index.js +1 -1
- package/modern/utils/domUtils.js +3 -0
- package/modern/utils/releaseInfo.js +1 -1
- package/node/DataGridPro/DataGridPro.js +2 -0
- package/node/DataGridPro/useDataGridProComponent.js +3 -0
- package/node/components/DataGridProColumnHeaders.js +25 -12
- package/node/hooks/features/columnReorder/useGridColumnReorder.js +95 -3
- package/node/hooks/features/columnResize/useGridColumnResize.js +9 -6
- package/node/index.js +1 -1
- package/node/utils/domUtils.js +7 -0
- package/node/utils/releaseInfo.js +1 -1
- package/package.json +5 -5
- package/utils/domUtils.d.ts +1 -0
- package/utils/domUtils.js +5 -0
- package/utils/releaseInfo.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,62 @@
|
|
|
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
|
+
## 5.16.0
|
|
7
|
+
|
|
8
|
+
_Aug 25, 2022_
|
|
9
|
+
|
|
10
|
+
We'd like to offer a big thanks to the 11 contributors who made this release possible. Here are some highlights ✨:
|
|
11
|
+
|
|
12
|
+
- 🎁 Introduce column grouping for data grid (#5133) @alexfauquette
|
|
13
|
+
|
|
14
|
+
You can now group columns using the `columnGroupingModel` prop. This lets you to display more structured data.
|
|
15
|
+
|
|
16
|
+
<img src="https://user-images.githubusercontent.com/45398769/186178366-4fba66b2-bf90-4c7a-9d83-940a7fc78704.png" width="800" />
|
|
17
|
+
|
|
18
|
+
To enable this feature, add `experimentalFeatures={{ columnGrouping: true }}`.
|
|
19
|
+
The grouping header can be fully customized.
|
|
20
|
+
See the [documentation](https://mui.com/x/react-data-grid/column-groups/) to explore everything it has to offer.
|
|
21
|
+
|
|
22
|
+
- 🐞 Bugfixes
|
|
23
|
+
- 🌏 New locales for pickers thanks to @tesseractjh and @drastus
|
|
24
|
+
|
|
25
|
+
### `@mui/x-data-grid@v5.16.0` / `@mui/x-data-grid-pro@v5.16.0` / `@mui/x-data-grid-premium@v5.16.0`
|
|
26
|
+
|
|
27
|
+
#### Changes
|
|
28
|
+
|
|
29
|
+
- [DataGrid] Implement column grouping (#5133) @alexfauquette
|
|
30
|
+
- [DataGrid] Handle `disableVirtualization` prop change (#5889) @cherniavskii
|
|
31
|
+
- [DataGrid] Improve `GridRowModel` typing (#5734) @cherniavskii
|
|
32
|
+
- [DataGrid] Update deprecation note for `GridColDef` `hide` property (#5886) @cherniavskii
|
|
33
|
+
|
|
34
|
+
### `@mui/x-date-pickers@v5.0.0-beta.7` / `@mui/x-date-pickers-pro@v5.0.0-beta.7`
|
|
35
|
+
|
|
36
|
+
#### Changes
|
|
37
|
+
|
|
38
|
+
- [DatePicker] Fix to pass down `className` prop provided on DatePicker to `renderInput` (#5471) @CruseCtrl
|
|
39
|
+
- [DatePicker] Improve `a11y` support (#5809) @LukasTy
|
|
40
|
+
- [pickers] Add `PaperContent` component slot (#5801) @LukasTy
|
|
41
|
+
- [pickers] Add a breaking change section in the migration guide (#5805) @alexfauquette
|
|
42
|
+
- [pickers] Add new translations to `localeText` (#5143) @alexfauquette
|
|
43
|
+
- [pickers] Document components slots (#4657) @flaviendelangle
|
|
44
|
+
- [pickers] Add new unstable field components (#5504) @flaviendelangle
|
|
45
|
+
- [pickers] Fallback to default `minDate` / `maxDate` when `null` value is passed (#5397) @flaviendelangle
|
|
46
|
+
- [l10n] Add Korean (ko-KR) locale (#5854) @tesseractjh
|
|
47
|
+
- [l10n] Add Polish (pl-PL) locale (#5833) @drastus
|
|
48
|
+
|
|
49
|
+
### Docs
|
|
50
|
+
|
|
51
|
+
- [docs] Fix typo in `migration from lab` (#5277) @chuckwired
|
|
52
|
+
- [docs] Use `dayjs` instead of `date-fns` in doc examples (#5481) @flaviendelangle
|
|
53
|
+
|
|
54
|
+
### Core
|
|
55
|
+
|
|
56
|
+
- [core] Clarify the scope of the license key used for tests and documentation (#5824) @oliviertassinari
|
|
57
|
+
- [core] Fix Typescript error on field hooks (#5892) @flaviendelangle
|
|
58
|
+
- [core] Memoize `columns` in `useDemoData` hook (#5848) @cherniavskii
|
|
59
|
+
- [core] Remove Firefox from the BrowserStack list (#5874) @DanailH
|
|
60
|
+
- [core] Small changes to the release script (#5840) @m4theushw
|
|
61
|
+
|
|
6
62
|
## 5.15.3
|
|
7
63
|
|
|
8
64
|
_Aug 18, 2022_
|
|
@@ -106,6 +106,7 @@ DataGridProRaw.propTypes = {
|
|
|
106
106
|
* @default 3
|
|
107
107
|
*/
|
|
108
108
|
columnBuffer: PropTypes.number,
|
|
109
|
+
columnGroupingModel: PropTypes.arrayOf(PropTypes.object),
|
|
109
110
|
|
|
110
111
|
/**
|
|
111
112
|
* Set of columns of type [[GridColumns]].
|
|
@@ -274,6 +275,7 @@ DataGridProRaw.propTypes = {
|
|
|
274
275
|
* For each feature, if the flag is not explicitly set to `true`, the feature will be fully disabled and any property / method call will not have any effect.
|
|
275
276
|
*/
|
|
276
277
|
experimentalFeatures: PropTypes.shape({
|
|
278
|
+
columnGrouping: PropTypes.bool,
|
|
277
279
|
newEditingApi: PropTypes.bool,
|
|
278
280
|
preventCommitWhileValidating: PropTypes.bool,
|
|
279
281
|
rowPinning: PropTypes.bool,
|
|
@@ -1,4 +1,4 @@
|
|
|
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';
|
|
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, useGridColumnGrouping, columnGroupsStateInitializer, useGridColumnGroupingPreProcessors } 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';
|
|
@@ -21,6 +21,7 @@ export const useDataGridProComponent = (inputApiRef, props) => {
|
|
|
21
21
|
* Register all pre-processors called during state initialization here.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
+
useGridColumnGroupingPreProcessors(apiRef, props);
|
|
24
25
|
useGridSelectionPreProcessors(apiRef, props);
|
|
25
26
|
useGridRowReorderPreProcessors(apiRef, props);
|
|
26
27
|
useGridTreeDataPreProcessors(apiRef, props);
|
|
@@ -51,6 +52,7 @@ export const useDataGridProComponent = (inputApiRef, props) => {
|
|
|
51
52
|
useGridInitializeState(paginationStateInitializer, apiRef, props);
|
|
52
53
|
useGridInitializeState(rowsMetaStateInitializer, apiRef, props);
|
|
53
54
|
useGridInitializeState(columnMenuStateInitializer, apiRef, props);
|
|
55
|
+
useGridInitializeState(columnGroupsStateInitializer, apiRef, props);
|
|
54
56
|
useGridTreeData(apiRef);
|
|
55
57
|
useGridKeyboardNavigation(apiRef, props);
|
|
56
58
|
useGridSelection(apiRef, props);
|
|
@@ -61,6 +63,7 @@ export const useDataGridProComponent = (inputApiRef, props) => {
|
|
|
61
63
|
useGridParamsApi(apiRef);
|
|
62
64
|
useGridDetailPanel(apiRef, props);
|
|
63
65
|
useGridColumnSpanning(apiRef);
|
|
66
|
+
useGridColumnGrouping(apiRef, props);
|
|
64
67
|
const useGridEditing = (_props$experimentalFe2 = props.experimentalFeatures) != null && _props$experimentalFe2.newEditingApi ? useGridEditing_new : useGridEditing_old;
|
|
65
68
|
useGridEditing(apiRef, props);
|
|
66
69
|
useGridFocus(apiRef, props);
|
|
@@ -11,7 +11,6 @@ import { useGridRootProps } from '../hooks/utils/useGridRootProps';
|
|
|
11
11
|
import { useGridApiContext } from '../hooks/utils/useGridApiContext';
|
|
12
12
|
import { gridPinnedColumnsSelector, GridPinnedPosition } from '../hooks/features/columnPinning';
|
|
13
13
|
import { filterColumns } from './DataGridProVirtualScroller';
|
|
14
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
14
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
15
|
|
|
17
16
|
const useUtilityClasses = ownerState => {
|
|
@@ -57,6 +56,7 @@ const GridColumnHeadersPinnedColumnHeaders = styled('div', {
|
|
|
57
56
|
height: '100%',
|
|
58
57
|
zIndex: 1,
|
|
59
58
|
display: 'flex',
|
|
59
|
+
flexDirection: 'column',
|
|
60
60
|
boxShadow: theme.shadows[2],
|
|
61
61
|
backgroundColor: theme.palette.background.default
|
|
62
62
|
}, theme.palette.mode === 'dark' && {
|
|
@@ -98,7 +98,8 @@ export const DataGridProColumnHeaders = /*#__PURE__*/React.forwardRef(function D
|
|
|
98
98
|
renderContext,
|
|
99
99
|
getRootProps,
|
|
100
100
|
getInnerProps,
|
|
101
|
-
|
|
101
|
+
getColumnHeaders,
|
|
102
|
+
getColumnGroupHeaders
|
|
102
103
|
} = useGridColumnHeaders({
|
|
103
104
|
innerRef,
|
|
104
105
|
minColumnIndex: leftPinnedColumns.length
|
|
@@ -119,35 +120,42 @@ export const DataGridProColumnHeaders = /*#__PURE__*/React.forwardRef(function D
|
|
|
119
120
|
}) : null;
|
|
120
121
|
const innerProps = getInnerProps();
|
|
121
122
|
const pinnedColumnHeadersProps = {
|
|
122
|
-
role: innerProps.role
|
|
123
|
-
'aria-rowindex': innerProps['aria-rowindex']
|
|
123
|
+
role: innerProps.role
|
|
124
124
|
};
|
|
125
125
|
return /*#__PURE__*/_jsxs(GridColumnHeaders, _extends({
|
|
126
126
|
ref: ref,
|
|
127
127
|
className: className
|
|
128
128
|
}, getRootProps(other), {
|
|
129
|
-
children: [leftRenderContext && /*#__PURE__*/
|
|
129
|
+
children: [leftRenderContext && /*#__PURE__*/_jsxs(GridColumnHeadersPinnedColumnHeaders, _extends({
|
|
130
130
|
className: classes.leftPinnedColumns,
|
|
131
131
|
ownerState: {
|
|
132
132
|
side: GridPinnedPosition.left
|
|
133
133
|
}
|
|
134
134
|
}, pinnedColumnHeadersProps, {
|
|
135
|
-
children:
|
|
135
|
+
children: [getColumnGroupHeaders({
|
|
136
|
+
renderContext: leftRenderContext,
|
|
137
|
+
minFirstColumn: leftRenderContext.firstColumnIndex,
|
|
138
|
+
maxLastColumn: leftRenderContext.lastColumnIndex
|
|
139
|
+
}), getColumnHeaders({
|
|
136
140
|
renderContext: leftRenderContext,
|
|
137
141
|
minFirstColumn: leftRenderContext.firstColumnIndex,
|
|
138
142
|
maxLastColumn: leftRenderContext.lastColumnIndex
|
|
139
143
|
}, {
|
|
140
144
|
disableReorder: true
|
|
141
|
-
})
|
|
142
|
-
})), /*#__PURE__*/
|
|
145
|
+
})]
|
|
146
|
+
})), /*#__PURE__*/_jsxs(GridColumnHeadersInner, _extends({
|
|
143
147
|
isDragging: isDragging
|
|
144
148
|
}, innerProps, {
|
|
145
|
-
children:
|
|
149
|
+
children: [getColumnGroupHeaders({
|
|
146
150
|
renderContext,
|
|
147
151
|
minFirstColumn: leftPinnedColumns.length,
|
|
148
152
|
maxLastColumn: visibleColumnFields.length - rightPinnedColumns.length
|
|
149
|
-
})
|
|
150
|
-
|
|
153
|
+
}), getColumnHeaders({
|
|
154
|
+
renderContext,
|
|
155
|
+
minFirstColumn: leftPinnedColumns.length,
|
|
156
|
+
maxLastColumn: visibleColumnFields.length - rightPinnedColumns.length
|
|
157
|
+
})]
|
|
158
|
+
})), rightRenderContext && /*#__PURE__*/_jsxs(GridColumnHeadersPinnedColumnHeaders, _extends({
|
|
151
159
|
ownerState: {
|
|
152
160
|
side: GridPinnedPosition.right
|
|
153
161
|
},
|
|
@@ -156,14 +164,18 @@ export const DataGridProColumnHeaders = /*#__PURE__*/React.forwardRef(function D
|
|
|
156
164
|
paddingRight: scrollbarSize
|
|
157
165
|
}
|
|
158
166
|
}, pinnedColumnHeadersProps, {
|
|
159
|
-
children:
|
|
167
|
+
children: [getColumnGroupHeaders({
|
|
168
|
+
renderContext: rightRenderContext,
|
|
169
|
+
minFirstColumn: rightRenderContext.firstColumnIndex,
|
|
170
|
+
maxLastColumn: rightRenderContext.lastColumnIndex
|
|
171
|
+
}), getColumnHeaders({
|
|
160
172
|
renderContext: rightRenderContext,
|
|
161
173
|
minFirstColumn: rightRenderContext.firstColumnIndex,
|
|
162
174
|
maxLastColumn: rightRenderContext.lastColumnIndex
|
|
163
175
|
}, {
|
|
164
176
|
disableReorder: true,
|
|
165
177
|
separatorSide: GridColumnHeaderSeparatorSides.Left
|
|
166
|
-
})
|
|
178
|
+
})]
|
|
167
179
|
}))]
|
|
168
180
|
}));
|
|
169
181
|
});
|
|
@@ -39,6 +39,7 @@ export const useGridColumnReorder = (apiRef, props) => {
|
|
|
39
39
|
y: 0
|
|
40
40
|
});
|
|
41
41
|
const originColumnIndex = React.useRef(null);
|
|
42
|
+
const forbiddenIndexes = React.useRef({});
|
|
42
43
|
const removeDnDStylesTimeout = React.useRef();
|
|
43
44
|
const ownerState = {
|
|
44
45
|
classes: props.classes
|
|
@@ -70,6 +71,69 @@ export const useGridColumnReorder = (apiRef, props) => {
|
|
|
70
71
|
dragColNode.current.classList.remove(classes.columnHeaderDragging);
|
|
71
72
|
});
|
|
72
73
|
originColumnIndex.current = apiRef.current.getColumnIndex(params.field, false);
|
|
74
|
+
const draggingColumnGroupPath = apiRef.current.unstable_getColumnGroupPath(params.field);
|
|
75
|
+
const columnIndex = originColumnIndex.current;
|
|
76
|
+
const allColumns = apiRef.current.getAllColumns();
|
|
77
|
+
const groupsLookup = apiRef.current.unstable_getAllGroupDetails(); // The limitingGroupId is the id of the group from which the dragged column should not escape
|
|
78
|
+
|
|
79
|
+
let limitingGroupId = null;
|
|
80
|
+
draggingColumnGroupPath.forEach(groupId => {
|
|
81
|
+
var _groupsLookup$groupId;
|
|
82
|
+
|
|
83
|
+
if (!((_groupsLookup$groupId = groupsLookup[groupId]) != null && _groupsLookup$groupId.freeReordering)) {
|
|
84
|
+
var _allColumns$groupPath, _allColumns$groupPath2;
|
|
85
|
+
|
|
86
|
+
// Only consider group that are made of more than one column
|
|
87
|
+
if (columnIndex > 0 && (_allColumns$groupPath = allColumns[columnIndex - 1].groupPath) != null && _allColumns$groupPath.includes(groupId)) {
|
|
88
|
+
limitingGroupId = groupId;
|
|
89
|
+
} else if (columnIndex + 1 < allColumns.length && (_allColumns$groupPath2 = allColumns[columnIndex + 1].groupPath) != null && _allColumns$groupPath2.includes(groupId)) {
|
|
90
|
+
limitingGroupId = groupId;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
forbiddenIndexes.current = {};
|
|
95
|
+
|
|
96
|
+
for (let indexToForbid = 0; indexToForbid < allColumns.length; indexToForbid += 1) {
|
|
97
|
+
const leftIndex = indexToForbid <= columnIndex ? indexToForbid - 1 : indexToForbid;
|
|
98
|
+
const rightIndex = indexToForbid < columnIndex ? indexToForbid : indexToForbid + 1;
|
|
99
|
+
|
|
100
|
+
if (limitingGroupId !== null) {
|
|
101
|
+
var _allColumns$leftIndex, _allColumns$rightInde;
|
|
102
|
+
|
|
103
|
+
// verify this indexToForbid will be linked to the limiting group. Otherwise forbid it
|
|
104
|
+
let allowIndex = false;
|
|
105
|
+
|
|
106
|
+
if (leftIndex >= 0 && (_allColumns$leftIndex = allColumns[leftIndex].groupPath) != null && _allColumns$leftIndex.includes(limitingGroupId)) {
|
|
107
|
+
allowIndex = true;
|
|
108
|
+
} else if (rightIndex < allColumns.length && (_allColumns$rightInde = allColumns[rightIndex].groupPath) != null && _allColumns$rightInde.includes(limitingGroupId)) {
|
|
109
|
+
allowIndex = true;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!allowIndex) {
|
|
113
|
+
forbiddenIndexes.current[indexToForbid] = true;
|
|
114
|
+
}
|
|
115
|
+
} // Verify we are not splitting another group
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
if (leftIndex >= 0 && rightIndex < allColumns.length) {
|
|
119
|
+
var _allColumns$rightInde2, _allColumns$rightInde3;
|
|
120
|
+
|
|
121
|
+
(_allColumns$rightInde2 = allColumns[rightIndex]) == null ? void 0 : (_allColumns$rightInde3 = _allColumns$rightInde2.groupPath) == null ? void 0 : _allColumns$rightInde3.forEach(groupId => {
|
|
122
|
+
var _allColumns$leftIndex2;
|
|
123
|
+
|
|
124
|
+
if ((_allColumns$leftIndex2 = allColumns[leftIndex].groupPath) != null && _allColumns$leftIndex2.includes(groupId)) {
|
|
125
|
+
if (!draggingColumnGroupPath.includes(groupId)) {
|
|
126
|
+
var _groupsLookup$groupId2;
|
|
127
|
+
|
|
128
|
+
// moving here split the group groupId in two distincts chunks
|
|
129
|
+
if (!((_groupsLookup$groupId2 = groupsLookup[groupId]) != null && _groupsLookup$groupId2.freeReordering)) {
|
|
130
|
+
forbiddenIndexes.current[indexToForbid] = true;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
73
137
|
}, [props.disableColumnReorder, classes.columnHeaderDragging, logger, apiRef]);
|
|
74
138
|
const handleDragEnter = React.useCallback((params, event) => {
|
|
75
139
|
event.preventDefault(); // Prevent drag events propagation.
|
|
@@ -100,19 +164,47 @@ export const useGridColumnReorder = (apiRef, props) => {
|
|
|
100
164
|
const targetCol = apiRef.current.getColumn(params.field);
|
|
101
165
|
const dragColIndex = apiRef.current.getColumnIndex(dragColField, false);
|
|
102
166
|
const visibleColumns = apiRef.current.getVisibleColumns();
|
|
167
|
+
const allColumns = apiRef.current.getAllColumns();
|
|
103
168
|
const cursorMoveDirectionX = getCursorMoveDirectionX(cursorPosition.current, coordinates);
|
|
104
169
|
const hasMovedLeft = cursorMoveDirectionX === CURSOR_MOVE_DIRECTION_LEFT && targetColIndex < dragColIndex;
|
|
105
170
|
const hasMovedRight = cursorMoveDirectionX === CURSOR_MOVE_DIRECTION_RIGHT && dragColIndex < targetColIndex;
|
|
106
171
|
|
|
107
172
|
if (hasMovedLeft || hasMovedRight) {
|
|
108
173
|
let canBeReordered;
|
|
174
|
+
let indexOffsetInHiddenColumns = 0;
|
|
109
175
|
|
|
110
176
|
if (!targetCol.disableReorder) {
|
|
111
177
|
canBeReordered = true;
|
|
112
178
|
} else if (hasMovedLeft) {
|
|
113
|
-
canBeReordered =
|
|
179
|
+
canBeReordered = targetColVisibleIndex > 0 && !visibleColumns[targetColVisibleIndex - 1].disableReorder;
|
|
114
180
|
} else {
|
|
115
|
-
canBeReordered =
|
|
181
|
+
canBeReordered = targetColVisibleIndex < visibleColumns.length - 1 && !visibleColumns[targetColVisibleIndex + 1].disableReorder;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (forbiddenIndexes.current[targetColIndex]) {
|
|
185
|
+
let nextVisibleColumnField;
|
|
186
|
+
let indexWithOffset = targetColIndex + indexOffsetInHiddenColumns;
|
|
187
|
+
|
|
188
|
+
if (hasMovedLeft) {
|
|
189
|
+
nextVisibleColumnField = targetColVisibleIndex > 0 ? visibleColumns[targetColVisibleIndex - 1].field : null;
|
|
190
|
+
|
|
191
|
+
while (indexWithOffset > 0 && allColumns[indexWithOffset].field !== nextVisibleColumnField && forbiddenIndexes.current[indexWithOffset]) {
|
|
192
|
+
indexOffsetInHiddenColumns -= 1;
|
|
193
|
+
indexWithOffset = targetColIndex + indexOffsetInHiddenColumns;
|
|
194
|
+
}
|
|
195
|
+
} else {
|
|
196
|
+
nextVisibleColumnField = targetColVisibleIndex + 1 < visibleColumns.length ? visibleColumns[targetColVisibleIndex + 1].field : null;
|
|
197
|
+
|
|
198
|
+
while (indexWithOffset < allColumns.length - 1 && allColumns[indexWithOffset].field !== nextVisibleColumnField && forbiddenIndexes.current[indexWithOffset]) {
|
|
199
|
+
indexOffsetInHiddenColumns += 1;
|
|
200
|
+
indexWithOffset = targetColIndex + indexOffsetInHiddenColumns;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (forbiddenIndexes.current[indexWithOffset] || allColumns[indexWithOffset].field === nextVisibleColumnField) {
|
|
205
|
+
// If we ended up on a visible column, or a forbidden one, we can not do the reorder
|
|
206
|
+
canBeReordered = false;
|
|
207
|
+
}
|
|
116
208
|
}
|
|
117
209
|
|
|
118
210
|
const canBeReorderedProcessed = apiRef.current.unstable_applyPipeProcessors('canBeReordered', canBeReordered, {
|
|
@@ -120,7 +212,7 @@ export const useGridColumnReorder = (apiRef, props) => {
|
|
|
120
212
|
});
|
|
121
213
|
|
|
122
214
|
if (canBeReorderedProcessed) {
|
|
123
|
-
apiRef.current.setColumnIndex(dragColField, targetColIndex);
|
|
215
|
+
apiRef.current.setColumnIndex(dragColField, targetColIndex + indexOffsetInHiddenColumns);
|
|
124
216
|
}
|
|
125
217
|
}
|
|
126
218
|
|
|
@@ -4,7 +4,7 @@ import { ownerDocument, useEventCallback } from '@mui/material/utils';
|
|
|
4
4
|
import { gridClasses, useGridApiEventHandler, useGridApiOptionHandler, useGridNativeEventListener, useGridLogger } from '@mui/x-data-grid';
|
|
5
5
|
import { clamp, findParentElementFromClassName } from '@mui/x-data-grid/internals';
|
|
6
6
|
import { useTheme } from '@mui/material/styles';
|
|
7
|
-
import { findGridCellElementsFromCol, getFieldFromHeaderElem, findHeaderElementFromField } from '../../../utils/domUtils';
|
|
7
|
+
import { findGridCellElementsFromCol, getFieldFromHeaderElem, findHeaderElementFromField, findGroupHeaderElementsFromField } from '../../../utils/domUtils';
|
|
8
8
|
// TODO: remove support for Safari < 13.
|
|
9
9
|
// https://caniuse.com/#search=touch-action
|
|
10
10
|
//
|
|
@@ -104,6 +104,7 @@ export const useGridColumnResize = (apiRef, props) => {
|
|
|
104
104
|
const logger = useGridLogger(apiRef, 'useGridColumnResize');
|
|
105
105
|
const colDefRef = React.useRef();
|
|
106
106
|
const colElementRef = React.useRef();
|
|
107
|
+
const colGroupingElementRef = React.useRef();
|
|
107
108
|
const colCellElementsRef = React.useRef();
|
|
108
109
|
const theme = useTheme(); // To improve accessibility, the separator has padding on both sides.
|
|
109
110
|
// Clicking inside the padding area should be treated as a click in the separator.
|
|
@@ -124,7 +125,7 @@ export const useGridColumnResize = (apiRef, props) => {
|
|
|
124
125
|
colElementRef.current.style.width = `${newWidth}px`;
|
|
125
126
|
colElementRef.current.style.minWidth = `${newWidth}px`;
|
|
126
127
|
colElementRef.current.style.maxWidth = `${newWidth}px`;
|
|
127
|
-
colCellElementsRef.current.forEach(element => {
|
|
128
|
+
[...colCellElementsRef.current, ...colGroupingElementRef.current].forEach(element => {
|
|
128
129
|
const div = element;
|
|
129
130
|
let finalWidth;
|
|
130
131
|
|
|
@@ -182,7 +183,7 @@ export const useGridColumnResize = (apiRef, props) => {
|
|
|
182
183
|
const handleColumnResizeMouseDown = useEventCallback(({
|
|
183
184
|
colDef
|
|
184
185
|
}, event) => {
|
|
185
|
-
var _apiRef$current$colum;
|
|
186
|
+
var _apiRef$current$colum, _apiRef$current$colum2;
|
|
186
187
|
|
|
187
188
|
// Only handle left clicks
|
|
188
189
|
if (event.button !== 0) {
|
|
@@ -202,6 +203,7 @@ export const useGridColumnResize = (apiRef, props) => {
|
|
|
202
203
|
}, event);
|
|
203
204
|
colDefRef.current = colDef;
|
|
204
205
|
colElementRef.current = (_apiRef$current$colum = apiRef.current.columnHeadersContainerElementRef) == null ? void 0 : _apiRef$current$colum.current.querySelector(`[data-field="${colDef.field}"]`);
|
|
206
|
+
colGroupingElementRef.current = findGroupHeaderElementsFromField((_apiRef$current$colum2 = apiRef.current.columnHeadersContainerElementRef) == null ? void 0 : _apiRef$current$colum2.current, colDef.field);
|
|
205
207
|
colCellElementsRef.current = findGridCellElementsFromCol(colElementRef.current, apiRef.current);
|
|
206
208
|
const doc = ownerDocument(apiRef.current.rootElementRef.current);
|
|
207
209
|
doc.body.style.cursor = 'col-resize';
|
|
@@ -250,7 +252,7 @@ export const useGridColumnResize = (apiRef, props) => {
|
|
|
250
252
|
apiRef.current.publishEvent('columnResize', params, nativeEvent);
|
|
251
253
|
});
|
|
252
254
|
const handleTouchStart = useEventCallback(event => {
|
|
253
|
-
var _apiRef$current$
|
|
255
|
+
var _apiRef$current$colum3, _apiRef$current$colum4;
|
|
254
256
|
|
|
255
257
|
const cellSeparator = findParentElementFromClassName(event.target, gridClasses['columnSeparator--resizable']); // Let the event bubble if the target is not a col separator
|
|
256
258
|
|
|
@@ -273,12 +275,13 @@ export const useGridColumnResize = (apiRef, props) => {
|
|
|
273
275
|
colElementRef.current = findParentElementFromClassName(event.target, gridClasses.columnHeader);
|
|
274
276
|
const field = getFieldFromHeaderElem(colElementRef.current);
|
|
275
277
|
const colDef = apiRef.current.getColumn(field);
|
|
278
|
+
colGroupingElementRef.current = findGroupHeaderElementsFromField((_apiRef$current$colum3 = apiRef.current.columnHeadersContainerElementRef) == null ? void 0 : _apiRef$current$colum3.current, field);
|
|
276
279
|
logger.debug(`Start Resize on col ${colDef.field}`);
|
|
277
280
|
apiRef.current.publishEvent('columnResizeStart', {
|
|
278
281
|
field
|
|
279
282
|
}, event);
|
|
280
283
|
colDefRef.current = colDef;
|
|
281
|
-
colElementRef.current = findHeaderElementFromField((_apiRef$current$
|
|
284
|
+
colElementRef.current = findHeaderElementFromField((_apiRef$current$colum4 = apiRef.current.columnHeadersElementRef) == null ? void 0 : _apiRef$current$colum4.current, colDef.field);
|
|
282
285
|
colCellElementsRef.current = findGridCellElementsFromCol(colElementRef.current, apiRef.current);
|
|
283
286
|
resizeDirection.current = getResizeDirection(event.target, theme.direction);
|
|
284
287
|
initialOffsetToSeparator.current = computeOffsetToSeparator(touch.clientX, colElementRef.current.getBoundingClientRect(), resizeDirection.current);
|
|
@@ -319,9 +322,9 @@ export const useGridColumnResize = (apiRef, props) => {
|
|
|
319
322
|
};
|
|
320
323
|
}, [apiRef, handleTouchStart, stopListening]);
|
|
321
324
|
useGridNativeEventListener(apiRef, () => {
|
|
322
|
-
var _apiRef$current$
|
|
325
|
+
var _apiRef$current$colum5;
|
|
323
326
|
|
|
324
|
-
return (_apiRef$current$
|
|
327
|
+
return (_apiRef$current$colum5 = apiRef.current.columnHeadersElementRef) == null ? void 0 : _apiRef$current$colum5.current;
|
|
325
328
|
}, 'touchstart', handleTouchStart, {
|
|
326
329
|
passive: doesSupportTouchActionNone()
|
|
327
330
|
});
|
|
@@ -12,8 +12,8 @@ export declare function addPinnedRow({ groupingParams, rowModel, rowId, position
|
|
|
12
12
|
apiRef: React.MutableRefObject<GridApiPro>;
|
|
13
13
|
}): {
|
|
14
14
|
idRowsLookup: {
|
|
15
|
-
[x: string]:
|
|
16
|
-
[x: number]:
|
|
15
|
+
[x: string]: import("@mui/x-data-grid").GridValidRowModel;
|
|
16
|
+
[x: number]: import("@mui/x-data-grid").GridValidRowModel;
|
|
17
17
|
};
|
|
18
18
|
tree: {
|
|
19
19
|
[x: string]: import("@mui/x-data-grid").GridRowTreeNodeConfig;
|
|
@@ -21,8 +21,8 @@ export declare function addPinnedRow({ groupingParams, rowModel, rowId, position
|
|
|
21
21
|
};
|
|
22
22
|
additionalRowGroups: {
|
|
23
23
|
pinnedRows: {
|
|
24
|
-
top?: GridRowEntry<
|
|
25
|
-
bottom?: GridRowEntry<
|
|
24
|
+
top?: GridRowEntry<import("@mui/x-data-grid").GridValidRowModel>[] | undefined;
|
|
25
|
+
bottom?: GridRowEntry<import("@mui/x-data-grid").GridValidRowModel>[] | undefined;
|
|
26
26
|
};
|
|
27
27
|
};
|
|
28
28
|
groupingName: string;
|
package/index.js
CHANGED
|
@@ -106,6 +106,7 @@ DataGridProRaw.propTypes = {
|
|
|
106
106
|
* @default 3
|
|
107
107
|
*/
|
|
108
108
|
columnBuffer: PropTypes.number,
|
|
109
|
+
columnGroupingModel: PropTypes.arrayOf(PropTypes.object),
|
|
109
110
|
|
|
110
111
|
/**
|
|
111
112
|
* Set of columns of type [[GridColumns]].
|
|
@@ -274,6 +275,7 @@ DataGridProRaw.propTypes = {
|
|
|
274
275
|
* For each feature, if the flag is not explicitly set to `true`, the feature will be fully disabled and any property / method call will not have any effect.
|
|
275
276
|
*/
|
|
276
277
|
experimentalFeatures: PropTypes.shape({
|
|
278
|
+
columnGrouping: PropTypes.bool,
|
|
277
279
|
newEditingApi: PropTypes.bool,
|
|
278
280
|
preventCommitWhileValidating: PropTypes.bool,
|
|
279
281
|
rowPinning: PropTypes.bool,
|
|
@@ -1,4 +1,4 @@
|
|
|
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';
|
|
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, useGridColumnGrouping, columnGroupsStateInitializer, useGridColumnGroupingPreProcessors } 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';
|
|
@@ -21,6 +21,7 @@ export var useDataGridProComponent = function useDataGridProComponent(inputApiRe
|
|
|
21
21
|
* Register all pre-processors called during state initialization here.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
+
useGridColumnGroupingPreProcessors(apiRef, props);
|
|
24
25
|
useGridSelectionPreProcessors(apiRef, props);
|
|
25
26
|
useGridRowReorderPreProcessors(apiRef, props);
|
|
26
27
|
useGridTreeDataPreProcessors(apiRef, props);
|
|
@@ -51,6 +52,7 @@ export var useDataGridProComponent = function useDataGridProComponent(inputApiRe
|
|
|
51
52
|
useGridInitializeState(paginationStateInitializer, apiRef, props);
|
|
52
53
|
useGridInitializeState(rowsMetaStateInitializer, apiRef, props);
|
|
53
54
|
useGridInitializeState(columnMenuStateInitializer, apiRef, props);
|
|
55
|
+
useGridInitializeState(columnGroupsStateInitializer, apiRef, props);
|
|
54
56
|
useGridTreeData(apiRef);
|
|
55
57
|
useGridKeyboardNavigation(apiRef, props);
|
|
56
58
|
useGridSelection(apiRef, props);
|
|
@@ -61,6 +63,7 @@ export var useDataGridProComponent = function useDataGridProComponent(inputApiRe
|
|
|
61
63
|
useGridParamsApi(apiRef);
|
|
62
64
|
useGridDetailPanel(apiRef, props);
|
|
63
65
|
useGridColumnSpanning(apiRef);
|
|
66
|
+
useGridColumnGrouping(apiRef, props);
|
|
64
67
|
var useGridEditing = (_props$experimentalFe2 = props.experimentalFeatures) != null && _props$experimentalFe2.newEditingApi ? useGridEditing_new : useGridEditing_old;
|
|
65
68
|
useGridEditing(apiRef, props);
|
|
66
69
|
useGridFocus(apiRef, props);
|
|
@@ -13,7 +13,6 @@ import { useGridRootProps } from '../hooks/utils/useGridRootProps';
|
|
|
13
13
|
import { useGridApiContext } from '../hooks/utils/useGridApiContext';
|
|
14
14
|
import { gridPinnedColumnsSelector, GridPinnedPosition } from '../hooks/features/columnPinning';
|
|
15
15
|
import { filterColumns } from './DataGridProVirtualScroller';
|
|
16
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
17
16
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
18
17
|
|
|
19
18
|
var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
@@ -55,6 +54,7 @@ var GridColumnHeadersPinnedColumnHeaders = styled('div', {
|
|
|
55
54
|
height: '100%',
|
|
56
55
|
zIndex: 1,
|
|
57
56
|
display: 'flex',
|
|
57
|
+
flexDirection: 'column',
|
|
58
58
|
boxShadow: theme.shadows[2],
|
|
59
59
|
backgroundColor: theme.palette.background.default
|
|
60
60
|
}, theme.palette.mode === 'dark' && {
|
|
@@ -109,7 +109,8 @@ export var DataGridProColumnHeaders = /*#__PURE__*/React.forwardRef(function Dat
|
|
|
109
109
|
renderContext = _useGridColumnHeaders.renderContext,
|
|
110
110
|
getRootProps = _useGridColumnHeaders.getRootProps,
|
|
111
111
|
getInnerProps = _useGridColumnHeaders.getInnerProps,
|
|
112
|
-
|
|
112
|
+
getColumnHeaders = _useGridColumnHeaders.getColumnHeaders,
|
|
113
|
+
getColumnGroupHeaders = _useGridColumnHeaders.getColumnGroupHeaders;
|
|
113
114
|
|
|
114
115
|
var ownerState = {
|
|
115
116
|
leftPinnedColumns: leftPinnedColumns,
|
|
@@ -127,35 +128,42 @@ export var DataGridProColumnHeaders = /*#__PURE__*/React.forwardRef(function Dat
|
|
|
127
128
|
}) : null;
|
|
128
129
|
var innerProps = getInnerProps();
|
|
129
130
|
var pinnedColumnHeadersProps = {
|
|
130
|
-
role: innerProps.role
|
|
131
|
-
'aria-rowindex': innerProps['aria-rowindex']
|
|
131
|
+
role: innerProps.role
|
|
132
132
|
};
|
|
133
133
|
return /*#__PURE__*/_jsxs(GridColumnHeaders, _extends({
|
|
134
134
|
ref: ref,
|
|
135
135
|
className: className
|
|
136
136
|
}, getRootProps(other), {
|
|
137
|
-
children: [leftRenderContext && /*#__PURE__*/
|
|
137
|
+
children: [leftRenderContext && /*#__PURE__*/_jsxs(GridColumnHeadersPinnedColumnHeaders, _extends({
|
|
138
138
|
className: classes.leftPinnedColumns,
|
|
139
139
|
ownerState: {
|
|
140
140
|
side: GridPinnedPosition.left
|
|
141
141
|
}
|
|
142
142
|
}, pinnedColumnHeadersProps, {
|
|
143
|
-
children:
|
|
143
|
+
children: [getColumnGroupHeaders({
|
|
144
|
+
renderContext: leftRenderContext,
|
|
145
|
+
minFirstColumn: leftRenderContext.firstColumnIndex,
|
|
146
|
+
maxLastColumn: leftRenderContext.lastColumnIndex
|
|
147
|
+
}), getColumnHeaders({
|
|
144
148
|
renderContext: leftRenderContext,
|
|
145
149
|
minFirstColumn: leftRenderContext.firstColumnIndex,
|
|
146
150
|
maxLastColumn: leftRenderContext.lastColumnIndex
|
|
147
151
|
}, {
|
|
148
152
|
disableReorder: true
|
|
149
|
-
})
|
|
150
|
-
})), /*#__PURE__*/
|
|
153
|
+
})]
|
|
154
|
+
})), /*#__PURE__*/_jsxs(GridColumnHeadersInner, _extends({
|
|
151
155
|
isDragging: isDragging
|
|
152
156
|
}, innerProps, {
|
|
153
|
-
children:
|
|
157
|
+
children: [getColumnGroupHeaders({
|
|
154
158
|
renderContext: renderContext,
|
|
155
159
|
minFirstColumn: leftPinnedColumns.length,
|
|
156
160
|
maxLastColumn: visibleColumnFields.length - rightPinnedColumns.length
|
|
157
|
-
})
|
|
158
|
-
|
|
161
|
+
}), getColumnHeaders({
|
|
162
|
+
renderContext: renderContext,
|
|
163
|
+
minFirstColumn: leftPinnedColumns.length,
|
|
164
|
+
maxLastColumn: visibleColumnFields.length - rightPinnedColumns.length
|
|
165
|
+
})]
|
|
166
|
+
})), rightRenderContext && /*#__PURE__*/_jsxs(GridColumnHeadersPinnedColumnHeaders, _extends({
|
|
159
167
|
ownerState: {
|
|
160
168
|
side: GridPinnedPosition.right
|
|
161
169
|
},
|
|
@@ -164,14 +172,18 @@ export var DataGridProColumnHeaders = /*#__PURE__*/React.forwardRef(function Dat
|
|
|
164
172
|
paddingRight: scrollbarSize
|
|
165
173
|
}
|
|
166
174
|
}, pinnedColumnHeadersProps, {
|
|
167
|
-
children:
|
|
175
|
+
children: [getColumnGroupHeaders({
|
|
176
|
+
renderContext: rightRenderContext,
|
|
177
|
+
minFirstColumn: rightRenderContext.firstColumnIndex,
|
|
178
|
+
maxLastColumn: rightRenderContext.lastColumnIndex
|
|
179
|
+
}), getColumnHeaders({
|
|
168
180
|
renderContext: rightRenderContext,
|
|
169
181
|
minFirstColumn: rightRenderContext.firstColumnIndex,
|
|
170
182
|
maxLastColumn: rightRenderContext.lastColumnIndex
|
|
171
183
|
}, {
|
|
172
184
|
disableReorder: true,
|
|
173
185
|
separatorSide: GridColumnHeaderSeparatorSides.Left
|
|
174
|
-
})
|
|
186
|
+
})]
|
|
175
187
|
}))]
|
|
176
188
|
}));
|
|
177
189
|
});
|