@mui/x-data-grid-pro 5.6.0 → 5.8.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 +187 -0
- package/DataGridPro/DataGridPro.d.ts +7 -1
- package/DataGridPro/DataGridPro.js +63 -20
- package/DataGridPro/useDataGridProComponent.js +29 -18
- package/DataGridPro/useDataGridProProps.d.ts +2 -1
- package/DataGridPro/useDataGridProProps.js +2 -2
- package/components/DataGridProColumnHeaders.js +10 -10
- package/components/DataGridProVirtualScroller.js +12 -23
- package/components/GridDetailPanelToggleCell.js +4 -3
- package/components/GridGroupingCriteriaCell.d.ts +2 -5
- package/components/GridGroupingCriteriaCell.js +2 -74
- package/components/GridTreeDataGroupingCell.js +4 -3
- package/components/index.d.ts +1 -0
- package/components/index.js +2 -1
- package/hooks/features/columnPinning/useGridColumnPinning.js +6 -6
- package/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +2 -2
- package/hooks/features/columnReorder/useGridColumnReorder.d.ts +2 -0
- package/hooks/features/columnReorder/useGridColumnReorder.js +7 -8
- package/hooks/features/columnResize/useGridColumnResize.d.ts +2 -0
- package/hooks/features/columnResize/useGridColumnResize.js +7 -7
- package/hooks/features/detailPanel/useGridDetailPanel.d.ts +2 -0
- package/hooks/features/detailPanel/useGridDetailPanel.js +10 -10
- package/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +2 -2
- package/hooks/features/infiniteLoader/useGridInfiniteLoader.js +2 -2
- package/hooks/features/rowGrouping/gridRowGroupingInterfaces.d.ts +6 -0
- package/hooks/features/rowGrouping/gridRowGroupingUtils.d.ts +5 -2
- package/hooks/features/rowGrouping/gridRowGroupingUtils.js +18 -3
- package/hooks/features/rowGrouping/useGridRowGrouping.js +46 -167
- package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.d.ts +1 -1
- package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +131 -4
- package/hooks/features/treeData/gridTreeDataUtils.d.ts +1 -0
- package/hooks/features/treeData/gridTreeDataUtils.js +2 -0
- package/hooks/features/treeData/useGridTreeData.d.ts +1 -5
- package/hooks/features/treeData/useGridTreeData.js +3 -82
- package/hooks/features/treeData/useGridTreeDataPreProcessors.d.ts +1 -1
- package/hooks/features/treeData/useGridTreeDataPreProcessors.js +73 -4
- package/index.d.ts +2 -1
- package/index.js +3 -2
- package/legacy/DataGridPro/DataGridPro.js +63 -20
- package/legacy/DataGridPro/useDataGridProComponent.js +29 -18
- package/legacy/DataGridPro/useDataGridProProps.js +7 -2
- package/legacy/components/DataGridProColumnHeaders.js +10 -10
- package/legacy/components/DataGridProVirtualScroller.js +12 -22
- package/legacy/components/GridDetailPanelToggleCell.js +4 -3
- package/legacy/components/GridGroupingCriteriaCell.js +2 -74
- package/legacy/components/GridTreeDataGroupingCell.js +4 -3
- package/legacy/components/index.js +2 -1
- package/legacy/hooks/features/columnPinning/useGridColumnPinning.js +6 -6
- package/legacy/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +2 -2
- package/legacy/hooks/features/columnReorder/useGridColumnReorder.js +9 -10
- package/legacy/hooks/features/columnResize/useGridColumnResize.js +9 -9
- package/legacy/hooks/features/detailPanel/useGridDetailPanel.js +10 -10
- package/legacy/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +2 -2
- package/legacy/hooks/features/infiniteLoader/useGridInfiniteLoader.js +2 -2
- package/legacy/hooks/features/rowGrouping/gridRowGroupingUtils.js +19 -2
- package/legacy/hooks/features/rowGrouping/useGridRowGrouping.js +48 -172
- package/legacy/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +138 -4
- package/legacy/hooks/features/treeData/gridTreeDataUtils.js +2 -0
- package/legacy/hooks/features/treeData/useGridTreeData.js +3 -90
- package/legacy/hooks/features/treeData/useGridTreeDataPreProcessors.js +85 -4
- package/legacy/index.js +3 -2
- package/legacy/utils/releaseInfo.js +15 -0
- package/models/dataGridProProps.d.ts +9 -8
- package/models/gridGroupingColDefOverride.d.ts +2 -2
- package/models/gridGroupingValueGetterParams.d.ts +1 -1
- package/modern/DataGridPro/DataGridPro.js +63 -20
- package/modern/DataGridPro/useDataGridProComponent.js +27 -18
- package/modern/DataGridPro/useDataGridProProps.js +2 -2
- package/modern/components/DataGridProColumnHeaders.js +10 -10
- package/modern/components/DataGridProVirtualScroller.js +12 -23
- package/modern/components/GridDetailPanelToggleCell.js +4 -3
- package/modern/components/GridGroupingCriteriaCell.js +2 -74
- package/modern/components/GridTreeDataGroupingCell.js +4 -3
- package/modern/components/index.js +2 -1
- package/modern/hooks/features/columnPinning/useGridColumnPinning.js +6 -6
- package/modern/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +2 -2
- package/modern/hooks/features/columnReorder/useGridColumnReorder.js +7 -8
- package/modern/hooks/features/columnResize/useGridColumnResize.js +7 -7
- package/modern/hooks/features/detailPanel/useGridDetailPanel.js +9 -9
- package/modern/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +2 -2
- package/modern/hooks/features/infiniteLoader/useGridInfiniteLoader.js +2 -2
- package/modern/hooks/features/rowGrouping/gridRowGroupingUtils.js +18 -3
- package/modern/hooks/features/rowGrouping/useGridRowGrouping.js +46 -167
- package/modern/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +131 -4
- package/modern/hooks/features/treeData/gridTreeDataUtils.js +2 -0
- package/modern/hooks/features/treeData/useGridTreeData.js +3 -82
- package/modern/hooks/features/treeData/useGridTreeDataPreProcessors.js +73 -4
- package/modern/index.js +3 -2
- package/modern/utils/releaseInfo.js +15 -0
- package/node/DataGridPro/DataGridPro.js +61 -19
- package/node/DataGridPro/useDataGridProComponent.js +26 -15
- package/node/DataGridPro/useDataGridProProps.js +2 -2
- package/node/components/DataGridProColumnHeaders.js +10 -10
- package/node/components/DataGridProVirtualScroller.js +11 -22
- package/node/components/GridDetailPanelToggleCell.js +4 -3
- package/node/components/GridGroupingCriteriaCell.js +1 -72
- package/node/components/GridTreeDataGroupingCell.js +4 -3
- package/node/components/index.js +13 -0
- package/node/hooks/features/columnPinning/useGridColumnPinning.js +5 -5
- package/node/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +1 -1
- package/node/hooks/features/columnReorder/useGridColumnReorder.js +10 -9
- package/node/hooks/features/columnResize/useGridColumnResize.js +9 -6
- package/node/hooks/features/detailPanel/useGridDetailPanel.js +13 -10
- package/node/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +1 -1
- package/node/hooks/features/infiniteLoader/useGridInfiniteLoader.js +1 -1
- package/node/hooks/features/rowGrouping/gridRowGroupingUtils.js +24 -5
- package/node/hooks/features/rowGrouping/useGridRowGrouping.js +42 -165
- package/node/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +134 -1
- package/node/hooks/features/treeData/gridTreeDataUtils.js +5 -2
- package/node/hooks/features/treeData/useGridTreeData.js +2 -91
- package/node/hooks/features/treeData/useGridTreeDataPreProcessors.js +75 -3
- package/node/index.js +23 -9
- package/node/utils/releaseInfo.js +25 -0
- package/package.json +5 -4
- package/typeOverloads/modules.d.ts +6 -6
- package/typeOverloads/reexports.d.ts +1 -1
- package/utils/releaseInfo.d.ts +1 -0
- package/utils/releaseInfo.js +15 -0
- package/utils/tree/buildRowTree.d.ts +3 -3
- package/components/Watermark.d.ts +0 -2
- package/components/Watermark.js +0 -43
- package/legacy/components/Watermark.js +0 -43
- package/modern/components/Watermark.js +0 -43
- package/node/components/Watermark.js +0 -56
|
@@ -2,7 +2,7 @@ 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
4
|
import { GridEvents, gridClasses, GridColumnHeaderSeparatorSides, useGridApiEventHandler, useGridApiOptionHandler, useGridNativeEventListener, useGridLogger } from '@mui/x-data-grid';
|
|
5
|
-
import {
|
|
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.
|
|
8
8
|
// https://caniuse.com/#search=touch-action
|
|
@@ -73,22 +73,22 @@ function computeOffsetToSeparator(clickX, columnBounds, separatorSide) {
|
|
|
73
73
|
function getSeparatorSide(element) {
|
|
74
74
|
return element.classList.contains(gridClasses['columnSeparator--sideRight']) ? GridColumnHeaderSeparatorSides.Right : GridColumnHeaderSeparatorSides.Left;
|
|
75
75
|
}
|
|
76
|
+
|
|
77
|
+
export var columnResizeStateInitializer = function columnResizeStateInitializer(state) {
|
|
78
|
+
return _extends({}, state, {
|
|
79
|
+
columnResize: {
|
|
80
|
+
resizingColumnField: ''
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
};
|
|
76
84
|
/**
|
|
77
85
|
* Only available in DataGridPro
|
|
78
86
|
* @requires useGridColumns (method, event)
|
|
79
87
|
* TODO: improve experience for last column
|
|
80
88
|
*/
|
|
81
89
|
|
|
82
|
-
|
|
83
90
|
export var useGridColumnResize = function useGridColumnResize(apiRef, props) {
|
|
84
91
|
var logger = useGridLogger(apiRef, 'useGridColumnResize');
|
|
85
|
-
useGridStateInit(apiRef, function (state) {
|
|
86
|
-
return _extends({}, state, {
|
|
87
|
-
columnResize: {
|
|
88
|
-
resizingColumnField: ''
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
});
|
|
92
92
|
var colDefRef = React.useRef();
|
|
93
93
|
var colElementRef = React.useRef();
|
|
94
94
|
var colCellElementsRef = React.useRef(); // To improve accessibility, the separator has padding on both sides.
|
|
@@ -2,19 +2,19 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import { GridEvents, useGridSelector, useGridApiEventHandler, useGridApiMethod } from '@mui/x-data-grid';
|
|
5
|
-
import {
|
|
5
|
+
import { useGridRegisterPipeProcessor } from '@mui/x-data-grid/internals';
|
|
6
6
|
import { GRID_DETAIL_PANEL_TOGGLE_FIELD } from './gridDetailPanelToggleColDef';
|
|
7
7
|
import { gridDetailPanelExpandedRowIdsSelector, gridDetailPanelExpandedRowsContentCacheSelector, gridDetailPanelExpandedRowsHeightCacheSelector } from './gridDetailPanelSelector';
|
|
8
|
-
export var
|
|
9
|
-
|
|
10
|
-
var _ref, _props$detailPanelExp, _props$initialState, _props$initialState$d;
|
|
8
|
+
export var detailPanelStateInitializer = function detailPanelStateInitializer(state, props) {
|
|
9
|
+
var _ref, _props$detailPanelExp, _props$initialState, _props$initialState$d;
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
});
|
|
11
|
+
return _extends({}, state, {
|
|
12
|
+
detailPanel: {
|
|
13
|
+
expandedRowIds: (_ref = (_props$detailPanelExp = props.detailPanelExpandedRowIds) != null ? _props$detailPanelExp : (_props$initialState = props.initialState) == null ? void 0 : (_props$initialState$d = _props$initialState.detailPanel) == null ? void 0 : _props$initialState$d.expandedRowIds) != null ? _ref : []
|
|
14
|
+
}
|
|
17
15
|
});
|
|
16
|
+
};
|
|
17
|
+
export var useGridDetailPanel = function useGridDetailPanel(apiRef, props) {
|
|
18
18
|
var expandedRowIds = useGridSelector(apiRef, gridDetailPanelExpandedRowIdsSelector);
|
|
19
19
|
var contentCache = useGridSelector(apiRef, gridDetailPanelExpandedRowsContentCacheSelector);
|
|
20
20
|
var handleCellClick = React.useCallback(function (params, event) {
|
|
@@ -59,7 +59,7 @@ export var useGridDetailPanel = function useGridDetailPanel(apiRef, props) {
|
|
|
59
59
|
|
|
60
60
|
});
|
|
61
61
|
}, [apiRef, expandedRowIds]);
|
|
62
|
-
|
|
62
|
+
useGridRegisterPipeProcessor(apiRef, 'rowHeight', addDetailHeight);
|
|
63
63
|
apiRef.current.unstable_updateControlState({
|
|
64
64
|
stateId: 'detailPanels',
|
|
65
65
|
propModel: props.detailPanelExpandedRowIds,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { useGridRegisterPipeProcessor } from '@mui/x-data-grid/internals';
|
|
4
4
|
import { GRID_DETAIL_PANEL_TOGGLE_FIELD, GRID_DETAIL_PANEL_TOGGLE_COL_DEF } from './gridDetailPanelToggleColDef';
|
|
5
5
|
export var useGridDetailPanelPreProcessors = function useGridDetailPanelPreProcessors(apiRef, props) {
|
|
6
6
|
var addToggleColumn = React.useCallback(function (columnsState) {
|
|
@@ -27,5 +27,5 @@ export var useGridDetailPanelPreProcessors = function useGridDetailPanelPreProce
|
|
|
27
27
|
columnsState.lookup[GRID_DETAIL_PANEL_TOGGLE_FIELD] = GRID_DETAIL_PANEL_TOGGLE_COL_DEF;
|
|
28
28
|
return columnsState;
|
|
29
29
|
}, [props.getDetailPanelContent]);
|
|
30
|
-
|
|
30
|
+
useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', addToggleColumn);
|
|
31
31
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useGridSelector, GridEvents, useGridApiEventHandler, useGridApiOptionHandler, gridVisibleColumnDefinitionsSelector, gridRowsMetaSelector } from '@mui/x-data-grid';
|
|
3
|
-
import {
|
|
3
|
+
import { useGridVisibleRows } from '@mui/x-data-grid/internals';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Only available in DataGridPro
|
|
@@ -10,7 +10,7 @@ import { useCurrentPageRows } from '@mui/x-data-grid/internals';
|
|
|
10
10
|
*/
|
|
11
11
|
export var useGridInfiniteLoader = function useGridInfiniteLoader(apiRef, props) {
|
|
12
12
|
var visibleColumns = useGridSelector(apiRef, gridVisibleColumnDefinitionsSelector);
|
|
13
|
-
var currentPage =
|
|
13
|
+
var currentPage = useGridVisibleRows(apiRef, props);
|
|
14
14
|
var rowsMeta = useGridSelector(apiRef, gridRowsMetaSelector);
|
|
15
15
|
var contentHeight = Math.max(rowsMeta.currentPageTotalHeight, 1);
|
|
16
16
|
var isInScrollBottomArea = React.useRef(false);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { gridRowGroupingSanitizedModelSelector } from './gridRowGroupingSelector';
|
|
2
3
|
export var GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD = '__row_group_by_columns_group__';
|
|
3
|
-
export var
|
|
4
|
+
export var ROW_GROUPING_STRATEGY = 'grouping-columns';
|
|
4
5
|
export var getRowGroupingFieldFromGroupingCriteria = function getRowGroupingFieldFromGroupingCriteria(groupingCriteria) {
|
|
5
6
|
if (groupingCriteria === null) {
|
|
6
7
|
return GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD;
|
|
@@ -112,7 +113,7 @@ export var filterRowTreeFromGroupingColumns = function filterRowTreeFromGrouping
|
|
|
112
113
|
export var getColDefOverrides = function getColDefOverrides(groupingColDefProp, fields) {
|
|
113
114
|
if (typeof groupingColDefProp === 'function') {
|
|
114
115
|
return groupingColDefProp({
|
|
115
|
-
groupingName:
|
|
116
|
+
groupingName: ROW_GROUPING_STRATEGY,
|
|
116
117
|
fields: fields
|
|
117
118
|
});
|
|
118
119
|
}
|
|
@@ -127,4 +128,20 @@ export var mergeStateWithRowGroupingModel = function mergeStateWithRowGroupingMo
|
|
|
127
128
|
})
|
|
128
129
|
});
|
|
129
130
|
};
|
|
131
|
+
};
|
|
132
|
+
export var setStrategyAvailability = function setStrategyAvailability(apiRef, disableRowGrouping) {
|
|
133
|
+
var isAvailable;
|
|
134
|
+
|
|
135
|
+
if (disableRowGrouping) {
|
|
136
|
+
isAvailable = function isAvailable() {
|
|
137
|
+
return false;
|
|
138
|
+
};
|
|
139
|
+
} else {
|
|
140
|
+
isAvailable = function isAvailable() {
|
|
141
|
+
var rowGroupingSanitizedModel = gridRowGroupingSanitizedModelSelector(apiRef);
|
|
142
|
+
return rowGroupingSanitizedModel.length > 0;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
apiRef.current.unstable_setStrategyAvailability('rowTree', ROW_GROUPING_STRATEGY, isAvailable);
|
|
130
147
|
};
|
|
@@ -2,12 +2,10 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import Divider from '@mui/material/Divider';
|
|
5
|
-
import { GridEvents,
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import { filterRowTreeFromGroupingColumns, getRowGroupingFieldFromGroupingCriteria, GROUPING_COLUMNS_FEATURE_NAME, isGroupingColumn, mergeStateWithRowGroupingModel } from './gridRowGroupingUtils';
|
|
10
|
-
import { sortRowTree } from '../../../utils/tree/sortRowTree';
|
|
5
|
+
import { GridEvents, useGridApiEventHandler, useGridApiMethod, gridFilteredDescendantCountLookupSelector } from '@mui/x-data-grid';
|
|
6
|
+
import { useGridRegisterPipeProcessor, isDeepEqual } from '@mui/x-data-grid/internals';
|
|
7
|
+
import { gridRowGroupingModelSelector, gridRowGroupingSanitizedModelSelector, gridRowGroupingStateSelector } from './gridRowGroupingSelector';
|
|
8
|
+
import { getRowGroupingFieldFromGroupingCriteria, ROW_GROUPING_STRATEGY, isGroupingColumn, mergeStateWithRowGroupingModel, setStrategyAvailability } from './gridRowGroupingUtils';
|
|
11
9
|
import { GridRowGroupableColumnMenuItems } from '../../../components/GridRowGroupableColumnMenuItems';
|
|
12
10
|
import { GridRowGroupingColumnMenuItems } from '../../../components/GridRowGroupingColumnMenuItems';
|
|
13
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -16,7 +14,8 @@ export var rowGroupingStateInitializer = function rowGroupingStateInitializer(st
|
|
|
16
14
|
|
|
17
15
|
return _extends({}, state, {
|
|
18
16
|
rowGrouping: {
|
|
19
|
-
model: (_ref = (_props$rowGroupingMod = props.rowGroupingModel) != null ? _props$rowGroupingMod : (_props$initialState = props.initialState) == null ? void 0 : (_props$initialState$r = _props$initialState.rowGrouping) == null ? void 0 : _props$initialState$r.model) != null ? _ref : []
|
|
17
|
+
model: (_ref = (_props$rowGroupingMod = props.rowGroupingModel) != null ? _props$rowGroupingMod : (_props$initialState = props.initialState) == null ? void 0 : (_props$initialState$r = _props$initialState.rowGrouping) == null ? void 0 : _props$initialState$r.model) != null ? _ref : [],
|
|
18
|
+
unstable_sanitizedModelOnLastRowTreeCreation: []
|
|
20
19
|
}
|
|
21
20
|
});
|
|
22
21
|
};
|
|
@@ -36,163 +35,6 @@ export var useGridRowGrouping = function useGridRowGrouping(apiRef, props) {
|
|
|
36
35
|
stateSelector: gridRowGroupingModelSelector,
|
|
37
36
|
changeEvent: GridEvents.rowGroupingModelChange
|
|
38
37
|
});
|
|
39
|
-
/**
|
|
40
|
-
* ROW GROUPING
|
|
41
|
-
*/
|
|
42
|
-
// Tracks the model on the last pre-processing to check if we need to re-build the grouping columns when the grid upserts a column.
|
|
43
|
-
|
|
44
|
-
var sanitizedModelOnLastRowPreProcessing = React.useRef([]);
|
|
45
|
-
var updateRowGrouping = React.useCallback(function () {
|
|
46
|
-
var groupRows = function groupRows(params) {
|
|
47
|
-
var rowGroupingModel = gridRowGroupingSanitizedModelSelector(apiRef);
|
|
48
|
-
var columnsLookup = gridColumnLookupSelector(apiRef);
|
|
49
|
-
sanitizedModelOnLastRowPreProcessing.current = rowGroupingModel;
|
|
50
|
-
|
|
51
|
-
if (props.disableRowGrouping || rowGroupingModel.length === 0) {
|
|
52
|
-
return null;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
var distinctValues = Object.fromEntries(rowGroupingModel.map(function (groupingField) {
|
|
56
|
-
return [groupingField, {
|
|
57
|
-
lookup: {},
|
|
58
|
-
list: []
|
|
59
|
-
}];
|
|
60
|
-
}));
|
|
61
|
-
|
|
62
|
-
var getCellGroupingCriteria = function getCellGroupingCriteria(_ref2) {
|
|
63
|
-
var row = _ref2.row,
|
|
64
|
-
id = _ref2.id,
|
|
65
|
-
colDef = _ref2.colDef;
|
|
66
|
-
var key;
|
|
67
|
-
|
|
68
|
-
if (colDef.groupingValueGetter) {
|
|
69
|
-
var groupingValueGetterParams = {
|
|
70
|
-
colDef: colDef,
|
|
71
|
-
field: colDef.field,
|
|
72
|
-
value: row[colDef.field],
|
|
73
|
-
id: id,
|
|
74
|
-
row: row,
|
|
75
|
-
rowNode: {
|
|
76
|
-
isAutoGenerated: false,
|
|
77
|
-
id: id
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
key = colDef.groupingValueGetter(groupingValueGetterParams);
|
|
81
|
-
} else {
|
|
82
|
-
key = row[colDef.field];
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return {
|
|
86
|
-
key: key,
|
|
87
|
-
field: colDef.field
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
params.ids.forEach(function (rowId) {
|
|
92
|
-
var row = params.idRowsLookup[rowId];
|
|
93
|
-
rowGroupingModel.forEach(function (groupingCriteria) {
|
|
94
|
-
var _getCellGroupingCrite = getCellGroupingCriteria({
|
|
95
|
-
row: row,
|
|
96
|
-
id: rowId,
|
|
97
|
-
colDef: columnsLookup[groupingCriteria]
|
|
98
|
-
}),
|
|
99
|
-
key = _getCellGroupingCrite.key;
|
|
100
|
-
|
|
101
|
-
var groupingFieldsDistinctKeys = distinctValues[groupingCriteria];
|
|
102
|
-
|
|
103
|
-
if (key != null && !groupingFieldsDistinctKeys.lookup[key.toString()]) {
|
|
104
|
-
groupingFieldsDistinctKeys.lookup[key.toString()] = true;
|
|
105
|
-
groupingFieldsDistinctKeys.list.push(key);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
var rows = params.ids.map(function (rowId) {
|
|
110
|
-
var row = params.idRowsLookup[rowId];
|
|
111
|
-
var parentPath = rowGroupingModel.map(function (groupingField) {
|
|
112
|
-
return getCellGroupingCriteria({
|
|
113
|
-
row: row,
|
|
114
|
-
id: rowId,
|
|
115
|
-
colDef: columnsLookup[groupingField]
|
|
116
|
-
});
|
|
117
|
-
}).filter(function (cell) {
|
|
118
|
-
return cell.key != null;
|
|
119
|
-
});
|
|
120
|
-
var leafGroupingCriteria = {
|
|
121
|
-
key: rowId.toString(),
|
|
122
|
-
field: null
|
|
123
|
-
};
|
|
124
|
-
return {
|
|
125
|
-
path: [].concat(_toConsumableArray(parentPath), [leafGroupingCriteria]),
|
|
126
|
-
id: rowId
|
|
127
|
-
};
|
|
128
|
-
});
|
|
129
|
-
return buildRowTree(_extends({}, params, {
|
|
130
|
-
rows: rows,
|
|
131
|
-
defaultGroupingExpansionDepth: props.defaultGroupingExpansionDepth,
|
|
132
|
-
isGroupExpandedByDefault: props.isGroupExpandedByDefault,
|
|
133
|
-
groupingName: GROUPING_COLUMNS_FEATURE_NAME
|
|
134
|
-
}));
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
return apiRef.current.unstable_registerRowGroupsBuilder('rowGrouping', groupRows);
|
|
138
|
-
}, [apiRef, props.defaultGroupingExpansionDepth, props.isGroupExpandedByDefault, props.disableRowGrouping]);
|
|
139
|
-
useFirstRender(function () {
|
|
140
|
-
updateRowGrouping();
|
|
141
|
-
});
|
|
142
|
-
var isFirstRender = React.useRef(true);
|
|
143
|
-
React.useEffect(function () {
|
|
144
|
-
if (isFirstRender.current) {
|
|
145
|
-
isFirstRender.current = false;
|
|
146
|
-
return function () {};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
return updateRowGrouping();
|
|
150
|
-
}, [updateRowGrouping]);
|
|
151
|
-
/**
|
|
152
|
-
* PRE-PROCESSING
|
|
153
|
-
*/
|
|
154
|
-
|
|
155
|
-
var addColumnMenuButtons = React.useCallback(function (initialValue, columns) {
|
|
156
|
-
if (props.disableRowGrouping) {
|
|
157
|
-
return initialValue;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
var menuItems;
|
|
161
|
-
|
|
162
|
-
if (isGroupingColumn(columns.field)) {
|
|
163
|
-
menuItems = /*#__PURE__*/_jsx(GridRowGroupingColumnMenuItems, {});
|
|
164
|
-
} else if (columns.groupable) {
|
|
165
|
-
menuItems = /*#__PURE__*/_jsx(GridRowGroupableColumnMenuItems, {});
|
|
166
|
-
} else {
|
|
167
|
-
menuItems = null;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
if (menuItems == null) {
|
|
171
|
-
return initialValue;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return [].concat(_toConsumableArray(initialValue), [/*#__PURE__*/_jsx(Divider, {}), menuItems]);
|
|
175
|
-
}, [props.disableRowGrouping]);
|
|
176
|
-
var filteringMethod = React.useCallback(function (params) {
|
|
177
|
-
var rowTree = gridRowTreeSelector(apiRef);
|
|
178
|
-
return filterRowTreeFromGroupingColumns({
|
|
179
|
-
rowTree: rowTree,
|
|
180
|
-
isRowMatchingFilters: params.isRowMatchingFilters
|
|
181
|
-
});
|
|
182
|
-
}, [apiRef]);
|
|
183
|
-
var sortingMethod = React.useCallback(function (params) {
|
|
184
|
-
var rowTree = gridRowTreeSelector(apiRef);
|
|
185
|
-
var rowIds = gridRowIdsSelector(apiRef);
|
|
186
|
-
return sortRowTree({
|
|
187
|
-
rowTree: rowTree,
|
|
188
|
-
rowIds: rowIds,
|
|
189
|
-
sortRowList: params.sortRowList,
|
|
190
|
-
disableChildrenSorting: false
|
|
191
|
-
});
|
|
192
|
-
}, [apiRef]);
|
|
193
|
-
useGridRegisterPreProcessor(apiRef, 'columnMenu', addColumnMenuButtons);
|
|
194
|
-
useGridRegisterFilteringMethod(apiRef, GROUPING_COLUMNS_FEATURE_NAME, filteringMethod);
|
|
195
|
-
useGridRegisterSortingMethod(apiRef, GROUPING_COLUMNS_FEATURE_NAME, sortingMethod);
|
|
196
38
|
/**
|
|
197
39
|
* API METHODS
|
|
198
40
|
*/
|
|
@@ -202,10 +44,10 @@ export var useGridRowGrouping = function useGridRowGrouping(apiRef, props) {
|
|
|
202
44
|
|
|
203
45
|
if (currentModel !== model) {
|
|
204
46
|
apiRef.current.setState(mergeStateWithRowGroupingModel(model));
|
|
205
|
-
|
|
47
|
+
setStrategyAvailability(apiRef, props.disableRowGrouping);
|
|
206
48
|
apiRef.current.forceUpdate();
|
|
207
49
|
}
|
|
208
|
-
}, [apiRef,
|
|
50
|
+
}, [apiRef, props.disableRowGrouping]);
|
|
209
51
|
var addRowGroupingCriteria = React.useCallback(function (field, groupingIndex) {
|
|
210
52
|
var currentModel = gridRowGroupingModelSelector(apiRef);
|
|
211
53
|
|
|
@@ -252,6 +94,27 @@ export var useGridRowGrouping = function useGridRowGrouping(apiRef, props) {
|
|
|
252
94
|
* PRE-PROCESSING
|
|
253
95
|
*/
|
|
254
96
|
|
|
97
|
+
var addColumnMenuButtons = React.useCallback(function (initialValue, columns) {
|
|
98
|
+
if (props.disableRowGrouping) {
|
|
99
|
+
return initialValue;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
var menuItems;
|
|
103
|
+
|
|
104
|
+
if (isGroupingColumn(columns.field)) {
|
|
105
|
+
menuItems = /*#__PURE__*/_jsx(GridRowGroupingColumnMenuItems, {});
|
|
106
|
+
} else if (columns.groupable) {
|
|
107
|
+
menuItems = /*#__PURE__*/_jsx(GridRowGroupableColumnMenuItems, {});
|
|
108
|
+
} else {
|
|
109
|
+
menuItems = null;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (menuItems == null) {
|
|
113
|
+
return initialValue;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return [].concat(_toConsumableArray(initialValue), [/*#__PURE__*/_jsx(Divider, {}), menuItems]);
|
|
117
|
+
}, [props.disableRowGrouping]);
|
|
255
118
|
var stateExportPreProcessing = React.useCallback(function (prevState) {
|
|
256
119
|
if (props.disableRowGrouping) {
|
|
257
120
|
return prevState;
|
|
@@ -284,8 +147,9 @@ export var useGridRowGrouping = function useGridRowGrouping(apiRef, props) {
|
|
|
284
147
|
|
|
285
148
|
return params;
|
|
286
149
|
}, [apiRef, props.disableRowGrouping]);
|
|
287
|
-
|
|
288
|
-
|
|
150
|
+
useGridRegisterPipeProcessor(apiRef, 'columnMenu', addColumnMenuButtons);
|
|
151
|
+
useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
|
|
152
|
+
useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
|
|
289
153
|
/**
|
|
290
154
|
* EVENTS
|
|
291
155
|
*/
|
|
@@ -310,15 +174,27 @@ export var useGridRowGrouping = function useGridRowGrouping(apiRef, props) {
|
|
|
310
174
|
}, [apiRef, props.rowGroupingColumnMode]);
|
|
311
175
|
var checkGroupingColumnsModelDiff = React.useCallback(function () {
|
|
312
176
|
var rowGroupingModel = gridRowGroupingSanitizedModelSelector(apiRef);
|
|
313
|
-
var lastGroupingColumnsModelApplied =
|
|
177
|
+
var lastGroupingColumnsModelApplied = gridRowGroupingStateSelector(apiRef.current.state).unstable_sanitizedModelOnLastRowTreeCreation;
|
|
314
178
|
|
|
315
179
|
if (!isDeepEqual(lastGroupingColumnsModelApplied, rowGroupingModel)) {
|
|
316
|
-
|
|
180
|
+
apiRef.current.setState(function (state) {
|
|
181
|
+
return _extends({}, state, {
|
|
182
|
+
rowGrouping: _extends({}, state.rowGrouping, {
|
|
183
|
+
unstable_sanitizedModelOnLastRowTreeCreation: rowGroupingModel
|
|
184
|
+
})
|
|
185
|
+
});
|
|
186
|
+
}); // Refresh the column pre-processing
|
|
187
|
+
// TODO: Add a clean way to re-run a pipe processing without faking a change
|
|
317
188
|
|
|
318
189
|
apiRef.current.updateColumns([]);
|
|
319
|
-
|
|
190
|
+
setStrategyAvailability(apiRef, props.disableRowGrouping); // Refresh the row tree creation strategy processing
|
|
191
|
+
// TODO: Add a clean way to re-run a strategy processing without publishing a private event
|
|
192
|
+
|
|
193
|
+
if (apiRef.current.unstable_getActiveStrategy('rowTree') === ROW_GROUPING_STRATEGY) {
|
|
194
|
+
apiRef.current.publishEvent(GridEvents.activeStrategyProcessorChange, 'rowTreeCreation');
|
|
195
|
+
}
|
|
320
196
|
}
|
|
321
|
-
}, [apiRef,
|
|
197
|
+
}, [apiRef, props.disableRowGrouping]);
|
|
322
198
|
useGridApiEventHandler(apiRef, GridEvents.cellKeyDown, handleCellKeyDown);
|
|
323
199
|
useGridApiEventHandler(apiRef, GridEvents.columnsChange, checkGroupingColumnsModelDiff);
|
|
324
200
|
useGridApiEventHandler(apiRef, GridEvents.rowGroupingModelChange, checkGroupingColumnsModelDiff);
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
1
2
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
2
3
|
import * as React from 'react';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
4
|
+
import { gridColumnLookupSelector, gridRowIdsSelector, gridRowTreeSelector, useFirstRender } from '@mui/x-data-grid';
|
|
5
|
+
import { useGridRegisterPipeProcessor, useGridRegisterStrategyProcessor } from '@mui/x-data-grid/internals';
|
|
6
|
+
import { gridRowGroupingModelSelector, gridRowGroupingSanitizedModelSelector } from './gridRowGroupingSelector';
|
|
5
7
|
import { createGroupingColDefForAllGroupingCriteria, createGroupingColDefForOneGroupingCriteria } from './createGroupingColDef';
|
|
6
|
-
import { getColDefOverrides, isGroupingColumn } from './gridRowGroupingUtils';
|
|
8
|
+
import { filterRowTreeFromGroupingColumns, getColDefOverrides, ROW_GROUPING_STRATEGY, isGroupingColumn, setStrategyAvailability } from './gridRowGroupingUtils';
|
|
9
|
+
import { buildRowTree } from '../../../utils/tree/buildRowTree';
|
|
10
|
+
import { sortRowTree } from '../../../utils/tree/sortRowTree';
|
|
7
11
|
export var useGridRowGroupingPreProcessors = function useGridRowGroupingPreProcessors(apiRef, props) {
|
|
8
12
|
var getGroupingColDefs = React.useCallback(function (columnsState) {
|
|
9
13
|
if (props.disableRowGrouping) {
|
|
@@ -79,5 +83,135 @@ export var useGridRowGroupingPreProcessors = function useGridRowGroupingPreProce
|
|
|
79
83
|
columnsState.lookup = newColumnsLookup;
|
|
80
84
|
return columnsState;
|
|
81
85
|
}, [getGroupingColDefs]);
|
|
82
|
-
|
|
86
|
+
var createRowTree = React.useCallback(function (params) {
|
|
87
|
+
var rowGroupingModel = gridRowGroupingSanitizedModelSelector(apiRef);
|
|
88
|
+
var columnsLookup = gridColumnLookupSelector(apiRef);
|
|
89
|
+
apiRef.current.setState(function (state) {
|
|
90
|
+
return _extends({}, state, {
|
|
91
|
+
rowGrouping: _extends({}, state.rowGrouping, {
|
|
92
|
+
unstable_sanitizedModelOnLastRowTreeCreation: rowGroupingModel
|
|
93
|
+
})
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
var distinctValues = Object.fromEntries(rowGroupingModel.map(function (groupingField) {
|
|
97
|
+
return [groupingField, {
|
|
98
|
+
lookup: {},
|
|
99
|
+
list: []
|
|
100
|
+
}];
|
|
101
|
+
}));
|
|
102
|
+
|
|
103
|
+
var getCellGroupingCriteria = function getCellGroupingCriteria(_ref) {
|
|
104
|
+
var row = _ref.row,
|
|
105
|
+
id = _ref.id,
|
|
106
|
+
colDef = _ref.colDef;
|
|
107
|
+
var key;
|
|
108
|
+
|
|
109
|
+
if (colDef.groupingValueGetter) {
|
|
110
|
+
var groupingValueGetterParams = {
|
|
111
|
+
colDef: colDef,
|
|
112
|
+
field: colDef.field,
|
|
113
|
+
value: row[colDef.field],
|
|
114
|
+
id: id,
|
|
115
|
+
row: row,
|
|
116
|
+
rowNode: {
|
|
117
|
+
isAutoGenerated: false,
|
|
118
|
+
id: id
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
key = colDef.groupingValueGetter(groupingValueGetterParams);
|
|
122
|
+
} else {
|
|
123
|
+
key = row[colDef.field];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
key: key,
|
|
128
|
+
field: colDef.field
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
params.ids.forEach(function (rowId) {
|
|
133
|
+
var row = params.idRowsLookup[rowId];
|
|
134
|
+
rowGroupingModel.forEach(function (groupingCriteria) {
|
|
135
|
+
var _getCellGroupingCrite = getCellGroupingCriteria({
|
|
136
|
+
row: row,
|
|
137
|
+
id: rowId,
|
|
138
|
+
colDef: columnsLookup[groupingCriteria]
|
|
139
|
+
}),
|
|
140
|
+
key = _getCellGroupingCrite.key;
|
|
141
|
+
|
|
142
|
+
var groupingFieldsDistinctKeys = distinctValues[groupingCriteria];
|
|
143
|
+
|
|
144
|
+
if (key != null && !groupingFieldsDistinctKeys.lookup[key.toString()]) {
|
|
145
|
+
groupingFieldsDistinctKeys.lookup[key.toString()] = true;
|
|
146
|
+
groupingFieldsDistinctKeys.list.push(key);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
var rows = params.ids.map(function (rowId) {
|
|
151
|
+
var row = params.idRowsLookup[rowId];
|
|
152
|
+
var parentPath = rowGroupingModel.map(function (groupingField) {
|
|
153
|
+
return getCellGroupingCriteria({
|
|
154
|
+
row: row,
|
|
155
|
+
id: rowId,
|
|
156
|
+
colDef: columnsLookup[groupingField]
|
|
157
|
+
});
|
|
158
|
+
}).filter(function (cell) {
|
|
159
|
+
return cell.key != null;
|
|
160
|
+
});
|
|
161
|
+
var leafGroupingCriteria = {
|
|
162
|
+
key: rowId.toString(),
|
|
163
|
+
field: null
|
|
164
|
+
};
|
|
165
|
+
return {
|
|
166
|
+
path: [].concat(_toConsumableArray(parentPath), [leafGroupingCriteria]),
|
|
167
|
+
id: rowId
|
|
168
|
+
};
|
|
169
|
+
});
|
|
170
|
+
return buildRowTree(_extends({}, params, {
|
|
171
|
+
rows: rows,
|
|
172
|
+
defaultGroupingExpansionDepth: props.defaultGroupingExpansionDepth,
|
|
173
|
+
isGroupExpandedByDefault: props.isGroupExpandedByDefault,
|
|
174
|
+
groupingName: ROW_GROUPING_STRATEGY
|
|
175
|
+
}));
|
|
176
|
+
}, [apiRef, props.defaultGroupingExpansionDepth, props.isGroupExpandedByDefault]);
|
|
177
|
+
var filterRows = React.useCallback(function (params) {
|
|
178
|
+
var rowTree = gridRowTreeSelector(apiRef);
|
|
179
|
+
return filterRowTreeFromGroupingColumns({
|
|
180
|
+
rowTree: rowTree,
|
|
181
|
+
isRowMatchingFilters: params.isRowMatchingFilters
|
|
182
|
+
});
|
|
183
|
+
}, [apiRef]);
|
|
184
|
+
var sortRows = React.useCallback(function (params) {
|
|
185
|
+
var rowTree = gridRowTreeSelector(apiRef);
|
|
186
|
+
var rowIds = gridRowIdsSelector(apiRef);
|
|
187
|
+
return sortRowTree({
|
|
188
|
+
rowTree: rowTree,
|
|
189
|
+
rowIds: rowIds,
|
|
190
|
+
sortRowList: params.sortRowList,
|
|
191
|
+
disableChildrenSorting: false
|
|
192
|
+
});
|
|
193
|
+
}, [apiRef]);
|
|
194
|
+
useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', updateGroupingColumn);
|
|
195
|
+
useGridRegisterStrategyProcessor(apiRef, ROW_GROUPING_STRATEGY, 'rowTreeCreation', createRowTree);
|
|
196
|
+
useGridRegisterStrategyProcessor(apiRef, ROW_GROUPING_STRATEGY, 'filtering', filterRows);
|
|
197
|
+
useGridRegisterStrategyProcessor(apiRef, ROW_GROUPING_STRATEGY, 'sorting', sortRows);
|
|
198
|
+
/**
|
|
199
|
+
* 1ST RENDER
|
|
200
|
+
*/
|
|
201
|
+
|
|
202
|
+
useFirstRender(function () {
|
|
203
|
+
setStrategyAvailability(apiRef, props.disableRowGrouping);
|
|
204
|
+
});
|
|
205
|
+
/**
|
|
206
|
+
* EFFECTS
|
|
207
|
+
*/
|
|
208
|
+
|
|
209
|
+
var isFirstRender = React.useRef(true);
|
|
210
|
+
React.useEffect(function () {
|
|
211
|
+
if (!isFirstRender.current) {
|
|
212
|
+
setStrategyAvailability(apiRef, props.disableRowGrouping);
|
|
213
|
+
} else {
|
|
214
|
+
isFirstRender.current = false;
|
|
215
|
+
}
|
|
216
|
+
}, [apiRef, props.disableRowGrouping]);
|
|
83
217
|
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
export var TREE_DATA_STRATEGY = 'tree-data';
|
|
1
2
|
/**
|
|
2
3
|
* A node is visible if one of the following criteria is met:
|
|
3
4
|
* - One of its children is passing the filter
|
|
4
5
|
* - It is passing the filter
|
|
5
6
|
*/
|
|
7
|
+
|
|
6
8
|
export var filterRowTreeFromTreeData = function filterRowTreeFromTreeData(params) {
|
|
7
9
|
var rowTree = params.rowTree,
|
|
8
10
|
disableChildrenFiltering = params.disableChildrenFiltering,
|