@mui/x-data-grid-pro 5.11.1 → 5.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/CHANGELOG.md +199 -20
  2. package/DataGridPro/DataGridPro.js +26 -27
  3. package/DataGridPro/useDataGridProComponent.js +1 -8
  4. package/DataGridPro/useDataGridProProps.js +6 -27
  5. package/README.md +2 -2
  6. package/components/DataGridProColumnHeaders.js +10 -7
  7. package/components/DataGridProVirtualScroller.d.ts +1 -1
  8. package/components/DataGridProVirtualScroller.js +6 -3
  9. package/components/GridRowReorderCell.js +6 -6
  10. package/hooks/features/columnPinning/gridColumnPinningInterface.d.ts +6 -0
  11. package/hooks/features/columnPinning/useGridColumnPinning.d.ts +1 -1
  12. package/hooks/features/columnPinning/useGridColumnPinning.js +73 -28
  13. package/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +67 -4
  14. package/hooks/features/columnResize/useGridColumnResize.js +32 -15
  15. package/hooks/features/detailPanel/gridDetailPanelToggleColDef.js +2 -2
  16. package/hooks/features/detailPanel/useGridDetailPanel.d.ts +1 -1
  17. package/hooks/features/detailPanel/useGridDetailPanel.js +78 -18
  18. package/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +5 -2
  19. package/hooks/features/rowReorder/useGridRowReorder.js +5 -1
  20. package/hooks/features/rowReorder/useGridRowReorderPreProcessors.d.ts +2 -2
  21. package/hooks/features/treeData/useGridTreeDataPreProcessors.js +2 -2
  22. package/index.d.ts +0 -2
  23. package/index.js +2 -5
  24. package/internals/index.d.ts +0 -1
  25. package/internals/index.js +0 -1
  26. package/legacy/DataGridPro/DataGridPro.js +26 -27
  27. package/legacy/DataGridPro/useDataGridProComponent.js +1 -8
  28. package/legacy/DataGridPro/useDataGridProProps.js +1 -20
  29. package/legacy/components/DataGridProColumnHeaders.js +10 -7
  30. package/legacy/components/DataGridProVirtualScroller.js +6 -3
  31. package/legacy/components/GridRowReorderCell.js +8 -6
  32. package/legacy/hooks/features/columnPinning/useGridColumnPinning.js +82 -33
  33. package/legacy/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +70 -5
  34. package/legacy/hooks/features/columnResize/useGridColumnResize.js +32 -15
  35. package/legacy/hooks/features/detailPanel/gridDetailPanelToggleColDef.js +3 -1
  36. package/legacy/hooks/features/detailPanel/useGridDetailPanel.js +78 -18
  37. package/legacy/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +5 -2
  38. package/legacy/hooks/features/rowReorder/useGridRowReorder.js +5 -1
  39. package/legacy/hooks/features/treeData/useGridTreeDataPreProcessors.js +2 -2
  40. package/legacy/index.js +2 -5
  41. package/legacy/internals/index.js +0 -1
  42. package/legacy/utils/releaseInfo.js +1 -1
  43. package/models/dataGridProProps.d.ts +0 -26
  44. package/models/gridApiPro.d.ts +1 -2
  45. package/models/gridStatePro.d.ts +0 -3
  46. package/modern/DataGridPro/DataGridPro.js +26 -27
  47. package/modern/DataGridPro/useDataGridProComponent.js +1 -8
  48. package/modern/DataGridPro/useDataGridProProps.js +1 -16
  49. package/modern/components/DataGridProColumnHeaders.js +11 -6
  50. package/modern/components/DataGridProVirtualScroller.js +6 -3
  51. package/modern/components/GridRowReorderCell.js +6 -6
  52. package/modern/hooks/features/columnPinning/useGridColumnPinning.js +73 -28
  53. package/modern/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +67 -4
  54. package/modern/hooks/features/columnResize/useGridColumnResize.js +32 -15
  55. package/modern/hooks/features/detailPanel/gridDetailPanelToggleColDef.js +2 -2
  56. package/modern/hooks/features/detailPanel/useGridDetailPanel.js +76 -16
  57. package/modern/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +5 -2
  58. package/modern/hooks/features/rowReorder/useGridRowReorder.js +5 -1
  59. package/modern/hooks/features/treeData/useGridTreeDataPreProcessors.js +2 -2
  60. package/modern/index.js +2 -5
  61. package/modern/internals/index.js +0 -1
  62. package/modern/utils/releaseInfo.js +1 -1
  63. package/node/DataGridPro/DataGridPro.js +26 -27
  64. package/node/DataGridPro/useDataGridProComponent.js +1 -11
  65. package/node/DataGridPro/useDataGridProProps.js +6 -28
  66. package/node/components/DataGridProColumnHeaders.js +11 -7
  67. package/node/components/DataGridProVirtualScroller.js +6 -3
  68. package/node/components/GridRowReorderCell.js +6 -6
  69. package/node/hooks/features/columnPinning/useGridColumnPinning.js +72 -24
  70. package/node/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +68 -5
  71. package/node/hooks/features/columnResize/useGridColumnResize.js +32 -14
  72. package/node/hooks/features/detailPanel/gridDetailPanelToggleColDef.js +2 -2
  73. package/node/hooks/features/detailPanel/useGridDetailPanel.js +76 -17
  74. package/node/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +8 -2
  75. package/node/hooks/features/rowReorder/useGridRowReorder.js +5 -1
  76. package/node/hooks/features/treeData/useGridTreeDataPreProcessors.js +1 -1
  77. package/node/index.js +2 -30
  78. package/node/internals/index.js +0 -9
  79. package/node/utils/releaseInfo.js +1 -1
  80. package/package.json +8 -7
  81. package/typeOverloads/modules.d.ts +9 -21
  82. package/utils/releaseInfo.js +1 -1
  83. package/components/GridGroupingColumnLeafCell.d.ts +0 -4
  84. package/components/GridGroupingColumnLeafCell.js +0 -22
  85. package/components/GridGroupingCriteriaCell.d.ts +0 -7
  86. package/components/GridGroupingCriteriaCell.js +0 -78
  87. package/components/GridRowGroupableColumnMenuItems.d.ts +0 -11
  88. package/components/GridRowGroupableColumnMenuItems.js +0 -63
  89. package/components/GridRowGroupingColumnMenuItems.d.ts +0 -11
  90. package/components/GridRowGroupingColumnMenuItems.js +0 -58
  91. package/hooks/features/detailPanel/useGridDetailPanelCache.d.ts +0 -4
  92. package/hooks/features/detailPanel/useGridDetailPanelCache.js +0 -57
  93. package/hooks/features/rowGrouping/createGroupingColDef.d.ts +0 -43
  94. package/hooks/features/rowGrouping/createGroupingColDef.js +0 -318
  95. package/hooks/features/rowGrouping/gridRowGroupingInterfaces.d.ts +0 -37
  96. package/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +0 -1
  97. package/hooks/features/rowGrouping/gridRowGroupingSelector.d.ts +0 -4
  98. package/hooks/features/rowGrouping/gridRowGroupingSelector.js +0 -5
  99. package/hooks/features/rowGrouping/gridRowGroupingUtils.d.ts +0 -27
  100. package/hooks/features/rowGrouping/gridRowGroupingUtils.js +0 -139
  101. package/hooks/features/rowGrouping/index.d.ts +0 -3
  102. package/hooks/features/rowGrouping/index.js +0 -3
  103. package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +0 -11
  104. package/hooks/features/rowGrouping/useGridRowGrouping.js +0 -200
  105. package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.d.ts +0 -4
  106. package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +0 -203
  107. package/legacy/components/GridGroupingColumnLeafCell.js +0 -20
  108. package/legacy/components/GridGroupingCriteriaCell.js +0 -74
  109. package/legacy/components/GridRowGroupableColumnMenuItems.js +0 -61
  110. package/legacy/components/GridRowGroupingColumnMenuItems.js +0 -56
  111. package/legacy/hooks/features/detailPanel/useGridDetailPanelCache.js +0 -57
  112. package/legacy/hooks/features/rowGrouping/createGroupingColDef.js +0 -319
  113. package/legacy/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +0 -1
  114. package/legacy/hooks/features/rowGrouping/gridRowGroupingSelector.js +0 -13
  115. package/legacy/hooks/features/rowGrouping/gridRowGroupingUtils.js +0 -147
  116. package/legacy/hooks/features/rowGrouping/index.js +0 -3
  117. package/legacy/hooks/features/rowGrouping/useGridRowGrouping.js +0 -206
  118. package/legacy/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +0 -217
  119. package/legacy/models/gridGroupingValueGetterParams.js +0 -1
  120. package/models/gridGroupingValueGetterParams.d.ts +0 -31
  121. package/models/gridGroupingValueGetterParams.js +0 -1
  122. package/modern/components/GridGroupingColumnLeafCell.js +0 -20
  123. package/modern/components/GridGroupingCriteriaCell.js +0 -76
  124. package/modern/components/GridRowGroupableColumnMenuItems.js +0 -61
  125. package/modern/components/GridRowGroupingColumnMenuItems.js +0 -56
  126. package/modern/hooks/features/detailPanel/useGridDetailPanelCache.js +0 -57
  127. package/modern/hooks/features/rowGrouping/createGroupingColDef.js +0 -302
  128. package/modern/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +0 -1
  129. package/modern/hooks/features/rowGrouping/gridRowGroupingSelector.js +0 -5
  130. package/modern/hooks/features/rowGrouping/gridRowGroupingUtils.js +0 -137
  131. package/modern/hooks/features/rowGrouping/index.js +0 -3
  132. package/modern/hooks/features/rowGrouping/useGridRowGrouping.js +0 -192
  133. package/modern/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +0 -203
  134. package/modern/models/gridGroupingValueGetterParams.js +0 -1
  135. package/node/components/GridGroupingColumnLeafCell.js +0 -38
  136. package/node/components/GridGroupingCriteriaCell.js +0 -99
  137. package/node/components/GridRowGroupableColumnMenuItems.js +0 -82
  138. package/node/components/GridRowGroupingColumnMenuItems.js +0 -78
  139. package/node/hooks/features/detailPanel/useGridDetailPanelCache.js +0 -74
  140. package/node/hooks/features/rowGrouping/createGroupingColDef.js +0 -341
  141. package/node/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +0 -5
  142. package/node/hooks/features/rowGrouping/gridRowGroupingSelector.js +0 -18
  143. package/node/hooks/features/rowGrouping/gridRowGroupingUtils.js +0 -172
  144. package/node/hooks/features/rowGrouping/index.js +0 -51
  145. package/node/hooks/features/rowGrouping/useGridRowGrouping.js +0 -228
  146. package/node/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +0 -227
  147. package/node/models/gridGroupingValueGetterParams.js +0 -5
