@mui/x-data-grid-premium 5.12.3 → 5.14.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 (122) hide show
  1. package/CHANGELOG.md +147 -1
  2. package/DataGridPremium/DataGridPremium.js +48 -1
  3. package/DataGridPremium/useDataGridPremiumComponent.js +6 -1
  4. package/DataGridPremium/useDataGridPremiumProps.js +17 -7
  5. package/components/GridAggregationColumnMenuItem.d.ts +9 -0
  6. package/components/GridAggregationColumnMenuItem.js +93 -0
  7. package/components/GridAggregationHeader.d.ts +4 -0
  8. package/components/GridAggregationHeader.js +94 -0
  9. package/components/GridExcelExportMenuItem.js +11 -4
  10. package/components/GridFooterCell.d.ts +9 -0
  11. package/components/GridFooterCell.js +51 -0
  12. package/components/GridGroupingColumnFooterCell.d.ts +4 -0
  13. package/components/GridGroupingColumnFooterCell.js +29 -0
  14. package/hooks/features/aggregation/createAggregationLookup.d.ts +10 -0
  15. package/hooks/features/aggregation/createAggregationLookup.js +128 -0
  16. package/hooks/features/aggregation/gridAggregationFunctions.d.ts +8 -0
  17. package/hooks/features/aggregation/gridAggregationFunctions.js +96 -0
  18. package/hooks/features/aggregation/gridAggregationInterfaces.d.ts +104 -0
  19. package/hooks/features/aggregation/gridAggregationInterfaces.js +1 -0
  20. package/hooks/features/aggregation/gridAggregationSelectors.d.ts +4 -0
  21. package/hooks/features/aggregation/gridAggregationSelectors.js +5 -0
  22. package/hooks/features/aggregation/gridAggregationUtils.d.ts +40 -0
  23. package/hooks/features/aggregation/gridAggregationUtils.js +177 -0
  24. package/hooks/features/aggregation/index.d.ts +4 -0
  25. package/hooks/features/aggregation/index.js +4 -0
  26. package/hooks/features/aggregation/useGridAggregation.d.ts +6 -0
  27. package/hooks/features/aggregation/useGridAggregation.js +94 -0
  28. package/hooks/features/aggregation/useGridAggregationPreProcessors.d.ts +4 -0
  29. package/hooks/features/aggregation/useGridAggregationPreProcessors.js +137 -0
  30. package/hooks/features/aggregation/wrapColumnWithAggregation.d.ts +29 -0
  31. package/hooks/features/aggregation/wrapColumnWithAggregation.js +257 -0
  32. package/hooks/features/export/serializer/excelSerializer.js +2 -1
  33. package/hooks/features/index.d.ts +1 -0
  34. package/hooks/features/index.js +1 -0
  35. package/hooks/features/rowGrouping/createGroupingColDef.js +13 -2
  36. package/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -1
  37. package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +1 -1
  38. package/hooks/features/rowGrouping/useGridRowGrouping.js +20 -10
  39. package/index.js +1 -1
  40. package/legacy/DataGridPremium/DataGridPremium.js +48 -1
  41. package/legacy/DataGridPremium/useDataGridPremiumComponent.js +6 -1
  42. package/legacy/DataGridPremium/useDataGridPremiumProps.js +12 -2
  43. package/legacy/components/GridAggregationColumnMenuItem.js +95 -0
  44. package/legacy/components/GridAggregationHeader.js +95 -0
  45. package/legacy/components/GridExcelExportMenuItem.js +11 -4
  46. package/legacy/components/GridFooterCell.js +63 -0
  47. package/legacy/components/GridGroupingColumnFooterCell.js +27 -0
  48. package/legacy/hooks/features/aggregation/createAggregationLookup.js +127 -0
  49. package/legacy/hooks/features/aggregation/gridAggregationFunctions.js +94 -0
  50. package/legacy/hooks/features/aggregation/gridAggregationInterfaces.js +1 -0
  51. package/legacy/hooks/features/aggregation/gridAggregationSelectors.js +11 -0
  52. package/legacy/hooks/features/aggregation/gridAggregationUtils.js +189 -0
  53. package/legacy/hooks/features/aggregation/index.js +4 -0
  54. package/legacy/hooks/features/aggregation/useGridAggregation.js +95 -0
  55. package/legacy/hooks/features/aggregation/useGridAggregationPreProcessors.js +140 -0
  56. package/legacy/hooks/features/aggregation/wrapColumnWithAggregation.js +262 -0
  57. package/legacy/hooks/features/export/serializer/excelSerializer.js +2 -1
  58. package/legacy/hooks/features/index.js +1 -0
  59. package/legacy/hooks/features/rowGrouping/createGroupingColDef.js +13 -2
  60. package/legacy/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -1
  61. package/legacy/hooks/features/rowGrouping/useGridRowGrouping.js +24 -10
  62. package/legacy/index.js +1 -1
  63. package/legacy/typeOverloads/index.js +1 -1
  64. package/legacy/utils/releaseInfo.js +1 -1
  65. package/models/dataGridPremiumProps.d.ts +46 -1
  66. package/models/gridApiPremium.d.ts +2 -2
  67. package/models/gridStatePremium.d.ts +3 -1
  68. package/modern/DataGridPremium/DataGridPremium.js +48 -1
  69. package/modern/DataGridPremium/useDataGridPremiumComponent.js +6 -1
  70. package/modern/DataGridPremium/useDataGridPremiumProps.js +8 -2
  71. package/modern/components/GridAggregationColumnMenuItem.js +93 -0
  72. package/modern/components/GridAggregationHeader.js +92 -0
  73. package/modern/components/GridExcelExportMenuItem.js +11 -4
  74. package/modern/components/GridFooterCell.js +51 -0
  75. package/modern/components/GridGroupingColumnFooterCell.js +29 -0
  76. package/modern/hooks/features/aggregation/createAggregationLookup.js +122 -0
  77. package/modern/hooks/features/aggregation/gridAggregationFunctions.js +96 -0
  78. package/modern/hooks/features/aggregation/gridAggregationInterfaces.js +1 -0
  79. package/modern/hooks/features/aggregation/gridAggregationSelectors.js +5 -0
  80. package/modern/hooks/features/aggregation/gridAggregationUtils.js +175 -0
  81. package/modern/hooks/features/aggregation/index.js +4 -0
  82. package/modern/hooks/features/aggregation/useGridAggregation.js +92 -0
  83. package/modern/hooks/features/aggregation/useGridAggregationPreProcessors.js +135 -0
  84. package/modern/hooks/features/aggregation/wrapColumnWithAggregation.js +251 -0
  85. package/modern/hooks/features/export/serializer/excelSerializer.js +2 -1
  86. package/modern/hooks/features/index.js +1 -0
  87. package/modern/hooks/features/rowGrouping/createGroupingColDef.js +13 -2
  88. package/modern/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -1
  89. package/modern/hooks/features/rowGrouping/useGridRowGrouping.js +17 -11
  90. package/modern/index.js +1 -1
  91. package/modern/typeOverloads/index.js +1 -1
  92. package/modern/utils/releaseInfo.js +1 -1
  93. package/node/DataGridPremium/DataGridPremium.js +48 -1
  94. package/node/DataGridPremium/useDataGridPremiumComponent.js +8 -1
  95. package/node/DataGridPremium/useDataGridPremiumProps.js +17 -6
  96. package/node/components/GridAggregationColumnMenuItem.js +120 -0
  97. package/node/components/GridAggregationHeader.js +115 -0
  98. package/node/components/GridExcelExportMenuItem.js +12 -4
  99. package/node/components/GridFooterCell.js +73 -0
  100. package/node/components/GridGroupingColumnFooterCell.js +46 -0
  101. package/node/hooks/features/aggregation/createAggregationLookup.js +139 -0
  102. package/node/hooks/features/aggregation/gridAggregationFunctions.js +105 -0
  103. package/node/hooks/features/aggregation/gridAggregationInterfaces.js +5 -0
  104. package/node/hooks/features/aggregation/gridAggregationSelectors.js +17 -0
  105. package/node/hooks/features/aggregation/gridAggregationUtils.js +212 -0
  106. package/node/hooks/features/aggregation/index.js +65 -0
  107. package/node/hooks/features/aggregation/useGridAggregation.js +118 -0
  108. package/node/hooks/features/aggregation/useGridAggregationPreProcessors.js +161 -0
  109. package/node/hooks/features/aggregation/wrapColumnWithAggregation.js +279 -0
  110. package/node/hooks/features/export/serializer/excelSerializer.js +2 -1
  111. package/node/hooks/features/index.js +13 -0
  112. package/node/hooks/features/rowGrouping/createGroupingColDef.js +14 -2
  113. package/node/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -1
  114. package/node/hooks/features/rowGrouping/useGridRowGrouping.js +19 -10
  115. package/node/index.js +1 -1
  116. package/node/typeOverloads/index.js +16 -1
  117. package/node/utils/releaseInfo.js +1 -1
  118. package/package.json +6 -6
  119. package/typeOverloads/index.d.ts +1 -1
  120. package/typeOverloads/index.js +1 -1
  121. package/typeOverloads/modules.d.ts +32 -2
  122. package/utils/releaseInfo.js +1 -1
