@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,37 @@
1
+ export declare type GridRowGroupingModel = string[];
2
+ export interface GridRowGroupingState {
3
+ model: GridRowGroupingModel;
4
+ /**
5
+ * Tracks the model on the last pre-processing
6
+ * Allows to check if we need to re-build the grouping columns when the grid upserts a column.
7
+ * TODO: Move outside of the state
8
+ */
9
+ unstable_sanitizedModelOnLastRowTreeCreation: GridRowGroupingModel;
10
+ }
11
+ export interface GridRowGroupingInitialState {
12
+ model?: GridRowGroupingModel;
13
+ }
14
+ export interface GridRowGroupingApi {
15
+ /**
16
+ * Sets the columns to use as grouping criteria.
17
+ * @param {GridRowGroupingModel} model The columns to use as grouping criteria.
18
+ */
19
+ setRowGroupingModel: (model: GridRowGroupingModel) => void;
20
+ /**
21
+ * Adds the field to the row grouping model.
22
+ * @param {string} groupingCriteriaField The field from which we want to group the rows.
23
+ * @param {number | undefined} groupingIndex The grouping index at which we want to insert the new grouping criteria. By default, it will be inserted at the end of the model.
24
+ */
25
+ addRowGroupingCriteria: (groupingCriteriaField: string, groupingIndex?: number) => void;
26
+ /**
27
+ * Remove the field from the row grouping model.
28
+ * @param {string} groupingCriteriaField The field from which we want to stop grouping the rows.
29
+ */
30
+ removeRowGroupingCriteria: (groupingCriteriaField: string) => void;
31
+ /**
32
+ * Sets the grouping index of a grouping criteria.
33
+ * @param {string} groupingCriteriaField The field of the grouping criteria from which we want to change the grouping index.
34
+ * @param {number} groupingIndex The new grouping index of this grouping criteria.
35
+ */
36
+ setRowGroupingCriteriaIndex: (groupingCriteriaField: string, groupingIndex: number) => void;
37
+ }
@@ -0,0 +1,4 @@
1
+ import { GridStatePremium } from '../../../models/gridStatePremium';
2
+ export declare const gridRowGroupingStateSelector: (state: GridStatePremium) => import("./gridRowGroupingInterfaces").GridRowGroupingState;
3
+ export declare const gridRowGroupingModelSelector: import("@mui/x-data-grid-pro").OutputSelector<GridStatePremium, import("./gridRowGroupingInterfaces").GridRowGroupingModel>;
4
+ export declare const gridRowGroupingSanitizedModelSelector: import("@mui/x-data-grid-pro").OutputSelector<GridStatePremium, string[]>;
@@ -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,27 @@
1
+ import * as React from 'react';
2
+ import { GridRowTreeConfig, GridFilterState } from '@mui/x-data-grid-pro';
3
+ import { GridAggregatedFilterItemApplier } from '@mui/x-data-grid-pro/internals';
4
+ import { DataGridPremiumProcessedProps } from '../../../models/dataGridPremiumProps';
5
+ import { GridRowGroupingModel } from './gridRowGroupingInterfaces';
6
+ import { GridStatePremium } from '../../../models/gridStatePremium';
7
+ import { GridApiPremium } from '../../../models/gridApiPremium';
8
+ export declare const GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD = "__row_group_by_columns_group__";
9
+ export declare const ROW_GROUPING_STRATEGY = "grouping-columns";
10
+ export declare const getRowGroupingFieldFromGroupingCriteria: (groupingCriteria: string | null) => string;
11
+ export declare const getRowGroupingCriteriaFromGroupingField: (groupingColDefField: string) => string | null;
12
+ export declare const isGroupingColumn: (field: string) => boolean;
13
+ interface FilterRowTreeFromTreeDataParams {
14
+ rowTree: GridRowTreeConfig;
15
+ isRowMatchingFilters: GridAggregatedFilterItemApplier | null;
16
+ }
17
+ /**
18
+ * A leaf is visible if it passed the filter
19
+ * A group is visible if all the following criteria are met:
20
+ * - One of its children is passing the filter
21
+ * - It is passing the filter
22
+ */
23
+ export declare const filterRowTreeFromGroupingColumns: (params: FilterRowTreeFromTreeDataParams) => Omit<GridFilterState, 'filterModel'>;
24
+ export declare const getColDefOverrides: (groupingColDefProp: DataGridPremiumProcessedProps['groupingColDef'], fields: string[]) => import("@mui/x-data-grid-pro").GridGroupingColDefOverride<any> | null | undefined;
25
+ export declare const mergeStateWithRowGroupingModel: (rowGroupingModel: GridRowGroupingModel) => (state: GridStatePremium) => GridStatePremium;
26
+ export declare const setStrategyAvailability: (apiRef: React.MutableRefObject<GridApiPremium>, disableRowGrouping: boolean) => void;
27
+ export {};
@@ -0,0 +1,139 @@
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
+ var _node$children, _node$children2;
53
+
54
+ let isMatchingFilters;
55
+
56
+ if (!isRowMatchingFilters) {
57
+ isMatchingFilters = true;
58
+ } else {
59
+ const shouldApplyItem = node.isAutoGenerated ? columnField => shouldApplyFilterItemOnGroup(columnField, node) : undefined;
60
+ isMatchingFilters = isRowMatchingFilters(node.id, shouldApplyItem);
61
+ }
62
+
63
+ let filteredDescendantCount = 0;
64
+ (_node$children = node.children) == null ? void 0 : _node$children.forEach(childId => {
65
+ const childNode = rowTree[childId];
66
+ const childSubTreeSize = filterTreeNode(childNode, areAncestorsPassingChildren && isMatchingFilters, areAncestorsExpanded && !!node.childrenExpanded);
67
+ filteredDescendantCount += childSubTreeSize;
68
+ });
69
+ let shouldPassFilters;
70
+
71
+ if (!areAncestorsPassingChildren) {
72
+ shouldPassFilters = false;
73
+ } else if ((_node$children2 = node.children) != null && _node$children2.length) {
74
+ shouldPassFilters = isMatchingFilters && filteredDescendantCount > 0;
75
+ } else {
76
+ shouldPassFilters = isMatchingFilters;
77
+ }
78
+
79
+ visibleRowsLookup[node.id] = shouldPassFilters && areAncestorsExpanded;
80
+ filteredRowsLookup[node.id] = shouldPassFilters;
81
+
82
+ if (!shouldPassFilters) {
83
+ return 0;
84
+ }
85
+
86
+ filteredDescendantCountLookup[node.id] = filteredDescendantCount;
87
+
88
+ if (!node.children) {
89
+ return filteredDescendantCount + 1;
90
+ }
91
+
92
+ return filteredDescendantCount;
93
+ };
94
+
95
+ const nodes = Object.values(rowTree);
96
+
97
+ for (let i = 0; i < nodes.length; i += 1) {
98
+ const node = nodes[i];
99
+
100
+ if (node.depth === 0) {
101
+ filterTreeNode(node, true, true);
102
+ }
103
+ }
104
+
105
+ return {
106
+ visibleRowsLookup,
107
+ filteredRowsLookup,
108
+ filteredDescendantCountLookup
109
+ };
110
+ };
111
+ export const getColDefOverrides = (groupingColDefProp, fields) => {
112
+ if (typeof groupingColDefProp === 'function') {
113
+ return groupingColDefProp({
114
+ groupingName: ROW_GROUPING_STRATEGY,
115
+ fields
116
+ });
117
+ }
118
+
119
+ return groupingColDefProp;
120
+ };
121
+ export const mergeStateWithRowGroupingModel = rowGroupingModel => state => _extends({}, state, {
122
+ rowGrouping: _extends({}, state.rowGrouping, {
123
+ model: rowGroupingModel
124
+ })
125
+ });
126
+ export const setStrategyAvailability = (apiRef, disableRowGrouping) => {
127
+ let isAvailable;
128
+
129
+ if (disableRowGrouping) {
130
+ isAvailable = () => false;
131
+ } else {
132
+ isAvailable = () => {
133
+ const rowGroupingSanitizedModel = gridRowGroupingSanitizedModelSelector(apiRef);
134
+ return rowGroupingSanitizedModel.length > 0;
135
+ };
136
+ }
137
+
138
+ apiRef.current.unstable_setStrategyAvailability('rowTree', ROW_GROUPING_STRATEGY, isAvailable);
139
+ };
@@ -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,3 @@
1
+ export * from './gridRowGroupingSelector';
2
+ export * from './gridRowGroupingInterfaces';
3
+ export { GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD, getRowGroupingFieldFromGroupingCriteria } from './gridRowGroupingUtils';
@@ -0,0 +1,11 @@
1
+ import * as React from 'react';
2
+ import { GridStateInitializer } from '@mui/x-data-grid-pro/internals';
3
+ import { GridApiPremium } from '../../../models/gridApiPremium';
4
+ import { DataGridPremiumProcessedProps } from '../../../models/dataGridPremiumProps';
5
+ export declare const rowGroupingStateInitializer: GridStateInitializer<Pick<DataGridPremiumProcessedProps, 'rowGroupingModel' | 'initialState'>>;
6
+ /**
7
+ * @requires useGridColumns (state, method) - can be after, async only
8
+ * @requires useGridRows (state, method) - can be after, async only
9
+ * @requires useGridParamsApi (method) - can be after, async only
10
+ */
11
+ export declare const useGridRowGrouping: (apiRef: React.MutableRefObject<GridApiPremium>, props: Pick<DataGridPremiumProcessedProps, 'initialState' | 'rowGroupingModel' | 'onRowGroupingModelChange' | 'defaultGroupingExpansionDepth' | 'isGroupExpandedByDefault' | 'groupingColDef' | 'rowGroupingColumnMode' | 'disableRowGrouping'>) => void;
@@ -0,0 +1,200 @@
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) => {
12
+ var _ref, _props$rowGroupingMod, _props$initialState, _props$initialState$r;
13
+
14
+ return _extends({}, state, {
15
+ rowGrouping: {
16
+ 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
+ unstable_sanitizedModelOnLastRowTreeCreation: []
18
+ }
19
+ });
20
+ };
21
+ /**
22
+ * @requires useGridColumns (state, method) - can be after, async only
23
+ * @requires useGridRows (state, method) - can be after, async only
24
+ * @requires useGridParamsApi (method) - can be after, async only
25
+ */
26
+
27
+ export const useGridRowGrouping = (apiRef, props) => {
28
+ apiRef.current.unstable_updateControlState({
29
+ stateId: 'rowGrouping',
30
+ propModel: props.rowGroupingModel,
31
+ propOnChange: props.onRowGroupingModelChange,
32
+ stateSelector: gridRowGroupingModelSelector,
33
+ changeEvent: 'rowGroupingModelChange'
34
+ });
35
+ /**
36
+ * API METHODS
37
+ */
38
+
39
+ const setRowGroupingModel = React.useCallback(model => {
40
+ const currentModel = gridRowGroupingModelSelector(apiRef);
41
+
42
+ if (currentModel !== model) {
43
+ apiRef.current.setState(mergeStateWithRowGroupingModel(model));
44
+ setStrategyAvailability(apiRef, props.disableRowGrouping);
45
+ apiRef.current.forceUpdate();
46
+ }
47
+ }, [apiRef, props.disableRowGrouping]);
48
+ const addRowGroupingCriteria = React.useCallback((field, groupingIndex) => {
49
+ const currentModel = gridRowGroupingModelSelector(apiRef);
50
+
51
+ if (currentModel.includes(field)) {
52
+ return;
53
+ }
54
+
55
+ const cleanGroupingIndex = groupingIndex != null ? groupingIndex : currentModel.length;
56
+ const updatedModel = [...currentModel.slice(0, cleanGroupingIndex), field, ...currentModel.slice(cleanGroupingIndex)];
57
+ apiRef.current.setRowGroupingModel(updatedModel);
58
+ }, [apiRef]);
59
+ const removeRowGroupingCriteria = React.useCallback(field => {
60
+ const currentModel = gridRowGroupingModelSelector(apiRef);
61
+
62
+ if (!currentModel.includes(field)) {
63
+ return;
64
+ }
65
+
66
+ apiRef.current.setRowGroupingModel(currentModel.filter(el => el !== field));
67
+ }, [apiRef]);
68
+ const setRowGroupingCriteriaIndex = React.useCallback((field, targetIndex) => {
69
+ const currentModel = gridRowGroupingModelSelector(apiRef);
70
+ const currentTargetIndex = currentModel.indexOf(field);
71
+
72
+ if (currentTargetIndex === -1) {
73
+ return;
74
+ }
75
+
76
+ const updatedModel = [...currentModel];
77
+ updatedModel.splice(targetIndex, 0, updatedModel.splice(currentTargetIndex, 1)[0]);
78
+ apiRef.current.setRowGroupingModel(updatedModel);
79
+ }, [apiRef]);
80
+ const rowGroupingApi = {
81
+ setRowGroupingModel,
82
+ addRowGroupingCriteria,
83
+ removeRowGroupingCriteria,
84
+ setRowGroupingCriteriaIndex
85
+ };
86
+ useGridApiMethod(apiRef, rowGroupingApi, 'GridRowGroupingApi');
87
+ /**
88
+ * PRE-PROCESSING
89
+ */
90
+
91
+ const addColumnMenuButtons = React.useCallback((initialValue, columns) => {
92
+ if (props.disableRowGrouping) {
93
+ return initialValue;
94
+ }
95
+
96
+ let menuItems;
97
+
98
+ if (isGroupingColumn(columns.field)) {
99
+ menuItems = /*#__PURE__*/_jsx(GridRowGroupingColumnMenuItems, {});
100
+ } else if (columns.groupable) {
101
+ menuItems = /*#__PURE__*/_jsx(GridRowGroupableColumnMenuItems, {});
102
+ } else {
103
+ menuItems = null;
104
+ }
105
+
106
+ if (menuItems == null) {
107
+ return initialValue;
108
+ }
109
+
110
+ return [...initialValue, /*#__PURE__*/_jsx(Divider, {}), menuItems];
111
+ }, [props.disableRowGrouping]);
112
+ const stateExportPreProcessing = React.useCallback(prevState => {
113
+ if (props.disableRowGrouping) {
114
+ return prevState;
115
+ }
116
+
117
+ const rowGroupingModelToExport = gridRowGroupingModelSelector(apiRef);
118
+
119
+ if (rowGroupingModelToExport.length === 0) {
120
+ return prevState;
121
+ }
122
+
123
+ return _extends({}, prevState, {
124
+ rowGrouping: {
125
+ model: rowGroupingModelToExport
126
+ }
127
+ });
128
+ }, [apiRef, props.disableRowGrouping]);
129
+ const stateRestorePreProcessing = React.useCallback((params, context) => {
130
+ var _context$stateToResto;
131
+
132
+ if (props.disableRowGrouping) {
133
+ return params;
134
+ }
135
+
136
+ const rowGroupingModel = (_context$stateToResto = context.stateToRestore.rowGrouping) == null ? void 0 : _context$stateToResto.model;
137
+
138
+ if (rowGroupingModel != null) {
139
+ apiRef.current.setState(mergeStateWithRowGroupingModel(rowGroupingModel));
140
+ }
141
+
142
+ return params;
143
+ }, [apiRef, props.disableRowGrouping]);
144
+ useGridRegisterPipeProcessor(apiRef, 'columnMenu', addColumnMenuButtons);
145
+ useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
146
+ useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
147
+ /**
148
+ * EVENTS
149
+ */
150
+
151
+ const handleCellKeyDown = React.useCallback((params, event) => {
152
+ const cellParams = apiRef.current.getCellParams(params.id, params.field);
153
+
154
+ if (isGroupingColumn(cellParams.field) && event.key === ' ' && !event.shiftKey) {
155
+ var _gridFilteredDescenda;
156
+
157
+ event.stopPropagation();
158
+ event.preventDefault();
159
+ const filteredDescendantCount = (_gridFilteredDescenda = gridFilteredDescendantCountLookupSelector(apiRef)[params.id]) != null ? _gridFilteredDescenda : 0;
160
+ const isOnGroupingCell = props.rowGroupingColumnMode === 'single' || getRowGroupingFieldFromGroupingCriteria(params.rowNode.groupingField) === params.field;
161
+
162
+ if (!isOnGroupingCell || filteredDescendantCount === 0) {
163
+ return;
164
+ }
165
+
166
+ apiRef.current.setRowChildrenExpansion(params.id, !params.rowNode.childrenExpanded);
167
+ }
168
+ }, [apiRef, props.rowGroupingColumnMode]);
169
+ const checkGroupingColumnsModelDiff = React.useCallback(() => {
170
+ const rowGroupingModel = gridRowGroupingSanitizedModelSelector(apiRef);
171
+ const lastGroupingColumnsModelApplied = gridRowGroupingStateSelector(apiRef.current.state).unstable_sanitizedModelOnLastRowTreeCreation;
172
+
173
+ if (!isDeepEqual(lastGroupingColumnsModelApplied, rowGroupingModel)) {
174
+ apiRef.current.setState(state => _extends({}, state, {
175
+ rowGrouping: _extends({}, state.rowGrouping, {
176
+ unstable_sanitizedModelOnLastRowTreeCreation: rowGroupingModel
177
+ })
178
+ }));
179
+ apiRef.current.unstable_requestPipeProcessorsApplication('hydrateColumns');
180
+ setStrategyAvailability(apiRef, props.disableRowGrouping); // Refresh the row tree creation strategy processing
181
+ // TODO: Add a clean way to re-run a strategy processing without publishing a private event
182
+
183
+ if (apiRef.current.unstable_getActiveStrategy('rowTree') === ROW_GROUPING_STRATEGY) {
184
+ apiRef.current.publishEvent('activeStrategyProcessorChange', 'rowTreeCreation');
185
+ }
186
+ }
187
+ }, [apiRef, props.disableRowGrouping]);
188
+ useGridApiEventHandler(apiRef, 'cellKeyDown', handleCellKeyDown);
189
+ useGridApiEventHandler(apiRef, 'columnsChange', checkGroupingColumnsModelDiff);
190
+ useGridApiEventHandler(apiRef, 'rowGroupingModelChange', checkGroupingColumnsModelDiff);
191
+ /**
192
+ * EFFECTS
193
+ */
194
+
195
+ React.useEffect(() => {
196
+ if (props.rowGroupingModel !== undefined) {
197
+ apiRef.current.setRowGroupingModel(props.rowGroupingModel);
198
+ }
199
+ }, [apiRef, props.rowGroupingModel]);
200
+ };
@@ -0,0 +1,4 @@
1
+ import * as React from 'react';
2
+ import { DataGridPremiumProcessedProps } from '../../../models/dataGridPremiumProps';
3
+ import { GridApiPremium } from '../../../models/gridApiPremium';
4
+ export declare const useGridRowGroupingPreProcessors: (apiRef: React.MutableRefObject<GridApiPremium>, props: Pick<DataGridPremiumProcessedProps, 'disableRowGrouping' | 'groupingColDef' | 'rowGroupingColumnMode' | 'defaultGroupingExpansionDepth' | 'isGroupExpandedByDefault'>) => void;
@@ -0,0 +1,201 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import * as React from 'react';
3
+ import { gridColumnLookupSelector, gridRowIdsSelector, gridRowTreeSelector, useFirstRender } from '@mui/x-data-grid-pro';
4
+ import { useGridRegisterPipeProcessor, useGridRegisterStrategyProcessor, sortRowTree, buildRowTree } from '@mui/x-data-grid-pro/internals';
5
+ import { gridRowGroupingModelSelector, gridRowGroupingSanitizedModelSelector } from './gridRowGroupingSelector';
6
+ import { createGroupingColDefForAllGroupingCriteria, createGroupingColDefForOneGroupingCriteria } from './createGroupingColDef';
7
+ import { filterRowTreeFromGroupingColumns, getColDefOverrides, ROW_GROUPING_STRATEGY, isGroupingColumn, setStrategyAvailability } from './gridRowGroupingUtils';
8
+ export const useGridRowGroupingPreProcessors = (apiRef, props) => {
9
+ const getGroupingColDefs = React.useCallback(columnsState => {
10
+ if (props.disableRowGrouping) {
11
+ return [];
12
+ }
13
+
14
+ const groupingColDefProp = props.groupingColDef; // We can't use `gridGroupingRowsSanitizedModelSelector` here because the new columns are not in the state yet
15
+
16
+ const rowGroupingModel = gridRowGroupingModelSelector(apiRef).filter(field => !!columnsState.lookup[field]);
17
+
18
+ if (rowGroupingModel.length === 0) {
19
+ return [];
20
+ }
21
+
22
+ switch (props.rowGroupingColumnMode) {
23
+ case 'single':
24
+ {
25
+ return [createGroupingColDefForAllGroupingCriteria({
26
+ apiRef,
27
+ rowGroupingModel,
28
+ colDefOverride: getColDefOverrides(groupingColDefProp, rowGroupingModel),
29
+ columnsLookup: columnsState.lookup
30
+ })];
31
+ }
32
+
33
+ case 'multiple':
34
+ {
35
+ return rowGroupingModel.map(groupingCriteria => createGroupingColDefForOneGroupingCriteria({
36
+ groupingCriteria,
37
+ colDefOverride: getColDefOverrides(groupingColDefProp, [groupingCriteria]),
38
+ groupedByColDef: columnsState.lookup[groupingCriteria],
39
+ columnsLookup: columnsState.lookup
40
+ }));
41
+ }
42
+
43
+ default:
44
+ {
45
+ return [];
46
+ }
47
+ }
48
+ }, [apiRef, props.groupingColDef, props.rowGroupingColumnMode, props.disableRowGrouping]);
49
+ const updateGroupingColumn = React.useCallback(columnsState => {
50
+ const groupingColDefs = getGroupingColDefs(columnsState);
51
+ let newColumnFields = [];
52
+ const newColumnsLookup = {}; // We only keep the non-grouping columns
53
+
54
+ columnsState.all.forEach(field => {
55
+ if (!isGroupingColumn(field)) {
56
+ newColumnFields.push(field);
57
+ newColumnsLookup[field] = columnsState.lookup[field];
58
+ }
59
+ }); // We add the grouping column
60
+
61
+ groupingColDefs.forEach(groupingColDef => {
62
+ const matchingGroupingColDef = columnsState.lookup[groupingColDef.field];
63
+
64
+ if (matchingGroupingColDef) {
65
+ groupingColDef.width = matchingGroupingColDef.width;
66
+ groupingColDef.flex = matchingGroupingColDef.flex;
67
+ }
68
+
69
+ newColumnsLookup[groupingColDef.field] = groupingColDef;
70
+ });
71
+ const startIndex = newColumnFields[0] === '__check__' ? 1 : 0;
72
+ newColumnFields = [...newColumnFields.slice(0, startIndex), ...groupingColDefs.map(colDef => colDef.field), ...newColumnFields.slice(startIndex)];
73
+ columnsState.all = newColumnFields;
74
+ columnsState.lookup = newColumnsLookup;
75
+ return columnsState;
76
+ }, [getGroupingColDefs]);
77
+ const createRowTree = React.useCallback(params => {
78
+ const rowGroupingModel = gridRowGroupingSanitizedModelSelector(apiRef);
79
+ const columnsLookup = gridColumnLookupSelector(apiRef);
80
+ apiRef.current.setState(state => _extends({}, state, {
81
+ rowGrouping: _extends({}, state.rowGrouping, {
82
+ unstable_sanitizedModelOnLastRowTreeCreation: rowGroupingModel
83
+ })
84
+ }));
85
+ const distinctValues = Object.fromEntries(rowGroupingModel.map(groupingField => [groupingField, {
86
+ lookup: {},
87
+ list: []
88
+ }]));
89
+
90
+ const getCellGroupingCriteria = ({
91
+ row,
92
+ id,
93
+ colDef
94
+ }) => {
95
+ let key;
96
+
97
+ if (colDef.groupingValueGetter) {
98
+ const groupingValueGetterParams = {
99
+ colDef,
100
+ field: colDef.field,
101
+ value: row[colDef.field],
102
+ id,
103
+ row,
104
+ rowNode: {
105
+ isAutoGenerated: false,
106
+ id
107
+ }
108
+ };
109
+ key = colDef.groupingValueGetter(groupingValueGetterParams);
110
+ } else {
111
+ key = row[colDef.field];
112
+ }
113
+
114
+ return {
115
+ key,
116
+ field: colDef.field
117
+ };
118
+ };
119
+
120
+ params.ids.forEach(rowId => {
121
+ const row = params.idRowsLookup[rowId];
122
+ rowGroupingModel.forEach(groupingCriteria => {
123
+ const {
124
+ key
125
+ } = getCellGroupingCriteria({
126
+ row,
127
+ id: rowId,
128
+ colDef: columnsLookup[groupingCriteria]
129
+ });
130
+ const groupingFieldsDistinctKeys = distinctValues[groupingCriteria];
131
+
132
+ if (key != null && !groupingFieldsDistinctKeys.lookup[key.toString()]) {
133
+ groupingFieldsDistinctKeys.lookup[key.toString()] = true;
134
+ groupingFieldsDistinctKeys.list.push(key);
135
+ }
136
+ });
137
+ });
138
+ const rows = params.ids.map(rowId => {
139
+ const row = params.idRowsLookup[rowId];
140
+ const parentPath = rowGroupingModel.map(groupingField => getCellGroupingCriteria({
141
+ row,
142
+ id: rowId,
143
+ colDef: columnsLookup[groupingField]
144
+ })).filter(cell => cell.key != null);
145
+ const leafGroupingCriteria = {
146
+ key: rowId.toString(),
147
+ field: null
148
+ };
149
+ return {
150
+ path: [...parentPath, leafGroupingCriteria],
151
+ id: rowId
152
+ };
153
+ });
154
+ return buildRowTree(_extends({}, params, {
155
+ rows,
156
+ defaultGroupingExpansionDepth: props.defaultGroupingExpansionDepth,
157
+ isGroupExpandedByDefault: props.isGroupExpandedByDefault,
158
+ groupingName: ROW_GROUPING_STRATEGY
159
+ }));
160
+ }, [apiRef, props.defaultGroupingExpansionDepth, props.isGroupExpandedByDefault]);
161
+ const filterRows = React.useCallback(params => {
162
+ const rowTree = gridRowTreeSelector(apiRef);
163
+ return filterRowTreeFromGroupingColumns({
164
+ rowTree,
165
+ isRowMatchingFilters: params.isRowMatchingFilters
166
+ });
167
+ }, [apiRef]);
168
+ const sortRows = React.useCallback(params => {
169
+ const rowTree = gridRowTreeSelector(apiRef);
170
+ const rowIds = gridRowIdsSelector(apiRef);
171
+ return sortRowTree({
172
+ rowTree,
173
+ rowIds,
174
+ sortRowList: params.sortRowList,
175
+ disableChildrenSorting: false
176
+ });
177
+ }, [apiRef]);
178
+ useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', updateGroupingColumn);
179
+ useGridRegisterStrategyProcessor(apiRef, ROW_GROUPING_STRATEGY, 'rowTreeCreation', createRowTree);
180
+ useGridRegisterStrategyProcessor(apiRef, ROW_GROUPING_STRATEGY, 'filtering', filterRows);
181
+ useGridRegisterStrategyProcessor(apiRef, ROW_GROUPING_STRATEGY, 'sorting', sortRows);
182
+ /**
183
+ * 1ST RENDER
184
+ */
185
+
186
+ useFirstRender(() => {
187
+ setStrategyAvailability(apiRef, props.disableRowGrouping);
188
+ });
189
+ /**
190
+ * EFFECTS
191
+ */
192
+
193
+ const isFirstRender = React.useRef(true);
194
+ React.useEffect(() => {
195
+ if (!isFirstRender.current) {
196
+ setStrategyAvailability(apiRef, props.disableRowGrouping);
197
+ } else {
198
+ isFirstRender.current = false;
199
+ }
200
+ }, [apiRef, props.disableRowGrouping]);
201
+ };
@@ -0,0 +1,2 @@
1
+ export * from './features';
2
+ export * from './utils';
package/hooks/index.js ADDED
@@ -0,0 +1,3 @@
1
+ // Only export the variable and types that should be publicly exposed and re-exported from `@mui/x-data-grid-premium`
2
+ export * from './features';
3
+ export * from './utils';
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "./index.js",
4
+ "main": "../node/hooks/index.js",
5
+ "types": "./index.d.ts"
6
+ }
@@ -0,0 +1 @@
1
+ export * from './useKeepGroupedColumnsHidden';
@@ -0,0 +1 @@
1
+ export * from './useKeepGroupedColumnsHidden';