@@ -1,319 +0,0 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
- import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- import _extends from "@babel/runtime/helpers/esm/extends";
4
- var _excluded = ["leafField", "mainGroupingCriteria", "hideDescendantCount"],
5
- _excluded2 = ["leafField", "mainGroupingCriteria", "hideDescendantCount"];
6
- import * as React from 'react';
7
- import { GRID_STRING_COL_DEF } from '@mui/x-data-grid';
8
- import { GridGroupingCriteriaCell } from '../../../components/GridGroupingCriteriaCell';
9
- import { GridGroupingColumnLeafCell } from '../../../components/GridGroupingColumnLeafCell';
10
- import { getRowGroupingFieldFromGroupingCriteria, GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD } from './gridRowGroupingUtils';
11
- import { gridRowGroupingSanitizedModelSelector } from './gridRowGroupingSelector';
12
- import { jsx as _jsx } from "react/jsx-runtime";
13
-
14
- var GROUPING_COL_DEF_DEFAULT_PROPERTIES = _extends({}, GRID_STRING_COL_DEF, {
15
- disableReorder: true
16
- });
17
-
18
- var GROUPING_COL_DEF_FORCED_PROPERTIES = {
19
- type: 'rowGroupByColumnsGroup',
20
- editable: false,
21
- groupable: false
22
- };
23
- /**
24
- * When sorting two cells with different grouping criteria, we consider that the cell with the grouping criteria coming first in the model should be displayed below.
25
- * This can occur when some rows don't have all the fields. In which case we want the rows with the missing field to be displayed above.
26
- * TODO: Make this index comparator depth invariant, the logic should not be inverted when sorting in the "desc" direction (but the current return format of `sortComparator` does not support this behavior).
27
- */
28
-
29
- var groupingFieldIndexComparator = function groupingFieldIndexComparator(v1, v2, cellParams1, cellParams2) {
30
- var model = gridRowGroupingSanitizedModelSelector(cellParams1.api.state, cellParams1.api.instanceId);
31
- var groupingField1 = cellParams1.rowNode.groupingField;
32
- var groupingField2 = cellParams2.rowNode.groupingField;
33
-
34
- if (groupingField1 === groupingField2) {
35
- return 0;
36
- }
37
-
38
- if (groupingField1 == null) {
39
- return -1;
40
- }
41
-
42
- if (groupingField2 == null) {
43
- return 1;
44
- }
45
-
46
- if (model.indexOf(groupingField1) < model.indexOf(groupingField2)) {
47
- return -1;
48
- }
49
-
50
- return 1;
51
- };
52
-
53
- var getLeafProperties = function getLeafProperties(leafColDef) {
54
- var _leafColDef$headerNam, _leafColDef$filterOpe;
55
-
56
- return {
57
- headerName: (_leafColDef$headerNam = leafColDef.headerName) != null ? _leafColDef$headerNam : leafColDef.field,
58
- sortable: leafColDef.sortable,
59
- filterable: leafColDef.filterable,
60
- filterOperators: (_leafColDef$filterOpe = leafColDef.filterOperators) == null ? void 0 : _leafColDef$filterOpe.map(function (operator) {
61
- return _extends({}, operator, {
62
- getApplyFilterFn: function getApplyFilterFn(filterItem, column) {
63
- var originalFn = operator.getApplyFilterFn(filterItem, column);
64
-
65
- if (!originalFn) {
66
- return null;
67
- }
68
-
69
- return function (params) {
70
- // We only want to filter leaves
71
- if (params.rowNode.groupingField != null) {
72
- return true;
73
- }
74
-
75
- return originalFn(params);
76
- };
77
- }
78
- });
79
- }),
80
- sortComparator: function sortComparator(v1, v2, cellParams1, cellParams2) {
81
- // We only want to sort the leaves
82
- if (cellParams1.rowNode.groupingField === null && cellParams2.rowNode.groupingField === null) {
83
- return leafColDef.sortComparator(v1, v2, cellParams1, cellParams2);
84
- }
85
-
86
- return groupingFieldIndexComparator(v1, v2, cellParams1, cellParams2);
87
- }
88
- };
89
- };
90
-
91
- var getGroupingCriteriaProperties = function getGroupingCriteriaProperties(groupedByColDef, applyHeaderName) {
92
- var _groupedByColDef$filt;
93
-
94
- var properties = {
95
- sortable: groupedByColDef.sortable,
96
- filterable: groupedByColDef.filterable,
97
- sortComparator: function sortComparator(v1, v2, cellParams1, cellParams2) {
98
- // We only want to sort the groups of the current grouping criteria
99
- if (cellParams1.rowNode.groupingField === groupedByColDef.field && cellParams2.rowNode.groupingField === groupedByColDef.field) {
100
- return groupedByColDef.sortComparator(v1, v2, cellParams1, cellParams2);
101
- }
102
-
103
- return groupingFieldIndexComparator(v1, v2, cellParams1, cellParams2);
104
- },
105
- filterOperators: (_groupedByColDef$filt = groupedByColDef.filterOperators) == null ? void 0 : _groupedByColDef$filt.map(function (operator) {
106
- return _extends({}, operator, {
107
- getApplyFilterFn: function getApplyFilterFn(filterItem, column) {
108
- var originalFn = operator.getApplyFilterFn(filterItem, column);
109
-
110
- if (!originalFn) {
111
- return null;
112
- }
113
-
114
- return function (params) {
115
- // We only want to filter the groups of the current grouping criteria
116
- if (params.rowNode.groupingField !== groupedByColDef.field) {
117
- return true;
118
- }
119
-
120
- return originalFn(params);
121
- };
122
- }
123
- });
124
- })
125
- };
126
-
127
- if (applyHeaderName) {
128
- var _groupedByColDef$head;
129
-
130
- properties.headerName = (_groupedByColDef$head = groupedByColDef.headerName) != null ? _groupedByColDef$head : groupedByColDef.field;
131
- }
132
-
133
- return properties;
134
- };
135
-
136
- /**
137
- * Creates the `GridColDef` for a grouping column that only takes care of a single grouping criteria
138
- */
139
- export var createGroupingColDefForOneGroupingCriteria = function createGroupingColDefForOneGroupingCriteria(_ref) {
140
- var _groupedByColDef$widt, _leafColDef$width;
141
-
142
- var columnsLookup = _ref.columnsLookup,
143
- groupedByColDef = _ref.groupedByColDef,
144
- groupingCriteria = _ref.groupingCriteria,
145
- colDefOverride = _ref.colDefOverride;
146
-
147
- var _ref2 = colDefOverride != null ? colDefOverride : {},
148
- leafField = _ref2.leafField,
149
- mainGroupingCriteria = _ref2.mainGroupingCriteria,
150
- hideDescendantCount = _ref2.hideDescendantCount,
151
- colDefOverrideProperties = _objectWithoutProperties(_ref2, _excluded);
152
-
153
- var leafColDef = leafField ? columnsLookup[leafField] : null; // The properties that do not depend on the presence of a `leafColDef` and that can be overridden by `colDefOverride`
154
-
155
- var commonProperties = {
156
- width: Math.max(((_groupedByColDef$widt = groupedByColDef.width) != null ? _groupedByColDef$widt : GRID_STRING_COL_DEF.width) + 40, (_leafColDef$width = leafColDef == null ? void 0 : leafColDef.width) != null ? _leafColDef$width : 0),
157
- renderCell: function renderCell(params) {
158
- // Render leaves
159
- if (params.rowNode.groupingField == null) {
160
- if (leafColDef) {
161
- var leafParams = _extends({}, params.api.getCellParams(params.id, leafField), {
162
- api: params.api
163
- });
164
-
165
- if (leafColDef.renderCell) {
166
- return leafColDef.renderCell(leafParams);
167
- }
168
-
169
- return /*#__PURE__*/_jsx(GridGroupingColumnLeafCell, _extends({}, leafParams));
170
- }
171
-
172
- return '';
173
- } // Render current grouping criteria groups
174
-
175
-
176
- if (params.rowNode.groupingField === groupingCriteria) {
177
- return /*#__PURE__*/_jsx(GridGroupingCriteriaCell, _extends({}, params, {
178
- hideDescendantCount: hideDescendantCount
179
- }));
180
- }
181
-
182
- return '';
183
- },
184
- valueGetter: function valueGetter(params) {
185
- if (!params.rowNode) {
186
- return undefined;
187
- }
188
-
189
- if (params.rowNode.groupingField == null) {
190
- if (leafColDef) {
191
- return params.api.getCellValue(params.id, leafField);
192
- }
193
-
194
- return undefined;
195
- }
196
-
197
- if (params.rowNode.groupingField === groupingCriteria) {
198
- return params.rowNode.groupingKey;
199
- }
200
-
201
- return undefined;
202
- }
203
- }; // If we have a `mainGroupingCriteria` defined and matching the `groupingCriteria`
204
- // Then we apply the sorting / filtering on the groups of this column's grouping criteria based on the properties of `groupedByColDef`.
205
- // It can be useful to define a `leafField` for leaves rendering but still use the grouping criteria for the sorting / filtering
206
- //
207
- // If we have a `leafField` defined and matching an existing column
208
- // Then we apply the sorting / filtering on the leaves based on the properties of `leavesColDef`
209
- //
210
- // By default, we apply the sorting / filtering on the groups of this column's grouping criteria based on the properties of `groupedColDef`.
211
-
212
- var sourceProperties;
213
-
214
- if (mainGroupingCriteria && mainGroupingCriteria === groupingCriteria) {
215
- sourceProperties = getGroupingCriteriaProperties(groupedByColDef, true);
216
- } else if (leafColDef) {
217
- sourceProperties = getLeafProperties(leafColDef);
218
- } else {
219
- sourceProperties = getGroupingCriteriaProperties(groupedByColDef, true);
220
- } // The properties that can't be overridden with `colDefOverride`
221
-
222
-
223
- var forcedProperties = _extends({
224
- field: getRowGroupingFieldFromGroupingCriteria(groupingCriteria)
225
- }, GROUPING_COL_DEF_FORCED_PROPERTIES);
226
-
227
- return _extends({}, GROUPING_COL_DEF_DEFAULT_PROPERTIES, commonProperties, sourceProperties, colDefOverrideProperties, forcedProperties);
228
- };
229
-
230
- /**
231
- * Creates the `GridColDef` for a grouping column that takes care of all the grouping criteria
232
- */
233
- export var createGroupingColDefForAllGroupingCriteria = function createGroupingColDefForAllGroupingCriteria(_ref3) {
234
- var _leafColDef$width2;
235
-
236
- var apiRef = _ref3.apiRef,
237
- columnsLookup = _ref3.columnsLookup,
238
- rowGroupingModel = _ref3.rowGroupingModel,
239
- colDefOverride = _ref3.colDefOverride;
240
-
241
- var _ref4 = colDefOverride != null ? colDefOverride : {},
242
- leafField = _ref4.leafField,
243
- mainGroupingCriteria = _ref4.mainGroupingCriteria,
244
- hideDescendantCount = _ref4.hideDescendantCount,
245
- colDefOverrideProperties = _objectWithoutProperties(_ref4, _excluded2);
246
-
247
- var leafColDef = leafField ? columnsLookup[leafField] : null; // The properties that do not depend on the presence of a `leafColDef` and that can be overridden by `colDefOverride`
248
-
249
- var commonProperties = {
250
- headerName: apiRef.current.getLocaleText('groupingColumnHeaderName'),
251
- width: Math.max.apply(Math, _toConsumableArray(rowGroupingModel.map(function (field) {
252
- var _columnsLookup$field$;
253
-
254
- return ((_columnsLookup$field$ = columnsLookup[field].width) != null ? _columnsLookup$field$ : GRID_STRING_COL_DEF.width) + 40;
255
- })).concat([(_leafColDef$width2 = leafColDef == null ? void 0 : leafColDef.width) != null ? _leafColDef$width2 : 0])),
256
- renderCell: function renderCell(params) {
257
- // Render the leaves
258
- if (params.rowNode.groupingField == null) {
259
- if (leafColDef) {
260
- var leafParams = _extends({}, params.api.getCellParams(params.id, leafField), {
261
- api: params.api
262
- });
263
-
264
- if (leafColDef.renderCell) {
265
- return leafColDef.renderCell(leafParams);
266
- }
267
-
268
- return /*#__PURE__*/_jsx(GridGroupingColumnLeafCell, _extends({}, leafParams));
269
- }
270
-
271
- return '';
272
- } // Render the groups
273
-
274
-
275
- return /*#__PURE__*/_jsx(GridGroupingCriteriaCell, _extends({}, params, {
276
- hideDescendantCount: hideDescendantCount
277
- }));
278
- },
279
- valueGetter: function valueGetter(params) {
280
- if (!params.rowNode) {
281
- return undefined;
282
- }
283
-
284
- if (params.rowNode.groupingField == null) {
285
- if (leafColDef) {
286
- return params.api.getCellValue(params.id, leafField);
287
- }
288
-
289
- return undefined;
290
- }
291
-
292
- return params.rowNode.groupingKey;
293
- }
294
- }; // If we have a `mainGroupingCriteria` defined and matching one of the `orderedGroupedByFields`
295
- // Then we apply the sorting / filtering on the groups of this column's grouping criteria based on the properties of `columnsLookup[mainGroupingCriteria]`.
296
- // It can be useful to use another grouping criteria than the top level one for the sorting / filtering
297
- //
298
- // If we have a `leafField` defined and matching an existing column
299
- // Then we apply the sorting / filtering on the leaves based on the properties of `leavesColDef`
300
- //
301
- // By default, we apply the sorting / filtering on the groups of the top level grouping criteria based on the properties of `columnsLookup[orderedGroupedByFields[0]]`.
302
-
303
- var sourceProperties;
304
-
305
- if (mainGroupingCriteria && rowGroupingModel.includes(mainGroupingCriteria)) {
306
- sourceProperties = getGroupingCriteriaProperties(columnsLookup[mainGroupingCriteria], true);
307
- } else if (leafColDef) {
308
- sourceProperties = getLeafProperties(leafColDef);
309
- } else {
310
- sourceProperties = getGroupingCriteriaProperties(columnsLookup[rowGroupingModel[0]], rowGroupingModel.length === 1);
311
- } // The properties that can't be overridden with `colDefOverride`
312
-
313
-
314
- var forcedProperties = _extends({
315
- field: GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD
316
- }, GROUPING_COL_DEF_FORCED_PROPERTIES);
317
-
318
- return _extends({}, GROUPING_COL_DEF_DEFAULT_PROPERTIES, commonProperties, sourceProperties, colDefOverrideProperties, forcedProperties);
319
- };
@@ -1,13 +0,0 @@
1
- import { gridColumnLookupSelector } from '@mui/x-data-grid';
2
- import { createSelector } from '@mui/x-data-grid/internals';
3
- export var gridRowGroupingStateSelector = function gridRowGroupingStateSelector(state) {
4
- return state.rowGrouping;
5
- };
6
- export var gridRowGroupingModelSelector = createSelector(gridRowGroupingStateSelector, function (rowGrouping) {
7
- return rowGrouping.model;
8
- });
9
- export var gridRowGroupingSanitizedModelSelector = createSelector(gridRowGroupingModelSelector, gridColumnLookupSelector, function (model, columnsLookup) {
10
- return model.filter(function (field) {
11
- return !!columnsLookup[field] && columnsLookup[field].groupable;
12
- });
13
- });
@@ -1,147 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import { gridRowGroupingSanitizedModelSelector } from './gridRowGroupingSelector';
3
- export var GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD = '__row_group_by_columns_group__';
4
- export var ROW_GROUPING_STRATEGY = 'grouping-columns';
5
- export var getRowGroupingFieldFromGroupingCriteria = function getRowGroupingFieldFromGroupingCriteria(groupingCriteria) {
6
- if (groupingCriteria === null) {
7
- return GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD;
8
- }
9
-
10
- return "__row_group_by_columns_group_".concat(groupingCriteria, "__");
11
- };
12
- export var getRowGroupingCriteriaFromGroupingField = function getRowGroupingCriteriaFromGroupingField(groupingColDefField) {
13
- var match = groupingColDefField.match(/^__row_group_by_columns_group_(.*)__$/);
14
-
15
- if (!match) {
16
- return null;
17
- }
18
-
19
- return match[1];
20
- };
21
- export var isGroupingColumn = function isGroupingColumn(field) {
22
- return field === GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD || getRowGroupingCriteriaFromGroupingField(field) !== null;
23
- };
24
-
25
- /**
26
- * When filtering a group, we only want to filter according to the items related to this grouping column.
27
- */
28
- var shouldApplyFilterItemOnGroup = function shouldApplyFilterItemOnGroup(columnField, node) {
29
- if (columnField === GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD) {
30
- return true;
31
- }
32
-
33
- var groupingCriteriaField = getRowGroupingCriteriaFromGroupingField(columnField);
34
- return groupingCriteriaField === node.groupingField;
35
- };
36
- /**
37
- * A leaf is visible if it passed the filter
38
- * A group is visible if all the following criteria are met:
39
- * - One of its children is passing the filter
40
- * - It is passing the filter
41
- */
42
-
43
-
44
- export var filterRowTreeFromGroupingColumns = function filterRowTreeFromGroupingColumns(params) {
45
- var rowTree = params.rowTree,
46
- isRowMatchingFilters = params.isRowMatchingFilters;
47
- var visibleRowsLookup = {};
48
- var filteredRowsLookup = {};
49
- var filteredDescendantCountLookup = {};
50
-
51
- var filterTreeNode = function filterTreeNode(node, areAncestorsPassingChildren, areAncestorsExpanded) {
52
- var _node$children, _node$children2;
53
-
54
- var isMatchingFilters;
55
-
56
- if (!isRowMatchingFilters) {
57
- isMatchingFilters = true;
58
- } else {
59
- var shouldApplyItem = node.isAutoGenerated ? function (columnField) {
60
- return shouldApplyFilterItemOnGroup(columnField, node);
61
- } : undefined;
62
- isMatchingFilters = isRowMatchingFilters(node.id, shouldApplyItem);
63
- }
64
-
65
- var filteredDescendantCount = 0;
66
- (_node$children = node.children) == null ? void 0 : _node$children.forEach(function (childId) {
67
- var childNode = rowTree[childId];
68
- var childSubTreeSize = filterTreeNode(childNode, areAncestorsPassingChildren && isMatchingFilters, areAncestorsExpanded && !!node.childrenExpanded);
69
- filteredDescendantCount += childSubTreeSize;
70
- });
71
- var shouldPassFilters;
72
-
73
- if (!areAncestorsPassingChildren) {
74
- shouldPassFilters = false;
75
- } else if ((_node$children2 = node.children) != null && _node$children2.length) {
76
- shouldPassFilters = isMatchingFilters && filteredDescendantCount > 0;
77
- } else {
78
- shouldPassFilters = isMatchingFilters;
79
- }
80
-
81
- visibleRowsLookup[node.id] = shouldPassFilters && areAncestorsExpanded;
82
- filteredRowsLookup[node.id] = shouldPassFilters;
83
-
84
- if (!shouldPassFilters) {
85
- return 0;
86
- }
87
-
88
- filteredDescendantCountLookup[node.id] = filteredDescendantCount;
89
-
90
- if (!node.children) {
91
- return filteredDescendantCount + 1;
92
- }
93
-
94
- return filteredDescendantCount;
95
- };
96
-
97
- var nodes = Object.values(rowTree);
98
-
99
- for (var i = 0; i < nodes.length; i += 1) {
100
- var node = nodes[i];
101
-
102
- if (node.depth === 0) {
103
- filterTreeNode(node, true, true);
104
- }
105
- }
106
-
107
- return {
108
- visibleRowsLookup: visibleRowsLookup,
109
- filteredRowsLookup: filteredRowsLookup,
110
- filteredDescendantCountLookup: filteredDescendantCountLookup
111
- };
112
- };
113
- export var getColDefOverrides = function getColDefOverrides(groupingColDefProp, fields) {
114
- if (typeof groupingColDefProp === 'function') {
115
- return groupingColDefProp({
116
- groupingName: ROW_GROUPING_STRATEGY,
117
- fields: fields
118
- });
119
- }
120
-
121
- return groupingColDefProp;
122
- };
123
- export var mergeStateWithRowGroupingModel = function mergeStateWithRowGroupingModel(rowGroupingModel) {
124
- return function (state) {
125
- return _extends({}, state, {
126
- rowGrouping: _extends({}, state.rowGrouping, {
127
- model: rowGroupingModel
128
- })
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);
147
- };
@@ -1,3 +0,0 @@
1
- export * from './gridRowGroupingSelector';
2
- export * from './gridRowGroupingInterfaces';
3
- export { GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD, getRowGroupingFieldFromGroupingCriteria } from './gridRowGroupingUtils';
@@ -1,206 +0,0 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
- import _extends from "@babel/runtime/helpers/esm/extends";
3
- import * as React from 'react';
4
- import Divider from '@mui/material/Divider';
5
- import { 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';
9
- import { GridRowGroupableColumnMenuItems } from '../../../components/GridRowGroupableColumnMenuItems';
10
- import { GridRowGroupingColumnMenuItems } from '../../../components/GridRowGroupingColumnMenuItems';
11
- import { jsx as _jsx } from "react/jsx-runtime";
12
- export var rowGroupingStateInitializer = function rowGroupingStateInitializer(state, props) {
13
- var _ref, _props$rowGroupingMod, _props$initialState, _props$initialState$r;
14
-
15
- return _extends({}, state, {
16
- rowGrouping: {
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: []
19
- }
20
- });
21
- };
22
- /**
23
- * @requires useGridColumns (state, method) - can be after, async only
24
- * @requires useGridRows (state, method) - can be after, async only
25
- * @requires useGridParamsApi (method) - can be after, async only
26
- */
27
-
28
- export var useGridRowGrouping = function useGridRowGrouping(apiRef, props) {
29
- apiRef.current.unstable_updateControlState({
30
- stateId: 'rowGrouping',
31
- propModel: props.rowGroupingModel,
32
- propOnChange: props.onRowGroupingModelChange,
33
- stateSelector: gridRowGroupingModelSelector,
34
- changeEvent: 'rowGroupingModelChange'
35
- });
36
- /**
37
- * API METHODS
38
- */
39
-
40
- var setRowGroupingModel = React.useCallback(function (model) {
41
- var currentModel = gridRowGroupingModelSelector(apiRef);
42
-
43
- if (currentModel !== model) {
44
- apiRef.current.setState(mergeStateWithRowGroupingModel(model));
45
- setStrategyAvailability(apiRef, props.disableRowGrouping);
46
- apiRef.current.forceUpdate();
47
- }
48
- }, [apiRef, props.disableRowGrouping]);
49
- var addRowGroupingCriteria = React.useCallback(function (field, groupingIndex) {
50
- var currentModel = gridRowGroupingModelSelector(apiRef);
51
-
52
- if (currentModel.includes(field)) {
53
- return;
54
- }
55
-
56
- var cleanGroupingIndex = groupingIndex != null ? groupingIndex : currentModel.length;
57
- var updatedModel = [].concat(_toConsumableArray(currentModel.slice(0, cleanGroupingIndex)), [field], _toConsumableArray(currentModel.slice(cleanGroupingIndex)));
58
- apiRef.current.setRowGroupingModel(updatedModel);
59
- }, [apiRef]);
60
- var removeRowGroupingCriteria = React.useCallback(function (field) {
61
- var currentModel = gridRowGroupingModelSelector(apiRef);
62
-
63
- if (!currentModel.includes(field)) {
64
- return;
65
- }
66
-
67
- apiRef.current.setRowGroupingModel(currentModel.filter(function (el) {
68
- return el !== field;
69
- }));
70
- }, [apiRef]);
71
- var setRowGroupingCriteriaIndex = React.useCallback(function (field, targetIndex) {
72
- var currentModel = gridRowGroupingModelSelector(apiRef);
73
- var currentTargetIndex = currentModel.indexOf(field);
74
-
75
- if (currentTargetIndex === -1) {
76
- return;
77
- }
78
-
79
- var updatedModel = _toConsumableArray(currentModel);
80
-
81
- updatedModel.splice(targetIndex, 0, updatedModel.splice(currentTargetIndex, 1)[0]);
82
- apiRef.current.setRowGroupingModel(updatedModel);
83
- }, [apiRef]);
84
- var rowGroupingApi = {
85
- setRowGroupingModel: setRowGroupingModel,
86
- addRowGroupingCriteria: addRowGroupingCriteria,
87
- removeRowGroupingCriteria: removeRowGroupingCriteria,
88
- setRowGroupingCriteriaIndex: setRowGroupingCriteriaIndex
89
- };
90
- useGridApiMethod(apiRef, rowGroupingApi, 'GridRowGroupingApi');
91
- /**
92
- * PRE-PROCESSING
93
- */
94
-
95
- var addColumnMenuButtons = React.useCallback(function (initialValue, columns) {
96
- if (props.disableRowGrouping) {
97
- return initialValue;
98
- }
99
-
100
- var menuItems;
101
-
102
- if (isGroupingColumn(columns.field)) {
103
- menuItems = /*#__PURE__*/_jsx(GridRowGroupingColumnMenuItems, {});
104
- } else if (columns.groupable) {
105
- menuItems = /*#__PURE__*/_jsx(GridRowGroupableColumnMenuItems, {});
106
- } else {
107
- menuItems = null;
108
- }
109
-
110
- if (menuItems == null) {
111
- return initialValue;
112
- }
113
-
114
- return [].concat(_toConsumableArray(initialValue), [/*#__PURE__*/_jsx(Divider, {}), menuItems]);
115
- }, [props.disableRowGrouping]);
116
- var stateExportPreProcessing = React.useCallback(function (prevState) {
117
- if (props.disableRowGrouping) {
118
- return prevState;
119
- }
120
-
121
- var rowGroupingModelToExport = gridRowGroupingModelSelector(apiRef);
122
-
123
- if (rowGroupingModelToExport.length === 0) {
124
- return prevState;
125
- }
126
-
127
- return _extends({}, prevState, {
128
- rowGrouping: {
129
- model: rowGroupingModelToExport
130
- }
131
- });
132
- }, [apiRef, props.disableRowGrouping]);
133
- var stateRestorePreProcessing = React.useCallback(function (params, context) {
134
- var _context$stateToResto;
135
-
136
- if (props.disableRowGrouping) {
137
- return params;
138
- }
139
-
140
- var rowGroupingModel = (_context$stateToResto = context.stateToRestore.rowGrouping) == null ? void 0 : _context$stateToResto.model;
141
-
142
- if (rowGroupingModel != null) {
143
- apiRef.current.setState(mergeStateWithRowGroupingModel(rowGroupingModel));
144
- }
145
-
146
- return params;
147
- }, [apiRef, props.disableRowGrouping]);
148
- useGridRegisterPipeProcessor(apiRef, 'columnMenu', addColumnMenuButtons);
149
- useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
150
- useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
151
- /**
152
- * EVENTS
153
- */
154
-
155
- var handleCellKeyDown = React.useCallback(function (params, event) {
156
- var cellParams = apiRef.current.getCellParams(params.id, params.field);
157
-
158
- if (isGroupingColumn(cellParams.field) && event.key === ' ' && !event.shiftKey) {
159
- var _gridFilteredDescenda;
160
-
161
- event.stopPropagation();
162
- event.preventDefault();
163
- var filteredDescendantCount = (_gridFilteredDescenda = gridFilteredDescendantCountLookupSelector(apiRef)[params.id]) != null ? _gridFilteredDescenda : 0;
164
- var isOnGroupingCell = props.rowGroupingColumnMode === 'single' || getRowGroupingFieldFromGroupingCriteria(params.rowNode.groupingField) === params.field;
165
-
166
- if (!isOnGroupingCell || filteredDescendantCount === 0) {
167
- return;
168
- }
169
-
170
- apiRef.current.setRowChildrenExpansion(params.id, !params.rowNode.childrenExpanded);
171
- }
172
- }, [apiRef, props.rowGroupingColumnMode]);
173
- var checkGroupingColumnsModelDiff = React.useCallback(function () {
174
- var rowGroupingModel = gridRowGroupingSanitizedModelSelector(apiRef);
175
- var lastGroupingColumnsModelApplied = gridRowGroupingStateSelector(apiRef.current.state).unstable_sanitizedModelOnLastRowTreeCreation;
176
-
177
- if (!isDeepEqual(lastGroupingColumnsModelApplied, rowGroupingModel)) {
178
- apiRef.current.setState(function (state) {
179
- return _extends({}, state, {
180
- rowGrouping: _extends({}, state.rowGrouping, {
181
- unstable_sanitizedModelOnLastRowTreeCreation: rowGroupingModel
182
- })
183
- });
184
- });
185
- apiRef.current.unstable_requestPipeProcessorsApplication('hydrateColumns');
186
- setStrategyAvailability(apiRef, props.disableRowGrouping); // Refresh the row tree creation strategy processing
187
- // TODO: Add a clean way to re-run a strategy processing without publishing a private event
188
-
189
- if (apiRef.current.unstable_getActiveStrategy('rowTree') === ROW_GROUPING_STRATEGY) {
190
- apiRef.current.publishEvent('activeStrategyProcessorChange', 'rowTreeCreation');
191
- }
192
- }
193
- }, [apiRef, props.disableRowGrouping]);
194
- useGridApiEventHandler(apiRef, 'cellKeyDown', handleCellKeyDown);
195
- useGridApiEventHandler(apiRef, 'columnsChange', checkGroupingColumnsModelDiff);
196
- useGridApiEventHandler(apiRef, 'rowGroupingModelChange', checkGroupingColumnsModelDiff);
197
- /**
198
- * EFFECTS
199
- */
200
-
201
- React.useEffect(function () {
202
- if (props.rowGroupingModel !== undefined) {
203
- apiRef.current.setRowGroupingModel(props.rowGroupingModel);
204
- }
205
- }, [apiRef, props.rowGroupingModel]);
206
- };