@@ -78,7 +78,8 @@ var serializeRow = function serializeRow(id, columns, api, defaultValueOptionsFo
78
78
  api.unstable_calculateColSpan({
79
79
  rowId: id,
80
80
  minFirstColumn: 0,
81
- maxLastColumn: columns.length - 1
81
+ maxLastColumn: columns.length,
82
+ columns: columns
82
83
  });
83
84
  columns.forEach(function (column, colIndex) {
84
85
  var colSpanInfo = api.unstable_getCellColSpanInfo(id, colIndex);
@@ -1,3 +1,4 @@
1
1
  // Only export the variable and types that should be publicly exposed and re-exported from `@mui/x-data-grid-premium`
2
+ export * from './aggregation';
2
3
  export * from './rowGrouping';
3
4
  export * from './export';
@@ -5,6 +5,7 @@ var _excluded = ["leafField", "mainGroupingCriteria", "hideDescendantCount"],
5
5
  _excluded2 = ["leafField", "mainGroupingCriteria", "hideDescendantCount"];
6
6
  import * as React from 'react';
7
7
  import { GRID_STRING_COL_DEF } from '@mui/x-data-grid-pro';
8
+ import { GridGroupingColumnFooterCell } from '../../../components/GridGroupingColumnFooterCell';
8
9
  import { GridGroupingCriteriaCell } from '../../../components/GridGroupingCriteriaCell';
9
10
  import { GridGroupingColumnLeafCell } from '../../../components/GridGroupingColumnLeafCell';
10
11
  import { getRowGroupingFieldFromGroupingCriteria, GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD } from './gridRowGroupingUtils';
@@ -155,7 +156,12 @@ export var createGroupingColDefForOneGroupingCriteria = function createGroupingC
155
156
  var commonProperties = {
156
157
  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
158
  renderCell: function renderCell(params) {
158
- // Render leaves
159
+ // Render footer
160
+ if (params.rowNode.position === 'footer') {
161
+ return /*#__PURE__*/_jsx(GridGroupingColumnFooterCell, _extends({}, params));
162
+ } // Render leaves
163
+
164
+
159
165
  if (params.rowNode.groupingField == null) {
160
166
  if (leafColDef) {
161
167
  var leafParams = _extends({}, params.api.getCellParams(params.id, leafField), {
@@ -254,7 +260,12 @@ export var createGroupingColDefForAllGroupingCriteria = function createGroupingC
254
260
  return ((_columnsLookup$field$ = columnsLookup[field].width) != null ? _columnsLookup$field$ : GRID_STRING_COL_DEF.width) + 40;
255
261
  })).concat([(_leafColDef$width2 = leafColDef == null ? void 0 : leafColDef.width) != null ? _leafColDef$width2 : 0])),
256
262
  renderCell: function renderCell(params) {
257
- // Render the leaves
263
+ // Render footer
264
+ if (params.rowNode.position === 'footer') {
265
+ return /*#__PURE__*/_jsx(GridGroupingColumnFooterCell, _extends({}, params));
266
+ } // Render the leaves
267
+
268
+
258
269
  if (params.rowNode.groupingField == null) {
259
270
  if (leafColDef) {
260
271
  var leafParams = _extends({}, params.api.getCellParams(params.id, leafField), {
@@ -81,13 +81,17 @@ export var filterRowTreeFromGroupingColumns = function filterRowTreeFromGrouping
81
81
  visibleRowsLookup[node.id] = shouldPassFilters && areAncestorsExpanded;
82
82
  filteredRowsLookup[node.id] = shouldPassFilters;
83
83
 
84
+ if (node.footerId != null) {
85
+ visibleRowsLookup[node.footerId] = shouldPassFilters && areAncestorsExpanded && !!node.childrenExpanded;
86
+ }
87
+
84
88
  if (!shouldPassFilters) {
85
89
  return 0;
86
90
  }
87
91
 
88
92
  filteredDescendantCountLookup[node.id] = filteredDescendantCount;
89
93
 
90
- if (!node.children) {
94
+ if (!node.children && !node.isAutoGenerated) {
91
95
  return filteredDescendantCount + 1;
92
96
  }
93
97
 
@@ -1,7 +1,7 @@
1
1
  import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  import * as React from 'react';
4
- import Divider from '@mui/material/Divider';
4
+ import MuiDivider from '@mui/material/Divider';
5
5
  import { useGridApiEventHandler, useGridApiMethod, gridFilteredDescendantCountLookupSelector } from '@mui/x-data-grid-pro';
6
6
  import { useGridRegisterPipeProcessor, isDeepEqual } from '@mui/x-data-grid-pro/internals';
7
7
  import { gridRowGroupingModelSelector, gridRowGroupingSanitizedModelSelector } from './gridRowGroupingSelector';
@@ -9,6 +9,15 @@ import { getRowGroupingFieldFromGroupingCriteria, ROW_GROUPING_STRATEGY, isGroup
9
9
  import { GridRowGroupableColumnMenuItems } from '../../../components/GridRowGroupableColumnMenuItems';
10
10
  import { GridRowGroupingColumnMenuItems } from '../../../components/GridRowGroupingColumnMenuItems';
11
11
  import { jsx as _jsx } from "react/jsx-runtime";
12
+
13
+ var Divider = function Divider() {
14
+ return /*#__PURE__*/_jsx(MuiDivider, {
15
+ onClick: function onClick(event) {
16
+ return event.stopPropagation();
17
+ }
18
+ });
19
+ };
20
+
12
21
  export var rowGroupingStateInitializer = function rowGroupingStateInitializer(state, props, apiRef) {
13
22
  var _ref, _props$rowGroupingMod, _props$initialState, _props$initialState$r;
14
23
 
@@ -28,6 +37,8 @@ export var rowGroupingStateInitializer = function rowGroupingStateInitializer(st
28
37
  */
29
38
 
30
39
  export var useGridRowGrouping = function useGridRowGrouping(apiRef, props) {
40
+ var _props$initialState3, _props$initialState3$;
41
+
31
42
  apiRef.current.unstable_registerControlState({
32
43
  stateId: 'rowGrouping',
33
44
  propModel: props.rowGroupingModel,
@@ -94,16 +105,16 @@ export var useGridRowGrouping = function useGridRowGrouping(apiRef, props) {
94
105
  * PRE-PROCESSING
95
106
  */
96
107
 
97
- var addColumnMenuButtons = React.useCallback(function (initialValue, columns) {
108
+ var addColumnMenuButtons = React.useCallback(function (initialValue, column) {
98
109
  if (props.disableRowGrouping) {
99
110
  return initialValue;
100
111
  }
101
112
 
102
113
  var menuItems;
103
114
 
104
- if (isGroupingColumn(columns.field)) {
115
+ if (isGroupingColumn(column.field)) {
105
116
  menuItems = /*#__PURE__*/_jsx(GridRowGroupingColumnMenuItems, {});
106
- } else if (columns.groupable) {
117
+ } else if (column.groupable) {
107
118
  menuItems = /*#__PURE__*/_jsx(GridRowGroupableColumnMenuItems, {});
108
119
  } else {
109
120
  menuItems = null;
@@ -115,14 +126,17 @@ export var useGridRowGrouping = function useGridRowGrouping(apiRef, props) {
115
126
 
116
127
  return [].concat(_toConsumableArray(initialValue), [/*#__PURE__*/_jsx(Divider, {}), menuItems]);
117
128
  }, [props.disableRowGrouping]);
118
- var stateExportPreProcessing = React.useCallback(function (prevState) {
119
- if (props.disableRowGrouping) {
120
- return prevState;
121
- }
129
+ var stateExportPreProcessing = React.useCallback(function (prevState, context) {
130
+ var _props$initialState2, _props$initialState2$;
122
131
 
123
132
  var rowGroupingModelToExport = gridRowGroupingModelSelector(apiRef);
133
+ var shouldExportRowGroupingModel = // Always export if the `exportOnlyDirtyModels` property is activated
134
+ !context.exportOnlyDirtyModels || // Always export if the model is controlled
135
+ props.rowGroupingModel != null || // Always export if the model has been initialized
136
+ ((_props$initialState2 = props.initialState) == null ? void 0 : (_props$initialState2$ = _props$initialState2.rowGrouping) == null ? void 0 : _props$initialState2$.model) != null || // Export if the model is not empty
137
+ Object.keys(rowGroupingModelToExport).length > 0;
124
138
 
125
- if (rowGroupingModelToExport.length === 0) {
139
+ if (!shouldExportRowGroupingModel) {
126
140
  return prevState;
127
141
  }
128
142
 
@@ -131,7 +145,7 @@ export var useGridRowGrouping = function useGridRowGrouping(apiRef, props) {
131
145
  model: rowGroupingModelToExport
132
146
  }
133
147
  });
134
- }, [apiRef, props.disableRowGrouping]);
148
+ }, [apiRef, props.rowGroupingModel, (_props$initialState3 = props.initialState) == null ? void 0 : (_props$initialState3$ = _props$initialState3.rowGrouping) == null ? void 0 : _props$initialState3$.model]);
135
149
  var stateRestorePreProcessing = React.useCallback(function (params, context) {
136
150
  var _context$stateToResto;
137
151
 
package/legacy/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license MUI v5.12.3
1
+ /** @license MUI v5.14.0
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
@@ -1,2 +1,2 @@
1
1
  import '@mui/x-data-grid-pro/typeOverloads';
2
- import './modules';
2
+ export * from './modules';
@@ -1,6 +1,6 @@
1
1
  import { ponyfillGlobal } from '@mui/utils';
2
2
  export var getReleaseInfo = function getReleaseInfo() {
3
- var releaseInfo = "MTY1NjAyMTYwMDAwMA==";
3
+ var releaseInfo = "MTY1ODQ0MDgwMDAwMA==";
4
4
 
5
5
  if (process.env.NODE_ENV !== 'production') {
6
6
  // A simple hack to set the value in the test environment (has no build step).
@@ -1,10 +1,15 @@
1
1
  import * as React from 'react';
2
- import { GridCallbackDetails, GridValidRowModel } from '@mui/x-data-grid-pro';
2
+ import { GridCallbackDetails, GridValidRowModel, GridRowTreeNodeConfig } from '@mui/x-data-grid-pro';
3
3
  import { GridExperimentalProFeatures, DataGridProPropsWithDefaultValue, DataGridProPropsWithoutDefaultValue, DataGridPropsWithComplexDefaultValueAfterProcessing, DataGridPropsWithComplexDefaultValueBeforeProcessing } from '@mui/x-data-grid-pro/internals';
4
4
  import type { GridRowGroupingModel } from '../hooks/features/rowGrouping';
5
+ import type { GridAggregationModel, GridAggregationFunction, GridAggregationPosition } from '../hooks/features/aggregation';
5
6
  import { GridInitialStatePremium } from './gridStatePremium';
6
7
  import { GridApiPremium } from './gridApiPremium';
7
8
  export interface GridExperimentalPremiumFeatures extends GridExperimentalProFeatures {
9
+ /**
10
+ * Enables the aggregation feature.
11
+ */
12
+ private_aggregation: boolean;
8
13
  }
9
14
  /**
10
15
  * The props users can give to the `DataGridProProps` component.
@@ -28,6 +33,12 @@ export declare type DataGridPremiumForcedPropsKey = 'signature';
28
33
  * The controlled model do not have a default value at the prop processing level, so they must be defined in `DataGridOtherProps`
29
34
  */
30
35
  export interface DataGridPremiumPropsWithDefaultValue extends DataGridProPropsWithDefaultValue {
36
+ /**
37
+ * If `true`, aggregation is disabled.
38
+ * @default false
39
+ * @ignore - do not document.
40
+ */
41
+ private_disableAggregation: boolean;
31
42
  /**
32
43
  * If `true`, the row grouping is disabled.
33
44
  * @default false
@@ -39,6 +50,28 @@ export interface DataGridPremiumPropsWithDefaultValue extends DataGridProPropsWi
39
50
  * @default 'single'
40
51
  */
41
52
  rowGroupingColumnMode: 'single' | 'multiple';
53
+ /**
54
+ * Aggregation functions available on the grid.
55
+ * @default GRID_AGGREGATION_FUNCTIONS
56
+ * @ignore - do not document.
57
+ */
58
+ private_aggregationFunctions: Record<string, GridAggregationFunction>;
59
+ /**
60
+ * Rows used to generate the aggregated value.
61
+ * If `filtered`, the aggregated values will be generated using only the rows currently passing the filtering process.
62
+ * If `all`, the aggregated values will be generated using all the rows.
63
+ * @default "filtered"
64
+ * @ignore - do not document.
65
+ */
66
+ private_aggregationRowsScope: 'filtered' | 'all';
67
+ /**
68
+ * Determines the position of an aggregated value.
69
+ * @param {GridRowTreeNodeConfig | null} groupNode The current group (`null` being the top level group).
70
+ * @returns {GridAggregationPosition | null} Position of the aggregated value (if `null`, the group will not be aggregated).
71
+ * @default `(groupNode) => groupNode == null ? 'footer' : 'inline'`
72
+ * @ignore - do not document.
73
+ */
74
+ private_getAggregationPosition: (groupNode: GridRowTreeNodeConfig | null) => GridAggregationPosition | null;
42
75
  }
43
76
  export interface DataGridPremiumPropsWithoutDefaultValue<R extends GridValidRowModel = any> extends Omit<DataGridProPropsWithoutDefaultValue<R>, 'initialState' | 'apiRef'> {
44
77
  /**
@@ -61,4 +94,16 @@ export interface DataGridPremiumPropsWithoutDefaultValue<R extends GridValidRowM
61
94
  * @param {GridCallbackDetails} details Additional details for this callback.
62
95
  */
63
96
  onRowGroupingModelChange?: (model: GridRowGroupingModel, details: GridCallbackDetails) => void;
97
+ /**
98
+ * Set the aggregation model of the grid.
99
+ * @ignore - do not document.
100
+ */
101
+ private_aggregationModel?: GridAggregationModel;
102
+ /**
103
+ * Callback fired when the row grouping model changes.
104
+ * @param {GridAggregationModel} model The aggregated columns.
105
+ * @param {GridCallbackDetails} details Additional details for this callback.
106
+ * @ignore - do not document.
107
+ */
108
+ private_onAggregationModelChange?: (model: GridAggregationModel, details: GridCallbackDetails) => void;
64
109
  }
@@ -1,6 +1,6 @@
1
1
  import { GridApiCommon, GridStateApi, GridStatePersistenceApi, GridColumnPinningApi, GridDetailPanelApi } from '@mui/x-data-grid-pro';
2
2
  import { GridInitialStatePremium, GridStatePremium } from './gridStatePremium';
3
- import type { GridRowGroupingApi, GridExcelExportApi } from '../hooks';
3
+ import type { GridRowGroupingApi, GridExcelExportApi, GridAggregationApi } from '../hooks';
4
4
  declare type GridStateApiUntyped = {
5
5
  [key in keyof (GridStateApi<any> & GridStatePersistenceApi<any>)]: any;
6
6
  };
@@ -8,6 +8,6 @@ declare type GridStateApiUntyped = {
8
8
  * The api of `DataGridPremium`.
9
9
  * TODO: Do not redefine manually the pro features
10
10
  */
11
- export interface GridApiPremium extends Omit<GridApiCommon, keyof GridStateApiUntyped>, GridStateApi<GridStatePremium>, GridStatePersistenceApi<GridInitialStatePremium>, GridColumnPinningApi, GridDetailPanelApi, GridRowGroupingApi, GridExcelExportApi {
11
+ export interface GridApiPremium extends Omit<GridApiCommon, keyof GridStateApiUntyped>, GridStateApi<GridStatePremium>, GridStatePersistenceApi<GridInitialStatePremium>, GridColumnPinningApi, GridDetailPanelApi, GridRowGroupingApi, GridExcelExportApi, GridAggregationApi {
12
12
  }
13
13
  export {};
@@ -1,14 +1,16 @@
1
1
  import { GridInitialState as GridInitialStatePro, GridState as GridStatePro } from '@mui/x-data-grid-pro';
2
- import type { GridRowGroupingState, GridRowGroupingInitialState } from '../hooks';
2
+ import type { GridRowGroupingState, GridRowGroupingInitialState, GridAggregationState, GridAggregationInitialState } from '../hooks';
3
3
  /**
4
4
  * The state of `DataGridPremium`.
5
5
  */
6
6
  export interface GridStatePremium extends GridStatePro {
7
7
  rowGrouping: GridRowGroupingState;
8
+ private_aggregation: GridAggregationState;
8
9
  }
9
10
  /**
10
11
  * The initial state of `DataGridPremium`.
11
12
  */
12
13
  export interface GridInitialStatePremium extends GridInitialStatePro {
13
14
  rowGrouping?: GridRowGroupingInitialState;
15
+ private_aggregation?: GridAggregationInitialState;
14
16
  }
@@ -275,6 +275,7 @@ process.env.NODE_ENV !== "production" ? DataGridPremiumRaw.propTypes = {
275
275
  experimentalFeatures: PropTypes.shape({
276
276
  newEditingApi: PropTypes.bool,
277
277
  preventCommitWhileValidating: PropTypes.bool,
278
+ private_aggregation: PropTypes.bool,
278
279
  warnIfFocusStateIsNotSynced: PropTypes.bool
279
280
  }),
280
281
 
@@ -323,7 +324,7 @@ process.env.NODE_ENV !== "production" ? DataGridPremiumRaw.propTypes = {
323
324
  /**
324
325
  * Function that returns the height of the row detail panel.
325
326
  * @param {GridRowParams} params With all properties from [[GridRowParams]].
326
- * @returns {number} The height in pixels.
327
+ * @returns {number | string} The height in pixels or "auto" to use the content height.
327
328
  * @default "() => 500"
328
329
  */
329
330
  getDetailPanelHeight: PropTypes.func,
@@ -866,6 +867,52 @@ process.env.NODE_ENV !== "production" ? DataGridPremiumRaw.propTypes = {
866
867
  right: PropTypes.arrayOf(PropTypes.string)
867
868
  }),
868
869
 
870
+ /**
871
+ * Aggregation functions available on the grid.
872
+ * @default GRID_AGGREGATION_FUNCTIONS
873
+ * @ignore - do not document.
874
+ */
875
+ private_aggregationFunctions: PropTypes.object,
876
+
877
+ /**
878
+ * Set the aggregation model of the grid.
879
+ * @ignore - do not document.
880
+ */
881
+ private_aggregationModel: PropTypes.object,
882
+
883
+ /**
884
+ * Rows used to generate the aggregated value.
885
+ * If `filtered`, the aggregated values will be generated using only the rows currently passing the filtering process.
886
+ * If `all`, the aggregated values will be generated using all the rows.
887
+ * @default "filtered"
888
+ * @ignore - do not document.
889
+ */
890
+ private_aggregationRowsScope: PropTypes.oneOf(['all', 'filtered']),
891
+
892
+ /**
893
+ * If `true`, aggregation is disabled.
894
+ * @default false
895
+ * @ignore - do not document.
896
+ */
897
+ private_disableAggregation: PropTypes.bool,
898
+
899
+ /**
900
+ * Determines the position of an aggregated value.
901
+ * @param {GridRowTreeNodeConfig | null} groupNode The current group (`null` being the top level group).
902
+ * @returns {GridAggregationPosition | null} Position of the aggregated value (if `null`, the group will not be aggregated).
903
+ * @default `(groupNode) => groupNode == null ? 'footer' : 'inline'`
904
+ * @ignore - do not document.
905
+ */
906
+ private_getAggregationPosition: PropTypes.func,
907
+
908
+ /**
909
+ * Callback fired when the row grouping model changes.
910
+ * @param {GridAggregationModel} model The aggregated columns.
911
+ * @param {GridCallbackDetails} details Additional details for this callback.
912
+ * @ignore - do not document.
913
+ */
914
+ private_onAggregationModelChange: PropTypes.func,
915
+
869
916
  /**
870
917
  * Callback called before updating a row with new values in the row and cell editing.
871
918
  * Only applied if `props.experimentalFeatures.newEditingApi: true`.
@@ -1,5 +1,7 @@
1
1
  import { useGridInitialization, useGridInitializeState, useGridClipboard, useGridColumnMenu, useGridColumns, columnsStateInitializer, useGridDensity, useGridCsvExport, useGridPrintExport, useGridFilter, filterStateInitializer, useGridFocus, useGridKeyboardNavigation, useGridPagination, paginationStateInitializer, useGridPreferencesPanel, useGridEditing_new, useGridEditing_old, editingStateInitializer_old, editingStateInitializer_new, useGridRows, useGridRowsPreProcessors, rowsStateInitializer, useGridRowsMeta, useGridParamsApi, useGridSelection, useGridSorting, sortingStateInitializer, useGridScroll, useGridEvents, useGridDimensions, useGridStatePersistence, useGridSelectionPreProcessors, columnMenuStateInitializer, densityStateInitializer, focusStateInitializer, preferencePanelStateInitializer, rowsMetaStateInitializer, selectionStateInitializer, useGridColumnReorder, columnReorderStateInitializer, useGridColumnResize, columnResizeStateInitializer, useGridTreeData, useGridTreeDataPreProcessors, useGridColumnPinning, columnPinningStateInitializer, useGridColumnPinningPreProcessors, useGridDetailPanel, detailPanelStateInitializer, useGridDetailPanelPreProcessors, useGridInfiniteLoader, useGridColumnSpanning, useGridRowReorder, useGridRowReorderPreProcessors } from '@mui/x-data-grid-pro/internals';
2
2
  // Premium-only features
3
+ import { useGridAggregation, aggregationStateInitializer } from '../hooks/features/aggregation/useGridAggregation';
4
+ import { useGridAggregationPreProcessors } from '../hooks/features/aggregation/useGridAggregationPreProcessors';
3
5
  import { useGridRowGrouping, rowGroupingStateInitializer } from '../hooks/features/rowGrouping/useGridRowGrouping';
4
6
  import { useGridRowGroupingPreProcessors } from '../hooks/features/rowGrouping/useGridRowGroupingPreProcessors';
5
7
  import { useGridExcelExport } from '../hooks/features/export/useGridExcelExport';
@@ -13,6 +15,7 @@ export const useDataGridPremiumComponent = (inputApiRef, props) => {
13
15
  useGridRowReorderPreProcessors(apiRef, props);
14
16
  useGridRowGroupingPreProcessors(apiRef, props);
15
17
  useGridTreeDataPreProcessors(apiRef, props);
18
+ useGridAggregationPreProcessors(apiRef, props);
16
19
  useGridDetailPanelPreProcessors(apiRef, props); // The column pinning `hydrateColumns` pre-processor must be after every other `hydrateColumns` pre-processors
17
20
  // Because it changes the order of the columns.
18
21
 
@@ -23,6 +26,7 @@ export const useDataGridPremiumComponent = (inputApiRef, props) => {
23
26
  */
24
27
 
25
28
  useGridInitializeState(rowGroupingStateInitializer, apiRef, props);
29
+ useGridInitializeState(aggregationStateInitializer, apiRef, props);
26
30
  useGridInitializeState(selectionStateInitializer, apiRef, props);
27
31
  useGridInitializeState(detailPanelStateInitializer, apiRef, props);
28
32
  useGridInitializeState(columnPinningStateInitializer, apiRef, props);
@@ -41,6 +45,7 @@ export const useDataGridPremiumComponent = (inputApiRef, props) => {
41
45
  useGridInitializeState(columnMenuStateInitializer, apiRef, props);
42
46
  useGridRowGrouping(apiRef, props);
43
47
  useGridTreeData(apiRef);
48
+ useGridAggregation(apiRef, props);
44
49
  useGridKeyboardNavigation(apiRef, props);
45
50
  useGridSelection(apiRef, props);
46
51
  useGridColumnPinning(apiRef, props);
@@ -52,7 +57,7 @@ export const useDataGridPremiumComponent = (inputApiRef, props) => {
52
57
  const useGridEditing = props.experimentalFeatures?.newEditingApi ? useGridEditing_new : useGridEditing_old;
53
58
  useGridEditing(apiRef, props);
54
59
  useGridFocus(apiRef, props);
55
- useGridPreferencesPanel(apiRef);
60
+ useGridPreferencesPanel(apiRef, props);
56
61
  useGridFilter(apiRef, props);
57
62
  useGridSorting(apiRef, props);
58
63
  useGridDensity(apiRef, props);
@@ -2,13 +2,18 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import { useThemeProps } from '@mui/material/styles';
4
4
  import { DATA_GRID_PRO_PROPS_DEFAULT_VALUES, DATA_GRID_DEFAULT_SLOTS_COMPONENTS, GRID_DEFAULT_LOCALE_TEXT } from '@mui/x-data-grid-pro';
5
-
5
+ import { PRIVATE_GRID_AGGREGATION_FUNCTIONS } from '../hooks/features/aggregation';
6
6
  /**
7
7
  * The default values of `DataGridPremiumPropsWithDefaultValue` to inject in the props of DataGridPremium.
8
8
  */
9
+
9
10
  export const DATA_GRID_PREMIUM_PROPS_DEFAULT_VALUES = _extends({}, DATA_GRID_PRO_PROPS_DEFAULT_VALUES, {
11
+ private_disableAggregation: false,
10
12
  disableRowGrouping: false,
11
- rowGroupingColumnMode: 'single'
13
+ rowGroupingColumnMode: 'single',
14
+ private_aggregationFunctions: PRIVATE_GRID_AGGREGATION_FUNCTIONS,
15
+ private_aggregationRowsScope: 'filtered',
16
+ private_getAggregationPosition: groupNode => groupNode == null ? 'footer' : 'inline'
12
17
  });
13
18
  export const useDataGridPremiumProps = inProps => {
14
19
  const themedProps = useThemeProps({
@@ -30,6 +35,7 @@ export const useDataGridPremiumProps = inProps => {
30
35
  return mergedComponents;
31
36
  }, [themedProps.components]);
32
37
  return React.useMemo(() => _extends({}, DATA_GRID_PREMIUM_PROPS_DEFAULT_VALUES, themedProps, {
38
+ private_disableAggregation: themedProps.private_disableAggregation || !themedProps.experimentalFeatures?.private_aggregation,
33
39
  localeText,
34
40
  components,
35
41
  signature: 'DataGridPremium'
@@ -0,0 +1,93 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ import _toPropertyKey from "@babel/runtime/helpers/esm/toPropertyKey";
4
+ import * as React from 'react';
5
+ import { useGridSelector } from '@mui/x-data-grid-pro';
6
+ import MenuItem from '@mui/material/MenuItem';
7
+ import FormControl from '@mui/material/FormControl';
8
+ import InputLabel from '@mui/material/InputLabel';
9
+ import { unstable_useId as useId } from '@mui/material/utils';
10
+ import Select from '@mui/material/Select';
11
+ import { useGridApiContext } from '../hooks/utils/useGridApiContext';
12
+ import { useGridRootProps } from '../hooks/utils/useGridRootProps';
13
+ import { canColumnHaveAggregationFunction, getAggregationFunctionLabel } from '../hooks/features/aggregation/gridAggregationUtils';
14
+ import { gridAggregationModelSelector } from '../hooks/features/aggregation/gridAggregationSelectors';
15
+ import { jsx as _jsx } from "react/jsx-runtime";
16
+ import { jsxs as _jsxs } from "react/jsx-runtime";
17
+ export const GridAggregationColumnMenuItem = props => {
18
+ const {
19
+ column,
20
+ label,
21
+ availableAggregationFunctions
22
+ } = props;
23
+ const apiRef = useGridApiContext();
24
+ const rootProps = useGridRootProps();
25
+ const id = useId();
26
+ const aggregationModel = useGridSelector(apiRef, gridAggregationModelSelector);
27
+ const selectedAggregationRule = React.useMemo(() => {
28
+ if (!column || !aggregationModel[column.field]) {
29
+ return '';
30
+ }
31
+
32
+ const aggregationFunctionName = aggregationModel[column.field];
33
+
34
+ if (canColumnHaveAggregationFunction({
35
+ column,
36
+ aggregationFunctionName,
37
+ aggregationFunction: rootProps.private_aggregationFunctions[aggregationFunctionName]
38
+ })) {
39
+ return aggregationFunctionName;
40
+ }
41
+
42
+ return '';
43
+ }, [rootProps.private_aggregationFunctions, aggregationModel, column]);
44
+
45
+ const handleAggregationItemChange = event => {
46
+ const newAggregationItem = event.target.value || undefined;
47
+ const currentModel = gridAggregationModelSelector(apiRef);
48
+
49
+ const _column$field = column.field,
50
+ otherColumnItems = _objectWithoutPropertiesLoose(currentModel, [_column$field].map(_toPropertyKey));
51
+
52
+ const newModel = newAggregationItem == null ? otherColumnItems : _extends({}, otherColumnItems, {
53
+ [column.field]: newAggregationItem
54
+ });
55
+ apiRef.current.private_setAggregationModel(newModel);
56
+ apiRef.current.hideColumnMenu();
57
+ };
58
+
59
+ return /*#__PURE__*/_jsx(MenuItem, {
60
+ disableRipple: true,
61
+ children: /*#__PURE__*/_jsxs(FormControl, {
62
+ size: "small",
63
+ sx: {
64
+ width: 150
65
+ },
66
+ children: [/*#__PURE__*/_jsx(InputLabel, {
67
+ id: `${id}-label`,
68
+ children: label
69
+ }), /*#__PURE__*/_jsxs(Select, {
70
+ labelId: `${id}-label`,
71
+ id: `${id}-input`,
72
+ value: selectedAggregationRule,
73
+ label: label,
74
+ onChange: handleAggregationItemChange,
75
+ onBlur: e => e.stopPropagation(),
76
+ fullWidth: true,
77
+ children: [/*#__PURE__*/_jsx(MenuItem, {
78
+ value: "",
79
+ children: "..."
80
+ }), availableAggregationFunctions.map(aggFunc => /*#__PURE__*/_jsx(MenuItem, {
81
+ value: aggFunc,
82
+ children: getAggregationFunctionLabel({
83
+ apiRef,
84
+ aggregationRule: {
85
+ aggregationFunctionName: aggFunc,
86
+ aggregationFunction: rootProps.private_aggregationFunctions[aggFunc]
87
+ }
88
+ })
89
+ }, aggFunc))]
90
+ })]
91
+ })
92
+ });
93
+ };
@@ -0,0 +1,92 @@
1
+ import * as React from 'react';
2
+ import { unstable_composeClasses as composeClasses } from '@mui/material';
3
+ import Box from '@mui/material/Box';
4
+ import { styled } from '@mui/material/styles';
5
+ import { getDataGridUtilityClass, gridClasses, GridColumnHeaderTitle, gridDensityHeaderHeightSelector, useGridSelector } from '@mui/x-data-grid';
6
+ import { getAggregationFunctionLabel } from '../hooks/features/aggregation/gridAggregationUtils';
7
+ import { useGridApiContext } from '../hooks/utils/useGridApiContext';
8
+ import { useGridRootProps } from '../hooks/utils/useGridRootProps';
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ import { jsxs as _jsxs } from "react/jsx-runtime";
11
+ const GridAggregationHeaderRoot = styled(Box, {
12
+ name: 'MuiDataGrid',
13
+ slot: 'AggregationColumnHeader',
14
+ overridesResolver: (_, styles) => styles.aggregationColumnHeader
15
+ })({
16
+ display: 'flex',
17
+ flexDirection: 'column',
18
+ [`&.${gridClasses['aggregationColumnHeader--alignRight']}`]: {
19
+ alignItems: 'flex-end'
20
+ },
21
+ [`&.${gridClasses['aggregationColumnHeader--alignCenter']}`]: {
22
+ alignItems: 'center'
23
+ }
24
+ });
25
+ const GridAggregationFunctionLabel = styled('div', {
26
+ name: 'MuiDataGrid',
27
+ slot: 'AggregationColumnHeaderLabel',
28
+ overridesResolver: (_, styles) => styles.aggregationColumnHeaderLabel
29
+ })(({
30
+ theme
31
+ }) => {
32
+ return {
33
+ fontSize: theme.typography.caption.fontSize,
34
+ lineHeight: theme.typography.caption.fontSize,
35
+ marginTop: `calc(-2px - ${theme.typography.caption.fontSize})`,
36
+ fontWeight: theme.typography.fontWeightMedium,
37
+ color: theme.palette.primary.dark,
38
+ textTransform: 'uppercase'
39
+ };
40
+ });
41
+
42
+ const useUtilityClasses = ownerState => {
43
+ const {
44
+ classes,
45
+ colDef
46
+ } = ownerState;
47
+ const slots = {
48
+ root: ['aggregationColumnHeader', colDef.headerAlign === 'left' && 'aggregationColumnHeader--alignLeft', colDef.headerAlign === 'center' && 'aggregationColumnHeader--alignCenter', colDef.headerAlign === 'right' && 'aggregationColumnHeader--alignRight'],
49
+ aggregationLabel: ['aggregationColumnHeaderLabel']
50
+ };
51
+ return composeClasses(slots, getDataGridUtilityClass, classes);
52
+ };
53
+
54
+ const GridAggregationHeader = props => {
55
+ const {
56
+ colDef,
57
+ aggregation
58
+ } = props;
59
+ const apiRef = useGridApiContext();
60
+ const rootProps = useGridRootProps();
61
+ const headerHeight = useGridSelector(apiRef, gridDensityHeaderHeightSelector);
62
+ const ownerState = {
63
+ classes: rootProps.classes,
64
+ headerHeight,
65
+ colDef
66
+ };
67
+ const classes = useUtilityClasses(ownerState);
68
+
69
+ if (!aggregation) {
70
+ return null;
71
+ }
72
+
73
+ const aggregationLabel = getAggregationFunctionLabel({
74
+ apiRef,
75
+ aggregationRule: aggregation.aggregationRule
76
+ });
77
+ return /*#__PURE__*/_jsxs(GridAggregationHeaderRoot, {
78
+ ownerState: ownerState,
79
+ className: classes.root,
80
+ children: [/*#__PURE__*/_jsx(GridColumnHeaderTitle, {
81
+ label: colDef.headerName ?? colDef.field,
82
+ description: colDef.description,
83
+ columnWidth: colDef.computedWidth
84
+ }), /*#__PURE__*/_jsx(GridAggregationFunctionLabel, {
85
+ ownerState: ownerState,
86
+ className: classes.aggregationLabel,
87
+ children: aggregationLabel
88
+ })]
89
+ });
90
+ };
91
+
92
+ export { GridAggregationHeader };
@@ -1,3 +1,6 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["hideMenu", "options"];
1
4
  import * as React from 'react';
2
5
  import PropTypes from 'prop-types';
3
6
  import MenuItem from '@mui/material/MenuItem';
@@ -6,17 +9,21 @@ import { jsx as _jsx } from "react/jsx-runtime";
6
9
 
7
10
  const GridExcelExportMenuItem = props => {
8
11
  const apiRef = useGridApiContext();
12
+
9
13
  const {
10
14
  hideMenu,
11
15
  options
12
- } = props;
13
- return /*#__PURE__*/_jsx(MenuItem, {
16
+ } = props,
17
+ other = _objectWithoutPropertiesLoose(props, _excluded);
18
+
19
+ return /*#__PURE__*/_jsx(MenuItem, _extends({
14
20
  onClick: () => {
15
21
  apiRef.current.exportDataAsExcel(options);
16
22
  hideMenu?.();
17
- },
23
+ }
24
+ }, other, {
18
25
  children: apiRef.current.getLocaleText('toolbarExportExcel')
19
- });
26
+ }));
20
27
  };
21
28
 
22
29
  process.env.NODE_ENV !== "production" ? GridExcelExportMenuItem.propTypes = {