@mui/x-data-grid-pro 5.8.0 → 5.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +333 -66
- package/DataGridPro/DataGridPro.d.ts +1 -1
- package/DataGridPro/DataGridPro.js +51 -3
- package/DataGridPro/useDataGridProComponent.js +9 -4
- package/DataGridPro/useDataGridProProps.js +20 -5
- package/LICENSE +12 -0
- package/README.md +7 -5
- package/components/DataGridProColumnHeaders.js +2 -8
- package/components/DataGridProVirtualScroller.js +7 -7
- package/components/GridDetailPanelToggleCell.js +13 -2
- package/components/GridGroupingCriteriaCell.js +2 -2
- package/components/GridRowReorderCell.d.ts +5 -0
- package/components/GridRowReorderCell.js +72 -0
- package/components/GridTreeDataGroupingCell.js +15 -4
- package/hooks/features/columnPinning/useGridColumnPinning.js +4 -4
- package/hooks/features/columnReorder/useGridColumnReorder.d.ts +0 -1
- package/hooks/features/columnReorder/useGridColumnReorder.js +8 -9
- package/hooks/features/columnResize/useGridColumnResize.d.ts +0 -1
- package/hooks/features/columnResize/useGridColumnResize.js +31 -20
- package/hooks/features/detailPanel/useGridDetailPanel.js +14 -6
- package/hooks/features/detailPanel/useGridDetailPanelCache.js +2 -2
- package/hooks/features/index.d.ts +1 -1
- package/hooks/features/index.js +1 -1
- package/hooks/features/infiniteLoader/useGridInfiniteLoader.d.ts +0 -1
- package/hooks/features/infiniteLoader/useGridInfiniteLoader.js +4 -5
- package/hooks/features/rowGrouping/createGroupingColDef.d.ts +1 -1
- package/hooks/features/rowGrouping/gridRowGroupingInterfaces.d.ts +1 -1
- package/hooks/features/rowGrouping/gridRowGroupingUtils.js +4 -4
- package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +0 -2
- package/hooks/features/rowGrouping/useGridRowGrouping.js +8 -12
- package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +2 -2
- 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/hooks/features/treeData/useGridTreeData.d.ts +0 -3
- package/hooks/features/treeData/useGridTreeData.js +2 -8
- package/index.d.ts +6 -1
- package/index.js +7 -3
- package/internals/index.d.ts +19 -0
- package/internals/index.js +17 -0
- package/internals/package.json +6 -0
- package/legacy/DataGridPro/DataGridPro.js +51 -3
- package/legacy/DataGridPro/useDataGridProComponent.js +9 -4
- package/legacy/DataGridPro/useDataGridProProps.js +20 -5
- package/legacy/components/DataGridProColumnHeaders.js +2 -8
- package/legacy/components/DataGridProVirtualScroller.js +7 -7
- package/legacy/components/GridDetailPanelToggleCell.js +13 -2
- package/legacy/components/GridGroupingCriteriaCell.js +2 -2
- package/legacy/components/GridRowReorderCell.js +74 -0
- package/legacy/components/GridTreeDataGroupingCell.js +15 -4
- package/legacy/hooks/features/columnPinning/useGridColumnPinning.js +4 -4
- package/legacy/hooks/features/columnReorder/useGridColumnReorder.js +8 -9
- package/legacy/hooks/features/columnResize/useGridColumnResize.js +31 -20
- package/legacy/hooks/features/detailPanel/useGridDetailPanel.js +14 -6
- package/legacy/hooks/features/detailPanel/useGridDetailPanelCache.js +2 -2
- package/legacy/hooks/features/index.js +1 -1
- package/legacy/hooks/features/infiniteLoader/useGridInfiniteLoader.js +4 -5
- package/legacy/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -5
- package/legacy/hooks/features/rowGrouping/useGridRowGrouping.js +8 -12
- package/legacy/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +2 -2
- 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/hooks/features/treeData/useGridTreeData.js +2 -8
- package/legacy/index.js +7 -3
- package/legacy/internals/index.js +17 -0
- package/legacy/models/gridRowOrderChangeParams.js +1 -0
- package/legacy/models/index.js +1 -2
- package/legacy/typeOverloads/index.js +1 -0
- package/legacy/utils/domUtils.js +30 -3
- package/legacy/utils/index.js +1 -0
- package/legacy/utils/releaseInfo.js +1 -1
- package/legacy/utils/tree/buildRowTree.js +11 -4
- package/legacy/utils/tree/index.js +1 -0
- package/models/dataGridProProps.d.ts +36 -24
- package/models/gridApiPro.d.ts +3 -2
- package/models/gridRowOrderChangeParams.d.ts +18 -0
- package/models/gridRowOrderChangeParams.js +1 -0
- package/models/gridStatePro.d.ts +4 -3
- package/models/index.d.ts +1 -2
- package/models/index.js +1 -2
- package/modern/DataGridPro/DataGridPro.js +51 -3
- package/modern/DataGridPro/useDataGridProComponent.js +9 -4
- package/modern/DataGridPro/useDataGridProProps.js +16 -3
- package/modern/components/DataGridProColumnHeaders.js +2 -8
- package/modern/components/DataGridProVirtualScroller.js +7 -7
- package/modern/components/GridDetailPanelToggleCell.js +13 -2
- package/modern/components/GridGroupingCriteriaCell.js +2 -2
- package/modern/components/GridRowReorderCell.js +72 -0
- package/modern/components/GridTreeDataGroupingCell.js +15 -4
- package/modern/hooks/features/columnPinning/useGridColumnPinning.js +4 -4
- package/modern/hooks/features/columnReorder/useGridColumnReorder.js +8 -9
- package/modern/hooks/features/columnResize/useGridColumnResize.js +31 -20
- package/modern/hooks/features/detailPanel/useGridDetailPanel.js +14 -6
- package/modern/hooks/features/detailPanel/useGridDetailPanelCache.js +2 -2
- package/modern/hooks/features/index.js +1 -1
- package/modern/hooks/features/infiniteLoader/useGridInfiniteLoader.js +4 -5
- package/modern/hooks/features/rowGrouping/gridRowGroupingUtils.js +4 -4
- package/modern/hooks/features/rowGrouping/useGridRowGrouping.js +8 -12
- package/modern/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +2 -2
- 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/hooks/features/treeData/useGridTreeData.js +2 -8
- package/modern/index.js +7 -3
- package/modern/internals/index.js +17 -0
- package/modern/models/gridRowOrderChangeParams.js +1 -0
- package/modern/models/index.js +1 -2
- package/modern/typeOverloads/index.js +1 -0
- package/modern/utils/domUtils.js +30 -3
- package/modern/utils/index.js +1 -0
- package/modern/utils/releaseInfo.js +1 -1
- package/modern/utils/tree/buildRowTree.js +9 -2
- package/modern/utils/tree/index.js +1 -0
- package/node/DataGridPro/DataGridPro.js +51 -3
- package/node/DataGridPro/useDataGridProComponent.js +12 -5
- package/node/DataGridPro/useDataGridProProps.js +21 -5
- package/node/components/DataGridProColumnHeaders.js +1 -7
- package/node/components/DataGridProVirtualScroller.js +6 -6
- package/node/components/GridDetailPanelToggleCell.js +13 -2
- package/node/components/GridGroupingCriteriaCell.js +1 -1
- package/node/components/GridRowReorderCell.js +92 -0
- package/node/components/GridTreeDataGroupingCell.js +14 -3
- package/node/hooks/features/columnPinning/useGridColumnPinning.js +3 -3
- package/node/hooks/features/columnReorder/useGridColumnReorder.js +7 -8
- package/node/hooks/features/columnResize/useGridColumnResize.js +30 -19
- package/node/hooks/features/detailPanel/useGridDetailPanel.js +13 -5
- package/node/hooks/features/detailPanel/useGridDetailPanelCache.js +1 -1
- package/node/hooks/features/index.js +4 -4
- package/node/hooks/features/infiniteLoader/useGridInfiniteLoader.js +3 -4
- package/node/hooks/features/rowGrouping/gridRowGroupingUtils.js +4 -4
- package/node/hooks/features/rowGrouping/useGridRowGrouping.js +7 -11
- package/node/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +4 -4
- 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/hooks/features/treeData/useGridTreeData.js +1 -6
- package/node/index.js +45 -3
- package/node/internals/index.js +193 -0
- package/node/models/gridRowOrderChangeParams.js +5 -0
- package/node/models/index.js +4 -4
- package/node/typeOverloads/index.js +18 -0
- package/node/utils/domUtils.js +30 -3
- package/node/utils/index.js +18 -0
- package/node/utils/releaseInfo.js +1 -1
- package/node/utils/tree/buildRowTree.js +12 -2
- package/node/utils/tree/index.js +13 -0
- package/package.json +8 -8
- package/typeOverloads/index.d.ts +1 -0
- package/typeOverloads/index.js +1 -0
- package/typeOverloads/modules.d.ts +41 -15
- package/typeOverloads/package.json +6 -0
- package/utils/domUtils.d.ts +2 -1
- package/utils/domUtils.js +30 -3
- package/utils/index.d.ts +1 -0
- package/utils/index.js +1 -0
- package/utils/package.json +6 -0
- package/utils/releaseInfo.js +1 -1
- package/utils/tree/buildRowTree.d.ts +1 -0
- package/utils/tree/buildRowTree.js +9 -2
- package/utils/tree/index.d.ts +1 -0
- package/utils/tree/index.js +1 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { ownerDocument, useEventCallback } from '@mui/material/utils';
|
|
4
|
-
import {
|
|
4
|
+
import { gridClasses, GridColumnHeaderSeparatorSides, useGridApiEventHandler, useGridApiOptionHandler, useGridNativeEventListener, useGridLogger } from '@mui/x-data-grid';
|
|
5
5
|
import { clamp, findParentElementFromClassName } from '@mui/x-data-grid/internals';
|
|
6
6
|
import { findGridCellElementsFromCol, getFieldFromHeaderElem, findHeaderElementFromField } from '../../../utils/domUtils';
|
|
7
7
|
// TODO: remove support for Safari < 13.
|
|
@@ -80,7 +80,6 @@ export const columnResizeStateInitializer = state => _extends({}, state, {
|
|
|
80
80
|
}
|
|
81
81
|
});
|
|
82
82
|
/**
|
|
83
|
-
* Only available in DataGridPro
|
|
84
83
|
* @requires useGridColumns (method, event)
|
|
85
84
|
* TODO: improve experience for last column
|
|
86
85
|
*/
|
|
@@ -100,17 +99,29 @@ export const useGridColumnResize = (apiRef, props) => {
|
|
|
100
99
|
|
|
101
100
|
const updateWidth = newWidth => {
|
|
102
101
|
logger.debug(`Updating width to ${newWidth} for col ${colDefRef.current.field}`);
|
|
102
|
+
const prevWidth = colElementRef.current.offsetWidth;
|
|
103
|
+
const widthDiff = newWidth - prevWidth;
|
|
103
104
|
colDefRef.current.computedWidth = newWidth;
|
|
104
105
|
colDefRef.current.width = newWidth;
|
|
105
|
-
colDefRef.current.flex =
|
|
106
|
+
colDefRef.current.flex = 0;
|
|
106
107
|
colElementRef.current.style.width = `${newWidth}px`;
|
|
107
108
|
colElementRef.current.style.minWidth = `${newWidth}px`;
|
|
108
109
|
colElementRef.current.style.maxWidth = `${newWidth}px`;
|
|
109
110
|
colCellElementsRef.current.forEach(element => {
|
|
110
111
|
const div = element;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
div.
|
|
112
|
+
let finalWidth;
|
|
113
|
+
|
|
114
|
+
if (div.getAttribute('aria-colspan') === '1') {
|
|
115
|
+
finalWidth = `${newWidth}px`;
|
|
116
|
+
} else {
|
|
117
|
+
// Cell with colspan > 1 cannot be just updated width new width.
|
|
118
|
+
// Instead, we add width diff to the current width.
|
|
119
|
+
finalWidth = `${div.offsetWidth + widthDiff}px`;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
div.style.width = finalWidth;
|
|
123
|
+
div.style.minWidth = finalWidth;
|
|
124
|
+
div.style.maxWidth = finalWidth;
|
|
114
125
|
});
|
|
115
126
|
};
|
|
116
127
|
|
|
@@ -120,12 +131,12 @@ export const useGridColumnResize = (apiRef, props) => {
|
|
|
120
131
|
apiRef.current.updateColumn(colDefRef.current);
|
|
121
132
|
clearTimeout(stopResizeEventTimeout.current);
|
|
122
133
|
stopResizeEventTimeout.current = setTimeout(() => {
|
|
123
|
-
apiRef.current.publishEvent(
|
|
134
|
+
apiRef.current.publishEvent('columnResizeStop', null, nativeEvent);
|
|
124
135
|
|
|
125
136
|
if (colDefRef.current) {
|
|
126
137
|
var _colDefRef$current;
|
|
127
138
|
|
|
128
|
-
apiRef.current.publishEvent(
|
|
139
|
+
apiRef.current.publishEvent('columnWidthChange', {
|
|
129
140
|
element: colElementRef.current,
|
|
130
141
|
colDef: colDefRef.current,
|
|
131
142
|
width: (_colDefRef$current = colDefRef.current) == null ? void 0 : _colDefRef$current.computedWidth
|
|
@@ -149,7 +160,7 @@ export const useGridColumnResize = (apiRef, props) => {
|
|
|
149
160
|
colDef: colDefRef.current,
|
|
150
161
|
width: newWidth
|
|
151
162
|
};
|
|
152
|
-
apiRef.current.publishEvent(
|
|
163
|
+
apiRef.current.publishEvent('columnResize', params, nativeEvent);
|
|
153
164
|
});
|
|
154
165
|
const handleColumnResizeMouseDown = useEventCallback(({
|
|
155
166
|
colDef
|
|
@@ -169,12 +180,12 @@ export const useGridColumnResize = (apiRef, props) => {
|
|
|
169
180
|
|
|
170
181
|
event.preventDefault();
|
|
171
182
|
logger.debug(`Start Resize on col ${colDef.field}`);
|
|
172
|
-
apiRef.current.publishEvent(
|
|
183
|
+
apiRef.current.publishEvent('columnResizeStart', {
|
|
173
184
|
field: colDef.field
|
|
174
185
|
}, event);
|
|
175
186
|
colDefRef.current = colDef;
|
|
176
187
|
colElementRef.current = (_apiRef$current$colum = apiRef.current.columnHeadersContainerElementRef) == null ? void 0 : _apiRef$current$colum.current.querySelector(`[data-field="${colDef.field}"]`);
|
|
177
|
-
colCellElementsRef.current = findGridCellElementsFromCol(colElementRef.current);
|
|
188
|
+
colCellElementsRef.current = findGridCellElementsFromCol(colElementRef.current, apiRef.current);
|
|
178
189
|
const doc = ownerDocument(apiRef.current.rootElementRef.current);
|
|
179
190
|
doc.body.style.cursor = 'col-resize';
|
|
180
191
|
separatorSide.current = getSeparatorSide(event.currentTarget);
|
|
@@ -194,7 +205,7 @@ export const useGridColumnResize = (apiRef, props) => {
|
|
|
194
205
|
apiRef.current.updateColumn(colDefRef.current);
|
|
195
206
|
clearTimeout(stopResizeEventTimeout.current);
|
|
196
207
|
stopResizeEventTimeout.current = setTimeout(() => {
|
|
197
|
-
apiRef.current.publishEvent(
|
|
208
|
+
apiRef.current.publishEvent('columnResizeStop', null, nativeEvent);
|
|
198
209
|
});
|
|
199
210
|
logger.debug(`Updating col ${colDefRef.current.field} with new width: ${colDefRef.current.width}`);
|
|
200
211
|
});
|
|
@@ -219,7 +230,7 @@ export const useGridColumnResize = (apiRef, props) => {
|
|
|
219
230
|
colDef: colDefRef.current,
|
|
220
231
|
width: newWidth
|
|
221
232
|
};
|
|
222
|
-
apiRef.current.publishEvent(
|
|
233
|
+
apiRef.current.publishEvent('columnResize', params, nativeEvent);
|
|
223
234
|
});
|
|
224
235
|
const handleTouchStart = useEventCallback(event => {
|
|
225
236
|
var _apiRef$current$colum2;
|
|
@@ -246,12 +257,12 @@ export const useGridColumnResize = (apiRef, props) => {
|
|
|
246
257
|
const field = getFieldFromHeaderElem(colElementRef.current);
|
|
247
258
|
const colDef = apiRef.current.getColumn(field);
|
|
248
259
|
logger.debug(`Start Resize on col ${colDef.field}`);
|
|
249
|
-
apiRef.current.publishEvent(
|
|
260
|
+
apiRef.current.publishEvent('columnResizeStart', {
|
|
250
261
|
field
|
|
251
262
|
}, event);
|
|
252
263
|
colDefRef.current = colDef;
|
|
253
264
|
colElementRef.current = findHeaderElementFromField((_apiRef$current$colum2 = apiRef.current.columnHeadersElementRef) == null ? void 0 : _apiRef$current$colum2.current, colDef.field);
|
|
254
|
-
colCellElementsRef.current = findGridCellElementsFromCol(colElementRef.current);
|
|
265
|
+
colCellElementsRef.current = findGridCellElementsFromCol(colElementRef.current, apiRef.current);
|
|
255
266
|
separatorSide.current = getSeparatorSide(event.target);
|
|
256
267
|
initialOffsetToSeparator.current = computeOffsetToSeparator(touch.clientX, colElementRef.current.getBoundingClientRect(), separatorSide.current);
|
|
257
268
|
const doc = ownerDocument(event.currentTarget);
|
|
@@ -297,9 +308,9 @@ export const useGridColumnResize = (apiRef, props) => {
|
|
|
297
308
|
}, 'touchstart', handleTouchStart, {
|
|
298
309
|
passive: doesSupportTouchActionNone()
|
|
299
310
|
});
|
|
300
|
-
useGridApiEventHandler(apiRef,
|
|
301
|
-
useGridApiEventHandler(apiRef,
|
|
302
|
-
useGridApiEventHandler(apiRef,
|
|
303
|
-
useGridApiOptionHandler(apiRef,
|
|
304
|
-
useGridApiOptionHandler(apiRef,
|
|
311
|
+
useGridApiEventHandler(apiRef, 'columnSeparatorMouseDown', handleColumnResizeMouseDown);
|
|
312
|
+
useGridApiEventHandler(apiRef, 'columnResizeStart', handleResizeStart);
|
|
313
|
+
useGridApiEventHandler(apiRef, 'columnResizeStop', handleResizeStop);
|
|
314
|
+
useGridApiOptionHandler(apiRef, 'columnResize', props.onColumnResize);
|
|
315
|
+
useGridApiOptionHandler(apiRef, 'columnWidthChange', props.onColumnWidthChange);
|
|
305
316
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { useGridSelector, useGridApiEventHandler, useGridApiMethod } from '@mui/x-data-grid';
|
|
4
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';
|
|
@@ -35,14 +35,22 @@ 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 (
|
|
38
|
+
if (props.getDetailPanelContent == null) {
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
|
|
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
|
-
useGridApiEventHandler(apiRef,
|
|
45
|
-
useGridApiEventHandler(apiRef,
|
|
52
|
+
useGridApiEventHandler(apiRef, 'cellClick', handleCellClick);
|
|
53
|
+
useGridApiEventHandler(apiRef, 'cellKeyDown', handleCellKeyDown);
|
|
46
54
|
const addDetailHeight = React.useCallback((initialValue, row) => {
|
|
47
55
|
var _heightCache$row$id;
|
|
48
56
|
|
|
@@ -64,7 +72,7 @@ export const useGridDetailPanel = (apiRef, props) => {
|
|
|
64
72
|
propModel: props.detailPanelExpandedRowIds,
|
|
65
73
|
propOnChange: props.onDetailPanelExpandedRowIdsChange,
|
|
66
74
|
stateSelector: gridDetailPanelExpandedRowIdsSelector,
|
|
67
|
-
changeEvent:
|
|
75
|
+
changeEvent: 'detailPanelsExpandedRowIdsChange'
|
|
68
76
|
});
|
|
69
77
|
const toggleDetailPanel = React.useCallback(id => {
|
|
70
78
|
if (props.getDetailPanelContent == null) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import { useGridApiEventHandler, gridRowIdsSelector
|
|
3
|
+
import { useGridApiEventHandler, gridRowIdsSelector } from '@mui/x-data-grid';
|
|
4
4
|
|
|
5
5
|
function cacheContentAndHeight(apiRef, getDetailPanelContent, getDetailPanelHeight) {
|
|
6
6
|
if (typeof getDetailPanelContent !== 'function') {
|
|
@@ -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,
|
|
42
|
+
useGridApiEventHandler(apiRef, 'sortedRowsSet', updateCaches);
|
|
43
43
|
const isFirstRender = React.useRef(true);
|
|
44
44
|
|
|
45
45
|
if (isFirstRender.current) {
|
package/hooks/features/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import * as React from 'react';
|
|
|
2
2
|
import { GridApiPro } from '../../../models/gridApiPro';
|
|
3
3
|
import { DataGridProProcessedProps } from '../../../models/dataGridProProps';
|
|
4
4
|
/**
|
|
5
|
-
* Only available in DataGridPro
|
|
6
5
|
* @requires useGridColumns (state)
|
|
7
6
|
* @requires useGridDimensions (method) - can be after
|
|
8
7
|
* @requires useGridScroll (method
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { useGridSelector,
|
|
2
|
+
import { useGridSelector, useGridApiEventHandler, useGridApiOptionHandler, gridVisibleColumnDefinitionsSelector, gridRowsMetaSelector } from '@mui/x-data-grid';
|
|
3
3
|
import { useGridVisibleRows } from '@mui/x-data-grid/internals';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Only available in DataGridPro
|
|
7
6
|
* @requires useGridColumns (state)
|
|
8
7
|
* @requires useGridDimensions (method) - can be after
|
|
9
8
|
* @requires useGridScroll (method
|
|
@@ -34,7 +33,7 @@ export const useGridInfiniteLoader = (apiRef, props) => {
|
|
|
34
33
|
viewportPageSize,
|
|
35
34
|
virtualRowsCount: currentPage.rows.length
|
|
36
35
|
};
|
|
37
|
-
apiRef.current.publishEvent(
|
|
36
|
+
apiRef.current.publishEvent('rowsScrollEnd', rowScrollEndParam);
|
|
38
37
|
isInScrollBottomArea.current = true;
|
|
39
38
|
}
|
|
40
39
|
}, [contentHeight, props.scrollEndThreshold, visibleColumns, apiRef, currentPage.rows.length]);
|
|
@@ -47,6 +46,6 @@ export const useGridInfiniteLoader = (apiRef, props) => {
|
|
|
47
46
|
top
|
|
48
47
|
});
|
|
49
48
|
}, [handleRowsScrollEnd]);
|
|
50
|
-
useGridApiEventHandler(apiRef,
|
|
51
|
-
useGridApiOptionHandler(apiRef,
|
|
49
|
+
useGridApiEventHandler(apiRef, 'rowsScroll', handleGridScroll);
|
|
50
|
+
useGridApiOptionHandler(apiRef, 'rowsScrollEnd', props.onRowsScrollEnd);
|
|
52
51
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { GridColDef, GridStateColDef } from '@mui/x-data-grid';
|
|
3
3
|
import { GridColumnRawLookup } from '@mui/x-data-grid/internals';
|
|
4
|
-
import { GridGroupingColDefOverride } from '../../../models';
|
|
4
|
+
import { GridGroupingColDefOverride } from '../../../models/gridGroupingColDefOverride';
|
|
5
5
|
import { GridApiPro } from '../../../models/gridApiPro';
|
|
6
6
|
interface CreateGroupingColDefMonoCriteriaParams {
|
|
7
7
|
columnsLookup: GridColumnRawLookup;
|
|
@@ -24,7 +24,7 @@ export interface GridRowGroupingApi {
|
|
|
24
24
|
*/
|
|
25
25
|
addRowGroupingCriteria: (groupingCriteriaField: string, groupingIndex?: number) => void;
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* Remove the field from the row grouping model.
|
|
28
28
|
* @param {string} groupingCriteriaField The field from which we want to stop grouping the rows.
|
|
29
29
|
*/
|
|
30
30
|
removeRowGroupingCriteria: (groupingCriteriaField: string) => void;
|
|
@@ -23,12 +23,12 @@ export const isGroupingColumn = field => field === GRID_ROW_GROUPING_SINGLE_GROU
|
|
|
23
23
|
/**
|
|
24
24
|
* When filtering a group, we only want to filter according to the items related to this grouping column.
|
|
25
25
|
*/
|
|
26
|
-
const shouldApplyFilterItemOnGroup = (
|
|
27
|
-
if (
|
|
26
|
+
const shouldApplyFilterItemOnGroup = (columnField, node) => {
|
|
27
|
+
if (columnField === GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD) {
|
|
28
28
|
return true;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const groupingCriteriaField = getRowGroupingCriteriaFromGroupingField(
|
|
31
|
+
const groupingCriteriaField = getRowGroupingCriteriaFromGroupingField(columnField);
|
|
32
32
|
return groupingCriteriaField === node.groupingField;
|
|
33
33
|
};
|
|
34
34
|
/**
|
|
@@ -56,7 +56,7 @@ export const filterRowTreeFromGroupingColumns = params => {
|
|
|
56
56
|
if (!isRowMatchingFilters) {
|
|
57
57
|
isMatchingFilters = true;
|
|
58
58
|
} else {
|
|
59
|
-
const shouldApplyItem = node.isAutoGenerated ?
|
|
59
|
+
const shouldApplyItem = node.isAutoGenerated ? columnField => shouldApplyFilterItemOnGroup(columnField, node) : undefined;
|
|
60
60
|
isMatchingFilters = isRowMatchingFilters(node.id, shouldApplyItem);
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -4,10 +4,8 @@ import { GridApiPro } from '../../../models/gridApiPro';
|
|
|
4
4
|
import { DataGridProProcessedProps } from '../../../models/dataGridProProps';
|
|
5
5
|
export declare const rowGroupingStateInitializer: GridStateInitializer<Pick<DataGridProProcessedProps, 'rowGroupingModel' | 'initialState'>>;
|
|
6
6
|
/**
|
|
7
|
-
* Only available in DataGridPro
|
|
8
7
|
* @requires useGridColumns (state, method) - can be after, async only
|
|
9
8
|
* @requires useGridRows (state, method) - can be after, async only
|
|
10
9
|
* @requires useGridParamsApi (method) - can be after, async only
|
|
11
|
-
* TODO: Move the the Premium plan once available and remove the `experimentalFeatures.rowGrouping` flag
|
|
12
10
|
*/
|
|
13
11
|
export declare const useGridRowGrouping: (apiRef: React.MutableRefObject<GridApiPro>, props: Pick<DataGridProProcessedProps, 'initialState' | 'rowGroupingModel' | 'onRowGroupingModelChange' | 'defaultGroupingExpansionDepth' | 'isGroupExpandedByDefault' | 'groupingColDef' | 'rowGroupingColumnMode' | 'disableRowGrouping'>) => void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import Divider from '@mui/material/Divider';
|
|
4
|
-
import {
|
|
4
|
+
import { useGridApiEventHandler, useGridApiMethod, gridFilteredDescendantCountLookupSelector } from '@mui/x-data-grid';
|
|
5
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';
|
|
@@ -19,11 +19,9 @@ export const rowGroupingStateInitializer = (state, props) => {
|
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
21
|
/**
|
|
22
|
-
* Only available in DataGridPro
|
|
23
22
|
* @requires useGridColumns (state, method) - can be after, async only
|
|
24
23
|
* @requires useGridRows (state, method) - can be after, async only
|
|
25
24
|
* @requires useGridParamsApi (method) - can be after, async only
|
|
26
|
-
* TODO: Move the the Premium plan once available and remove the `experimentalFeatures.rowGrouping` flag
|
|
27
25
|
*/
|
|
28
26
|
|
|
29
27
|
export const useGridRowGrouping = (apiRef, props) => {
|
|
@@ -32,7 +30,7 @@ export const useGridRowGrouping = (apiRef, props) => {
|
|
|
32
30
|
propModel: props.rowGroupingModel,
|
|
33
31
|
propOnChange: props.onRowGroupingModelChange,
|
|
34
32
|
stateSelector: gridRowGroupingModelSelector,
|
|
35
|
-
changeEvent:
|
|
33
|
+
changeEvent: 'rowGroupingModelChange'
|
|
36
34
|
});
|
|
37
35
|
/**
|
|
38
36
|
* API METHODS
|
|
@@ -177,21 +175,19 @@ export const useGridRowGrouping = (apiRef, props) => {
|
|
|
177
175
|
rowGrouping: _extends({}, state.rowGrouping, {
|
|
178
176
|
unstable_sanitizedModelOnLastRowTreeCreation: rowGroupingModel
|
|
179
177
|
})
|
|
180
|
-
}));
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
apiRef.current.updateColumns([]);
|
|
178
|
+
}));
|
|
179
|
+
apiRef.current.unstable_requestPipeProcessorsApplication('hydrateColumns');
|
|
184
180
|
setStrategyAvailability(apiRef, props.disableRowGrouping); // Refresh the row tree creation strategy processing
|
|
185
181
|
// TODO: Add a clean way to re-run a strategy processing without publishing a private event
|
|
186
182
|
|
|
187
183
|
if (apiRef.current.unstable_getActiveStrategy('rowTree') === ROW_GROUPING_STRATEGY) {
|
|
188
|
-
apiRef.current.publishEvent(
|
|
184
|
+
apiRef.current.publishEvent('activeStrategyProcessorChange', 'rowTreeCreation');
|
|
189
185
|
}
|
|
190
186
|
}
|
|
191
187
|
}, [apiRef, props.disableRowGrouping]);
|
|
192
|
-
useGridApiEventHandler(apiRef,
|
|
193
|
-
useGridApiEventHandler(apiRef,
|
|
194
|
-
useGridApiEventHandler(apiRef,
|
|
188
|
+
useGridApiEventHandler(apiRef, 'cellKeyDown', handleCellKeyDown);
|
|
189
|
+
useGridApiEventHandler(apiRef, 'columnsChange', checkGroupingColumnsModelDiff);
|
|
190
|
+
useGridApiEventHandler(apiRef, 'rowGroupingModelChange', checkGroupingColumnsModelDiff);
|
|
195
191
|
/**
|
|
196
192
|
* EFFECTS
|
|
197
193
|
*/
|
|
@@ -2,11 +2,11 @@ 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
4
|
import { useGridRegisterPipeProcessor, useGridRegisterStrategyProcessor } from '@mui/x-data-grid/internals';
|
|
5
|
+
import { sortRowTree } from '../../../utils/tree/sortRowTree';
|
|
6
|
+
import { buildRowTree } from '../../../utils/tree/buildRowTree';
|
|
5
7
|
import { gridRowGroupingModelSelector, gridRowGroupingSanitizedModelSelector } from './gridRowGroupingSelector';
|
|
6
8
|
import { createGroupingColDefForAllGroupingCriteria, createGroupingColDefForOneGroupingCriteria } from './createGroupingColDef';
|
|
7
9
|
import { filterRowTreeFromGroupingColumns, getColDefOverrides, ROW_GROUPING_STRATEGY, isGroupingColumn, setStrategyAvailability } from './gridRowGroupingUtils';
|
|
8
|
-
import { buildRowTree } from '../../../utils/tree/buildRowTree';
|
|
9
|
-
import { sortRowTree } from '../../../utils/tree/sortRowTree';
|
|
10
10
|
export const useGridRowGroupingPreProcessors = (apiRef, props) => {
|
|
11
11
|
const getGroupingColDefs = React.useCallback(columnsState => {
|
|
12
12
|
if (props.disableRowGrouping) {
|
|
@@ -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, 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('rowOrderChange', rowOrderChangeParams);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
setDragRowId('');
|
|
105
|
+
}, [isRowReorderDisabled, logger, apiRef, dragRowId]);
|
|
106
|
+
useGridApiEventHandler(apiRef, 'rowDragStart', handleDragStart);
|
|
107
|
+
useGridApiEventHandler(apiRef, 'rowDragOver', handleDragOver);
|
|
108
|
+
useGridApiEventHandler(apiRef, 'rowDragEnd', handleDragEnd);
|
|
109
|
+
useGridApiEventHandler(apiRef, 'cellDragOver', handleDragOver);
|
|
110
|
+
useGridApiOptionHandler(apiRef, '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 '../../../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
|
+
};
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { useGridApiEventHandler,
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Only available in DataGridPro
|
|
6
|
-
*/
|
|
2
|
+
import { useGridApiEventHandler, gridFilteredDescendantCountLookupSelector } from '@mui/x-data-grid';
|
|
7
3
|
export const useGridTreeData = apiRef => {
|
|
8
4
|
/**
|
|
9
5
|
* EVENTS
|
|
@@ -14,8 +10,6 @@ export const useGridTreeData = apiRef => {
|
|
|
14
10
|
if (cellParams.colDef.type === 'treeDataGroup' && event.key === ' ' && !event.shiftKey) {
|
|
15
11
|
var _gridFilteredDescenda;
|
|
16
12
|
|
|
17
|
-
event.stopPropagation();
|
|
18
|
-
event.preventDefault();
|
|
19
13
|
const filteredDescendantCount = (_gridFilteredDescenda = gridFilteredDescendantCountLookupSelector(apiRef)[params.id]) != null ? _gridFilteredDescenda : 0;
|
|
20
14
|
|
|
21
15
|
if (filteredDescendantCount === 0) {
|
|
@@ -25,5 +19,5 @@ export const useGridTreeData = apiRef => {
|
|
|
25
19
|
apiRef.current.setRowChildrenExpansion(params.id, !params.rowNode.childrenExpanded);
|
|
26
20
|
}
|
|
27
21
|
}, [apiRef]);
|
|
28
|
-
useGridApiEventHandler(apiRef,
|
|
22
|
+
useGridApiEventHandler(apiRef, 'cellKeyDown', handleCellKeyDown);
|
|
29
23
|
};
|