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