@mui/x-data-grid-premium 8.0.0-alpha.1 → 8.0.0-alpha.11

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 (119) hide show
  1. package/CHANGELOG.md +2007 -230
  2. package/DataGridPremium/DataGridPremium.js +41 -40
  3. package/DataGridPremium/useDataGridPremiumComponent.d.ts +2 -2
  4. package/DataGridPremium/useDataGridPremiumComponent.js +6 -4
  5. package/DataGridPremium/useDataGridPremiumProps.js +5 -3
  6. package/README.md +1 -1
  7. package/components/GridAggregationHeader.js +6 -1
  8. package/components/GridColumnMenuAggregationItem.js +77 -49
  9. package/components/GridColumnMenuRowGroupItem.js +5 -11
  10. package/components/GridColumnMenuRowUngroupItem.js +10 -19
  11. package/components/GridDataSourceGroupingCriteriaCell.js +1 -2
  12. package/components/GridPremiumColumnMenu.d.ts +1 -1
  13. package/components/GridPremiumColumnMenu.js +5 -5
  14. package/components/promptControl/GridToolbarPromptControl.js +47 -36
  15. package/esm/DataGridPremium/DataGridPremium.js +43 -42
  16. package/esm/DataGridPremium/useDataGridPremiumComponent.js +7 -5
  17. package/esm/DataGridPremium/useDataGridPremiumProps.js +6 -4
  18. package/esm/components/GridAggregationHeader.js +6 -1
  19. package/esm/components/GridColumnMenuAggregationItem.js +75 -47
  20. package/esm/components/GridColumnMenuRowGroupItem.js +6 -11
  21. package/esm/components/GridColumnMenuRowUngroupItem.js +11 -19
  22. package/esm/components/GridDataSourceGroupingCriteriaCell.js +1 -2
  23. package/esm/components/GridPremiumColumnMenu.js +5 -5
  24. package/esm/components/promptControl/GridToolbarPromptControl.js +47 -36
  25. package/esm/hooks/features/aggregation/createAggregationLookup.js +52 -55
  26. package/esm/hooks/features/aggregation/gridAggregationUtils.js +18 -14
  27. package/esm/hooks/features/aggregation/index.js +0 -1
  28. package/esm/hooks/features/aggregation/useGridAggregation.js +22 -12
  29. package/esm/hooks/features/aggregation/useGridAggregationPreProcessors.js +8 -14
  30. package/esm/hooks/features/cellSelection/useGridCellSelection.js +17 -15
  31. package/esm/hooks/features/clipboard/useGridClipboardImport.js +1 -1
  32. package/esm/hooks/features/dataSource/cache.js +3 -0
  33. package/esm/hooks/features/dataSource/models.js +1 -0
  34. package/esm/hooks/features/dataSource/useGridDataSourcePremium.js +53 -0
  35. package/esm/hooks/features/rowGrouping/createGroupingColDef.js +5 -1
  36. package/esm/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -3
  37. package/esm/hooks/features/rowGrouping/useGridRowGrouping.js +2 -2
  38. package/esm/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +9 -4
  39. package/esm/hooks/utils/useGridAriaAttributes.js +1 -3
  40. package/esm/hooks/utils/useKeepGroupedColumnsHidden.js +2 -2
  41. package/esm/utils/releaseInfo.js +1 -1
  42. package/hooks/features/aggregation/createAggregationLookup.d.ts +7 -6
  43. package/hooks/features/aggregation/createAggregationLookup.js +52 -55
  44. package/hooks/features/aggregation/gridAggregationInterfaces.d.ts +18 -5
  45. package/hooks/features/aggregation/gridAggregationSelectors.d.ts +2 -2
  46. package/hooks/features/aggregation/gridAggregationUtils.d.ts +12 -13
  47. package/hooks/features/aggregation/gridAggregationUtils.js +18 -14
  48. package/hooks/features/aggregation/index.d.ts +1 -1
  49. package/hooks/features/aggregation/index.js +0 -12
  50. package/hooks/features/aggregation/useGridAggregation.d.ts +2 -2
  51. package/hooks/features/aggregation/useGridAggregation.js +22 -12
  52. package/hooks/features/aggregation/useGridAggregationPreProcessors.d.ts +2 -2
  53. package/hooks/features/aggregation/useGridAggregationPreProcessors.js +8 -14
  54. package/hooks/features/aggregation/wrapColumnWithAggregation.d.ts +3 -2
  55. package/hooks/features/cellSelection/gridCellSelectionInterfaces.d.ts +3 -3
  56. package/hooks/features/cellSelection/useGridCellSelection.d.ts +2 -2
  57. package/hooks/features/cellSelection/useGridCellSelection.js +15 -13
  58. package/hooks/features/clipboard/useGridClipboardImport.d.ts +2 -2
  59. package/hooks/features/clipboard/useGridClipboardImport.js +1 -1
  60. package/hooks/features/dataSource/cache.d.ts +2 -0
  61. package/hooks/features/dataSource/cache.js +9 -0
  62. package/hooks/features/dataSource/models.d.ts +47 -0
  63. package/hooks/features/dataSource/models.js +5 -0
  64. package/hooks/features/dataSource/useGridDataSourcePremium.d.ts +4 -0
  65. package/hooks/features/dataSource/useGridDataSourcePremium.js +62 -0
  66. package/hooks/features/export/serializer/excelSerializer.d.ts +3 -2
  67. package/hooks/features/export/useGridExcelExport.d.ts +2 -2
  68. package/hooks/features/rowGrouping/createGroupingColDef.d.ts +2 -2
  69. package/hooks/features/rowGrouping/createGroupingColDef.js +5 -1
  70. package/hooks/features/rowGrouping/gridRowGroupingSelector.d.ts +2 -2
  71. package/hooks/features/rowGrouping/gridRowGroupingUtils.d.ts +4 -4
  72. package/hooks/features/rowGrouping/gridRowGroupingUtils.js +4 -2
  73. package/hooks/features/rowGrouping/useGridDataSourceRowGroupingPreProcessors.d.ts +2 -2
  74. package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +2 -2
  75. package/hooks/features/rowGrouping/useGridRowGrouping.js +1 -1
  76. package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.d.ts +2 -2
  77. package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +9 -4
  78. package/hooks/utils/useGridApiContext.d.ts +3 -1
  79. package/hooks/utils/useGridApiRef.d.ts +3 -1
  80. package/hooks/utils/useGridAriaAttributes.js +1 -3
  81. package/hooks/utils/useGridPrivateApiContext.d.ts +1 -1
  82. package/hooks/utils/useKeepGroupedColumnsHidden.d.ts +2 -2
  83. package/hooks/utils/useKeepGroupedColumnsHidden.js +2 -2
  84. package/index.d.ts +2 -0
  85. package/index.js +1 -1
  86. package/models/dataGridPremiumProps.d.ts +8 -12
  87. package/models/gridApiPremium.d.ts +5 -3
  88. package/models/gridGroupingValueGetter.d.ts +2 -1
  89. package/models/gridPastedValueParser.d.ts +2 -1
  90. package/modern/DataGridPremium/DataGridPremium.js +43 -42
  91. package/modern/DataGridPremium/useDataGridPremiumComponent.js +7 -5
  92. package/modern/DataGridPremium/useDataGridPremiumProps.js +6 -4
  93. package/modern/components/GridAggregationHeader.js +6 -1
  94. package/modern/components/GridColumnMenuAggregationItem.js +75 -47
  95. package/modern/components/GridColumnMenuRowGroupItem.js +6 -11
  96. package/modern/components/GridColumnMenuRowUngroupItem.js +11 -19
  97. package/modern/components/GridDataSourceGroupingCriteriaCell.js +1 -2
  98. package/modern/components/GridPremiumColumnMenu.js +5 -5
  99. package/modern/components/promptControl/GridToolbarPromptControl.js +47 -36
  100. package/modern/hooks/features/aggregation/createAggregationLookup.js +52 -55
  101. package/modern/hooks/features/aggregation/gridAggregationUtils.js +18 -14
  102. package/modern/hooks/features/aggregation/index.js +0 -1
  103. package/modern/hooks/features/aggregation/useGridAggregation.js +22 -12
  104. package/modern/hooks/features/aggregation/useGridAggregationPreProcessors.js +8 -14
  105. package/modern/hooks/features/cellSelection/useGridCellSelection.js +17 -15
  106. package/modern/hooks/features/clipboard/useGridClipboardImport.js +1 -1
  107. package/modern/hooks/features/dataSource/cache.js +3 -0
  108. package/modern/hooks/features/dataSource/models.js +1 -0
  109. package/modern/hooks/features/dataSource/useGridDataSourcePremium.js +53 -0
  110. package/modern/hooks/features/rowGrouping/createGroupingColDef.js +5 -1
  111. package/modern/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -3
  112. package/modern/hooks/features/rowGrouping/useGridRowGrouping.js +2 -2
  113. package/modern/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +9 -4
  114. package/modern/hooks/utils/useGridAriaAttributes.js +1 -3
  115. package/modern/hooks/utils/useKeepGroupedColumnsHidden.js +2 -2
  116. package/modern/index.js +1 -1
  117. package/modern/utils/releaseInfo.js +1 -1
  118. package/package.json +6 -6
  119. package/utils/releaseInfo.js +1 -1
@@ -1,18 +1,13 @@
1
1
  import { gridColumnLookupSelector, gridFilteredRowsLookupSelector, gridRowTreeSelector, GRID_ROOT_GROUP_ID } from '@mui/x-data-grid-pro';
2
2
  import { getAggregationRules } from "./gridAggregationUtils.js";
3
3
  import { gridAggregationModelSelector } from "./gridAggregationSelectors.js";
4
- const getAggregationCellValue = ({
5
- apiRef,
6
- groupId,
7
- field,
8
- aggregationFunction,
9
- aggregationRowsScope
10
- }) => {
11
- const filteredRowsLookup = gridFilteredRowsLookupSelector(apiRef);
4
+ const getGroupAggregatedValue = (groupId, apiRef, aggregationRowsScope, aggregatedFields, aggregationRules, position) => {
5
+ const groupAggregationLookup = {};
6
+ const aggregatedValues = [];
12
7
  const rowIds = apiRef.current.getRowGroupChildren({
13
8
  groupId
14
9
  });
15
- const values = [];
10
+ const filteredRowsLookup = gridFilteredRowsLookupSelector(apiRef);
16
11
  rowIds.forEach(rowId => {
17
12
  if (aggregationRowsScope === 'filtered' && filteredRowsLookup[rowId] === false) {
18
13
  return;
@@ -29,42 +24,53 @@ const getAggregationCellValue = ({
29
24
  if (rowNode.type === 'group') {
30
25
  return;
31
26
  }
32
- if (typeof aggregationFunction.getCellValue === 'function') {
33
- const row = apiRef.current.getRow(rowId);
34
- values.push(aggregationFunction.getCellValue({
35
- row
36
- }));
37
- } else {
38
- values.push(apiRef.current.getCellValue(rowId, field));
27
+ const row = apiRef.current.getRow(rowId);
28
+ for (let j = 0; j < aggregatedFields.length; j += 1) {
29
+ const aggregatedField = aggregatedFields[j];
30
+ const columnAggregationRules = aggregationRules[aggregatedField];
31
+ const aggregationFunction = columnAggregationRules.aggregationFunction;
32
+ const field = aggregatedField;
33
+ if (aggregatedValues[j] === undefined) {
34
+ aggregatedValues[j] = {
35
+ aggregatedField,
36
+ values: []
37
+ };
38
+ }
39
+ if (typeof aggregationFunction.getCellValue === 'function') {
40
+ aggregatedValues[j].values.push(aggregationFunction.getCellValue({
41
+ row
42
+ }));
43
+ } else {
44
+ const colDef = apiRef.current.getColumn(field);
45
+ aggregatedValues[j].values.push(apiRef.current.getRowValue(row, colDef));
46
+ }
39
47
  }
40
48
  });
41
- return aggregationFunction.apply({
42
- values,
43
- groupId,
44
- field // Added per user request in https://github.com/mui/mui-x/issues/6995#issuecomment-1327423455
45
- });
49
+ for (let i = 0; i < aggregatedValues.length; i += 1) {
50
+ const {
51
+ aggregatedField,
52
+ values
53
+ } = aggregatedValues[i];
54
+ const aggregationFunction = aggregationRules[aggregatedField].aggregationFunction;
55
+ const value = aggregationFunction.apply({
56
+ values,
57
+ groupId,
58
+ field: aggregatedField // Added per user request in https://github.com/mui/mui-x/issues/6995#issuecomment-1327423455
59
+ });
60
+ groupAggregationLookup[aggregatedField] = {
61
+ position,
62
+ value
63
+ };
64
+ }
65
+ return groupAggregationLookup;
46
66
  };
47
- const getGroupAggregatedValue = ({
48
- groupId,
49
- apiRef,
50
- aggregationRowsScope,
51
- aggregatedFields,
52
- aggregationRules,
53
- position
54
- }) => {
67
+ const getGroupAggregatedValueDataSource = (groupId, apiRef, aggregatedFields, position) => {
55
68
  const groupAggregationLookup = {};
56
69
  for (let j = 0; j < aggregatedFields.length; j += 1) {
57
70
  const aggregatedField = aggregatedFields[j];
58
- const columnAggregationRules = aggregationRules[aggregatedField];
59
71
  groupAggregationLookup[aggregatedField] = {
60
72
  position,
61
- value: getAggregationCellValue({
62
- apiRef,
63
- groupId,
64
- field: aggregatedField,
65
- aggregationFunction: columnAggregationRules.aggregationFunction,
66
- aggregationRowsScope
67
- })
73
+ value: apiRef.current.resolveGroupAggregation(groupId, aggregatedField)
68
74
  };
69
75
  }
70
76
  return groupAggregationLookup;
@@ -73,13 +79,10 @@ export const createAggregationLookup = ({
73
79
  apiRef,
74
80
  aggregationFunctions,
75
81
  aggregationRowsScope,
76
- getAggregationPosition
82
+ getAggregationPosition,
83
+ isDataSource
77
84
  }) => {
78
- const aggregationRules = getAggregationRules({
79
- columnsLookup: gridColumnLookupSelector(apiRef),
80
- aggregationModel: gridAggregationModelSelector(apiRef),
81
- aggregationFunctions
82
- });
85
+ const aggregationRules = getAggregationRules(gridColumnLookupSelector(apiRef), gridAggregationModelSelector(apiRef), aggregationFunctions, isDataSource);
83
86
  const aggregatedFields = Object.keys(aggregationRules);
84
87
  if (aggregatedFields.length === 0) {
85
88
  return {};
@@ -94,18 +97,12 @@ export const createAggregationLookup = ({
94
97
  createGroupAggregationLookup(childNode);
95
98
  }
96
99
  }
97
- const hasAggregableChildren = groupNode.children.length;
98
- if (hasAggregableChildren) {
99
- const position = getAggregationPosition(groupNode);
100
- if (position != null) {
101
- aggregationLookup[groupNode.id] = getGroupAggregatedValue({
102
- groupId: groupNode.id,
103
- apiRef,
104
- aggregatedFields,
105
- aggregationRowsScope,
106
- aggregationRules,
107
- position
108
- });
100
+ const position = getAggregationPosition(groupNode);
101
+ if (position !== null) {
102
+ if (isDataSource) {
103
+ aggregationLookup[groupNode.id] = getGroupAggregatedValueDataSource(groupNode.id, apiRef, aggregatedFields, position);
104
+ } else if (groupNode.children.length) {
105
+ aggregationLookup[groupNode.id] = getGroupAggregatedValue(groupNode.id, apiRef, aggregationRowsScope, aggregatedFields, aggregationRules, position);
109
106
  }
110
107
  }
111
108
  };
@@ -10,56 +10,60 @@ export const getAggregationFooterRowIdFromGroupId = groupId => {
10
10
  }
11
11
  return `auto-generated-group-footer-${groupId}`;
12
12
  };
13
+ const isClientSideAggregateFunction = aggregationFunction => !!aggregationFunction && 'apply' in aggregationFunction;
13
14
  export const canColumnHaveAggregationFunction = ({
14
15
  colDef,
15
16
  aggregationFunctionName,
16
- aggregationFunction
17
+ aggregationFunction,
18
+ isDataSource
17
19
  }) => {
18
20
  if (!colDef) {
19
21
  return false;
20
22
  }
21
- if (!aggregationFunction) {
23
+ if (!isClientSideAggregateFunction(aggregationFunction) && !isDataSource) {
22
24
  return false;
23
25
  }
24
26
  if (colDef.availableAggregationFunctions != null) {
25
27
  return colDef.availableAggregationFunctions.includes(aggregationFunctionName);
26
28
  }
27
- if (!aggregationFunction.columnTypes) {
29
+ if (!aggregationFunction?.columnTypes) {
28
30
  return true;
29
31
  }
30
32
  return aggregationFunction.columnTypes.includes(colDef.type);
31
33
  };
32
34
  export const getAvailableAggregationFunctions = ({
33
35
  aggregationFunctions,
34
- colDef
36
+ colDef,
37
+ isDataSource
35
38
  }) => Object.keys(aggregationFunctions).filter(aggregationFunctionName => canColumnHaveAggregationFunction({
36
39
  colDef,
37
40
  aggregationFunctionName,
38
- aggregationFunction: aggregationFunctions[aggregationFunctionName]
41
+ aggregationFunction: aggregationFunctions[aggregationFunctionName],
42
+ isDataSource
39
43
  }));
40
44
  export const mergeStateWithAggregationModel = aggregationModel => state => _extends({}, state, {
41
45
  aggregation: _extends({}, state.aggregation, {
42
46
  model: aggregationModel
43
47
  })
44
48
  });
45
- export const getAggregationRules = ({
46
- columnsLookup,
47
- aggregationModel,
48
- aggregationFunctions
49
- }) => {
49
+ export const getAggregationRules = (columnsLookup, aggregationModel, aggregationFunctions, isDataSource) => {
50
50
  const aggregationRules = {};
51
- Object.entries(aggregationModel).forEach(([field, columnItem]) => {
51
+
52
+ // eslint-disable-next-line guard-for-in
53
+ for (const field in aggregationModel) {
54
+ const columnItem = aggregationModel[field];
52
55
  if (columnsLookup[field] && canColumnHaveAggregationFunction({
53
56
  colDef: columnsLookup[field],
54
57
  aggregationFunctionName: columnItem,
55
- aggregationFunction: aggregationFunctions[columnItem]
58
+ aggregationFunction: aggregationFunctions[columnItem],
59
+ isDataSource
56
60
  })) {
57
61
  aggregationRules[field] = {
58
62
  aggregationFunctionName: columnItem,
59
63
  aggregationFunction: aggregationFunctions[columnItem]
60
64
  };
61
65
  }
62
- });
66
+ }
63
67
  return aggregationRules;
64
68
  };
65
69
  /**
@@ -107,7 +111,7 @@ export const addFooterRows = ({
107
111
  }
108
112
  };
109
113
  const updateRootGroupFooter = groupNode => {
110
- const shouldHaveFooter = hasAggregationRule && getAggregationPosition(groupNode) === 'footer';
114
+ const shouldHaveFooter = hasAggregationRule && getAggregationPosition(groupNode) === 'footer' && groupNode.children.length > 0;
111
115
  if (shouldHaveFooter) {
112
116
  const rowId = getAggregationFooterRowIdFromGroupId(null);
113
117
  newGroupingParams = addPinnedRow({
@@ -1,4 +1,3 @@
1
- export * from "./gridAggregationInterfaces.js";
2
1
  export * from "./gridAggregationSelectors.js";
3
2
  export * from "./gridAggregationFunctions.js";
4
3
  export { GRID_AGGREGATION_ROOT_FOOTER_ROW_ID, getAggregationFooterRowIdFromGroupId } from "./gridAggregationUtils.js";
@@ -1,6 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import { gridColumnLookupSelector, useGridApiEventHandler, useGridApiMethod } from '@mui/x-data-grid-pro';
4
+ import { useGridRegisterPipeProcessor } from '@mui/x-data-grid-pro/internals';
4
5
  import { gridAggregationModelSelector } from "./gridAggregationSelectors.js";
5
6
  import { getAggregationRules, mergeStateWithAggregationModel, areAggregationRulesEqual } from "./gridAggregationUtils.js";
6
7
  import { createAggregationLookup } from "./createAggregationLookup.js";
@@ -31,7 +32,6 @@ export const useGridAggregation = (apiRef, props) => {
31
32
  const currentModel = gridAggregationModelSelector(apiRef);
32
33
  if (currentModel !== model) {
33
34
  apiRef.current.setState(mergeStateWithAggregationModel(model));
34
- apiRef.current.forceUpdate();
35
35
  }
36
36
  }, [apiRef]);
37
37
  const applyAggregation = React.useCallback(() => {
@@ -39,18 +39,29 @@ export const useGridAggregation = (apiRef, props) => {
39
39
  apiRef,
40
40
  getAggregationPosition: props.getAggregationPosition,
41
41
  aggregationFunctions: props.aggregationFunctions,
42
- aggregationRowsScope: props.aggregationRowsScope
42
+ aggregationRowsScope: props.aggregationRowsScope,
43
+ isDataSource: !!props.unstable_dataSource
43
44
  });
44
45
  apiRef.current.setState(state => _extends({}, state, {
45
46
  aggregation: _extends({}, state.aggregation, {
46
47
  lookup: aggregationLookup
47
48
  })
48
49
  }));
49
- }, [apiRef, props.getAggregationPosition, props.aggregationFunctions, props.aggregationRowsScope]);
50
+ }, [apiRef, props.getAggregationPosition, props.aggregationFunctions, props.aggregationRowsScope, props.unstable_dataSource]);
50
51
  const aggregationApi = {
51
52
  setAggregationModel
52
53
  };
54
+ const aggregationPrivateApi = {
55
+ applyAggregation
56
+ };
53
57
  useGridApiMethod(apiRef, aggregationApi, 'public');
58
+ useGridApiMethod(apiRef, aggregationPrivateApi, 'private');
59
+ const addGetRowsParams = React.useCallback(params => {
60
+ return _extends({}, params, {
61
+ aggregationModel: gridAggregationModelSelector(apiRef)
62
+ });
63
+ }, [apiRef]);
64
+ useGridRegisterPipeProcessor(apiRef, 'getRowsParams', addGetRowsParams);
54
65
 
55
66
  /**
56
67
  * EVENTS
@@ -60,24 +71,23 @@ export const useGridAggregation = (apiRef, props) => {
60
71
  rulesOnLastRowHydration,
61
72
  rulesOnLastColumnHydration
62
73
  } = apiRef.current.caches.aggregation;
63
- const aggregationRules = props.disableAggregation ? {} : getAggregationRules({
64
- columnsLookup: gridColumnLookupSelector(apiRef),
65
- aggregationModel: gridAggregationModelSelector(apiRef),
66
- aggregationFunctions: props.aggregationFunctions
67
- });
74
+ const aggregationRules = props.disableAggregation ? {} : getAggregationRules(gridColumnLookupSelector(apiRef), gridAggregationModelSelector(apiRef), props.aggregationFunctions, !!props.unstable_dataSource);
68
75
 
69
76
  // Re-apply the row hydration to add / remove the aggregation footers
70
77
  if (!areAggregationRulesEqual(rulesOnLastRowHydration, aggregationRules)) {
71
- apiRef.current.requestPipeProcessorsApplication('hydrateRows');
72
- applyAggregation();
78
+ if (props.unstable_dataSource) {
79
+ apiRef.current.unstable_dataSource.fetchRows();
80
+ } else {
81
+ apiRef.current.requestPipeProcessorsApplication('hydrateRows');
82
+ applyAggregation();
83
+ }
73
84
  }
74
85
 
75
86
  // Re-apply the column hydration to wrap / unwrap the aggregated columns
76
87
  if (!areAggregationRulesEqual(rulesOnLastColumnHydration, aggregationRules)) {
77
- apiRef.current.caches.aggregation.rulesOnLastColumnHydration = aggregationRules;
78
88
  apiRef.current.requestPipeProcessorsApplication('hydrateColumns');
79
89
  }
80
- }, [apiRef, applyAggregation, props.aggregationFunctions, props.disableAggregation]);
90
+ }, [apiRef, applyAggregation, props.aggregationFunctions, props.disableAggregation, props.unstable_dataSource]);
81
91
  useGridApiEventHandler(apiRef, 'aggregationModelChange', checkAggregationRulesDiff);
82
92
  useGridApiEventHandler(apiRef, 'columnsChange', checkAggregationRulesDiff);
83
93
  useGridApiEventHandler(apiRef, 'filteredRowsSet', applyAggregation);
@@ -10,11 +10,7 @@ export const useGridAggregationPreProcessors = (apiRef, props) => {
10
10
  // that the pre-processor is called it will already have been updated with the current rules.
11
11
  const rulesOnLastColumnHydration = React.useRef({});
12
12
  const updateAggregatedColumns = React.useCallback(columnsState => {
13
- const aggregationRules = props.disableAggregation ? {} : getAggregationRules({
14
- columnsLookup: columnsState.lookup,
15
- aggregationModel: gridAggregationModelSelector(apiRef),
16
- aggregationFunctions: props.aggregationFunctions
17
- });
13
+ const aggregationRules = props.disableAggregation ? {} : getAggregationRules(columnsState.lookup, gridAggregationModelSelector(apiRef), props.aggregationFunctions, !!props.unstable_dataSource);
18
14
  columnsState.orderedFields.forEach(field => {
19
15
  const shouldHaveAggregationValue = !!aggregationRules[field];
20
16
  const haveAggregationColumnValue = !!rulesOnLastColumnHydration.current[field];
@@ -34,14 +30,11 @@ export const useGridAggregationPreProcessors = (apiRef, props) => {
34
30
  columnsState.lookup[field] = column;
35
31
  });
36
32
  rulesOnLastColumnHydration.current = aggregationRules;
33
+ apiRef.current.caches.aggregation.rulesOnLastColumnHydration = aggregationRules;
37
34
  return columnsState;
38
- }, [apiRef, props.aggregationFunctions, props.disableAggregation]);
35
+ }, [apiRef, props.aggregationFunctions, props.disableAggregation, props.unstable_dataSource]);
39
36
  const addGroupFooterRows = React.useCallback(value => {
40
- const aggregationRules = props.disableAggregation ? {} : getAggregationRules({
41
- columnsLookup: gridColumnLookupSelector(apiRef),
42
- aggregationModel: gridAggregationModelSelector(apiRef),
43
- aggregationFunctions: props.aggregationFunctions
44
- });
37
+ const aggregationRules = props.disableAggregation ? {} : getAggregationRules(gridColumnLookupSelector(apiRef), gridAggregationModelSelector(apiRef), props.aggregationFunctions, !!props.unstable_dataSource);
45
38
  const hasAggregationRule = Object.keys(aggregationRules).length > 0;
46
39
 
47
40
  // If we did not have any aggregation footer before, and we still don't have any,
@@ -56,20 +49,21 @@ export const useGridAggregationPreProcessors = (apiRef, props) => {
56
49
  getAggregationPosition: props.getAggregationPosition,
57
50
  hasAggregationRule
58
51
  });
59
- }, [apiRef, props.disableAggregation, props.getAggregationPosition, props.aggregationFunctions]);
52
+ }, [apiRef, props.disableAggregation, props.getAggregationPosition, props.aggregationFunctions, props.unstable_dataSource]);
60
53
  const addColumnMenuButtons = React.useCallback((columnMenuItems, colDef) => {
61
54
  if (props.disableAggregation || !colDef.aggregable) {
62
55
  return columnMenuItems;
63
56
  }
64
57
  const availableAggregationFunctions = getAvailableAggregationFunctions({
65
58
  aggregationFunctions: props.aggregationFunctions,
66
- colDef
59
+ colDef,
60
+ isDataSource: !!props.unstable_dataSource
67
61
  });
68
62
  if (availableAggregationFunctions.length === 0) {
69
63
  return columnMenuItems;
70
64
  }
71
65
  return [...columnMenuItems, 'columnMenuAggregationItem'];
72
- }, [props.aggregationFunctions, props.disableAggregation]);
66
+ }, [props.aggregationFunctions, props.disableAggregation, props.unstable_dataSource]);
73
67
  const stateExportPreProcessing = React.useCallback(prevState => {
74
68
  if (props.disableAggregation) {
75
69
  return prevState;
@@ -2,8 +2,8 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import ownerDocument from '@mui/utils/ownerDocument';
4
4
  import useEventCallback from '@mui/utils/useEventCallback';
5
- import { getTotalHeaderHeight, getVisibleRows, isNavigationKey, serializeCellValue, useGridRegisterPipeProcessor, useGridVisibleRows } from '@mui/x-data-grid-pro/internals';
6
- import { useGridApiEventHandler, useGridApiMethod, GRID_ACTIONS_COLUMN_TYPE, GRID_CHECKBOX_SELECTION_COL_DEF, GRID_DETAIL_PANEL_TOGGLE_FIELD, gridRowsDataRowIdToIdLookupSelector, gridClasses, gridFocusCellSelector, GRID_REORDER_COL_DEF, useGridSelector, gridSortedRowIdsSelector, gridDimensionsSelector } from '@mui/x-data-grid-pro';
5
+ import { getTotalHeaderHeight, getVisibleRows, isNavigationKey, serializeCellValue, useGridRegisterPipeProcessor } from '@mui/x-data-grid-pro/internals';
6
+ import { useGridApiEventHandler, useGridApiMethod, GRID_ACTIONS_COLUMN_TYPE, GRID_CHECKBOX_SELECTION_COL_DEF, GRID_DETAIL_PANEL_TOGGLE_FIELD, gridClasses, gridFocusCellSelector, GRID_REORDER_COL_DEF, gridSortedRowIdsSelector, gridDimensionsSelector } from '@mui/x-data-grid-pro';
7
7
  import { gridCellSelectionStateSelector } from "./gridCellSelectionSelector.js";
8
8
  export const cellSelectionStateInitializer = (state, props) => _extends({}, state, {
9
9
  cellSelection: _extends({}, props.cellSelectionModel ?? props.initialState?.cellSelection)
@@ -16,13 +16,10 @@ const AUTO_SCROLL_SPEED = 20; // The speed to scroll once the mouse enters the s
16
16
 
17
17
  export const useGridCellSelection = (apiRef, props) => {
18
18
  const hasRootReference = apiRef.current.rootElementRef.current !== null;
19
- const visibleRows = useGridVisibleRows(apiRef, props);
20
- const cellWithVirtualFocus = React.useRef();
21
- const lastMouseDownCell = React.useRef();
19
+ const cellWithVirtualFocus = React.useRef(null);
20
+ const lastMouseDownCell = React.useRef(null);
22
21
  const mousePosition = React.useRef(null);
23
- const autoScrollRAF = React.useRef();
24
- const sortedRowIds = useGridSelector(apiRef, gridSortedRowIdsSelector);
25
- const dimensions = useGridSelector(apiRef, gridDimensionsSelector);
22
+ const autoScrollRAF = React.useRef(null);
26
23
  const totalHeaderHeight = getTotalHeaderHeight(apiRef, props);
27
24
  const ignoreValueFormatterProp = props.ignoreValueFormatterDuringExport;
28
25
  const ignoreValueFormatter = (typeof ignoreValueFormatterProp === 'object' ? ignoreValueFormatterProp?.clipboardExport : ignoreValueFormatterProp) || false;
@@ -76,6 +73,7 @@ export const useGridCellSelection = (apiRef, props) => {
76
73
  finalEndColumnIndex = startColumnIndex;
77
74
  }
78
75
  const visibleColumns = apiRef.current.getVisibleColumns();
76
+ const visibleRows = getVisibleRows(apiRef);
79
77
  const rowsInRange = visibleRows.rows.slice(finalStartRowIndex, finalEndRowIndex + 1);
80
78
  const columnsInRange = visibleColumns.slice(finalStartColumnIndex, finalEndColumnIndex + 1);
81
79
  const newModel = keepOtherSelected ? _extends({}, apiRef.current.getCellSelectionModel()) : {};
@@ -88,10 +86,9 @@ export const useGridCellSelection = (apiRef, props) => {
88
86
  }, {});
89
87
  });
90
88
  apiRef.current.setCellSelectionModel(newModel);
91
- }, [apiRef, visibleRows.rows]);
89
+ }, [apiRef]);
92
90
  const getSelectedCellsAsArray = React.useCallback(() => {
93
91
  const selectionModel = apiRef.current.getCellSelectionModel();
94
- const idToIdLookup = gridRowsDataRowIdToIdLookupSelector(apiRef);
95
92
  const currentVisibleRows = getVisibleRows(apiRef, props);
96
93
  const sortedEntries = currentVisibleRows.rows.reduce((result, row) => {
97
94
  if (row.id in selectionModel) {
@@ -103,7 +100,7 @@ export const useGridCellSelection = (apiRef, props) => {
103
100
  selectedCells.push(...Object.entries(fields).reduce((selectedFields, [field, isSelected]) => {
104
101
  if (isSelected) {
105
102
  selectedFields.push({
106
- id: idToIdLookup[id],
103
+ id,
107
104
  field
108
105
  });
109
106
  }
@@ -187,6 +184,7 @@ export const useGridCellSelection = (apiRef, props) => {
187
184
  if (!mousePosition.current || !apiRef.current.virtualScrollerRef?.current) {
188
185
  return;
189
186
  }
187
+ const dimensions = gridDimensionsSelector(apiRef.current.state);
190
188
  const {
191
189
  x: mouseX,
192
190
  y: mouseY
@@ -229,7 +227,7 @@ export const useGridCellSelection = (apiRef, props) => {
229
227
  autoScrollRAF.current = requestAnimationFrame(autoScroll);
230
228
  }
231
229
  autoScroll();
232
- }, [apiRef, dimensions, totalHeaderHeight]);
230
+ }, [apiRef, totalHeaderHeight]);
233
231
  const handleCellMouseOver = React.useCallback((params, event) => {
234
232
  if (!lastMouseDownCell.current) {
235
233
  return;
@@ -246,6 +244,7 @@ export const useGridCellSelection = (apiRef, props) => {
246
244
  if (!virtualScrollerRect) {
247
245
  return;
248
246
  }
247
+ const dimensions = gridDimensionsSelector(apiRef.current.state);
249
248
  const {
250
249
  x,
251
250
  y
@@ -271,7 +270,7 @@ export const useGridCellSelection = (apiRef, props) => {
271
270
  // Mouse has left the sensitivity area while auto scroll is on
272
271
  stopAutoScroll();
273
272
  }
274
- }, [apiRef, startAutoScroll, stopAutoScroll, totalHeaderHeight, dimensions]);
273
+ }, [apiRef, startAutoScroll, stopAutoScroll, totalHeaderHeight]);
275
274
  const handleCellClick = useEventCallback((params, event) => {
276
275
  const {
277
276
  id,
@@ -331,6 +330,7 @@ export const useGridCellSelection = (apiRef, props) => {
331
330
  } else if (event.key === 'ArrowLeft') {
332
331
  endColumnIndex -= 1;
333
332
  }
333
+ const visibleRows = getVisibleRows(apiRef);
334
334
  if (endRowIndex < 0 || endRowIndex >= visibleRows.rows.length) {
335
335
  return;
336
336
  }
@@ -383,6 +383,7 @@ export const useGridCellSelection = (apiRef, props) => {
383
383
  id,
384
384
  field
385
385
  }) => {
386
+ const visibleRows = getVisibleRows(apiRef);
386
387
  if (!visibleRows.range || !apiRef.current.isCellSelected(id, field)) {
387
388
  return classes;
388
389
  }
@@ -431,7 +432,7 @@ export const useGridCellSelection = (apiRef, props) => {
431
432
  newClasses.push(gridClasses['cell--rangeRight']);
432
433
  }
433
434
  return newClasses;
434
- }, [apiRef, visibleRows.range, visibleRows.rows]);
435
+ }, [apiRef]);
435
436
  const canUpdateFocus = React.useCallback((initialValue, {
436
437
  event,
437
438
  cell
@@ -452,6 +453,7 @@ export const useGridCellSelection = (apiRef, props) => {
452
453
  if (apiRef.current.getSelectedCellsAsArray().length <= 1) {
453
454
  return value;
454
455
  }
456
+ const sortedRowIds = gridSortedRowIdsSelector(apiRef.current.state);
455
457
  const cellSelectionModel = apiRef.current.getCellSelectionModel();
456
458
  const unsortedSelectedRowIds = Object.keys(cellSelectionModel);
457
459
  const sortedSelectedRowIds = sortedRowIds.filter(id => unsortedSelectedRowIds.includes(`${id}`));
@@ -477,7 +479,7 @@ export const useGridCellSelection = (apiRef, props) => {
477
479
  return acc === '' ? rowString : [acc, rowString].join('\r\n');
478
480
  }, '');
479
481
  return copyData;
480
- }, [apiRef, ignoreValueFormatter, clipboardCopyCellDelimiter, sortedRowIds]);
482
+ }, [apiRef, ignoreValueFormatter, clipboardCopyCellDelimiter]);
481
483
  useGridRegisterPipeProcessor(apiRef, 'isCellSelected', checkIfCellIsSelected);
482
484
  useGridRegisterPipeProcessor(apiRef, 'cellClassName', addClassesToCells);
483
485
  useGridRegisterPipeProcessor(apiRef, 'canUpdateFocus', canUpdateFocus);
@@ -121,7 +121,7 @@ class CellValueUpdater {
121
121
  if (onProcessRowUpdateError) {
122
122
  onProcessRowUpdateError(errorThrown);
123
123
  } else if (process.env.NODE_ENV !== 'production') {
124
- warnOnce(['MUI X: A call to `processRowUpdate` threw an error which was not handled because `onProcessRowUpdateError` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError` prop, for example `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/#server-side-persistence.'], 'error');
124
+ warnOnce(['MUI X: A call to `processRowUpdate` threw an error which was not handled because `onProcessRowUpdateError` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError` prop, for example `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/persistence/.'], 'error');
125
125
  }
126
126
  };
127
127
  try {
@@ -0,0 +1,3 @@
1
+ export function getKeyPremium(params) {
2
+ return JSON.stringify([params.filterModel, params.sortModel, params.groupKeys, params.groupFields, params.start, params.end, params.aggregationModel]);
3
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,53 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import * as React from 'react';
3
+ import { useGridApiEventHandler as addEventHandler, useGridApiMethod, GRID_ROOT_GROUP_ID } from '@mui/x-data-grid-pro';
4
+ import { useGridDataSourceBase, useGridRegisterStrategyProcessor, useGridRegisterPipeProcessor } from '@mui/x-data-grid-pro/internals';
5
+ import { getKeyPremium } from "./cache.js";
6
+ const options = {
7
+ cacheOptions: {
8
+ getKey: getKeyPremium
9
+ }
10
+ };
11
+ export const useGridDataSourcePremium = (apiRef, props) => {
12
+ const {
13
+ api,
14
+ strategyProcessor,
15
+ events
16
+ } = useGridDataSourceBase(apiRef, props, options);
17
+ const aggregateRowRef = React.useRef({});
18
+ const processDataSourceRows = React.useCallback(({
19
+ params,
20
+ response
21
+ }, applyRowHydration) => {
22
+ if (response.aggregateRow) {
23
+ aggregateRowRef.current = response.aggregateRow;
24
+ }
25
+ if (Object.keys(params.aggregationModel || {}).length > 0) {
26
+ if (applyRowHydration) {
27
+ apiRef.current.requestPipeProcessorsApplication('hydrateRows');
28
+ }
29
+ apiRef.current.applyAggregation();
30
+ }
31
+ return {
32
+ params,
33
+ response
34
+ };
35
+ }, [apiRef]);
36
+ const resolveGroupAggregation = React.useCallback((groupId, field) => {
37
+ if (groupId === GRID_ROOT_GROUP_ID) {
38
+ return props.unstable_dataSource?.getAggregatedValue?.(aggregateRowRef.current, field);
39
+ }
40
+ const row = apiRef.current.getRow(groupId);
41
+ return props.unstable_dataSource?.getAggregatedValue?.(row, field);
42
+ }, [apiRef, props.unstable_dataSource]);
43
+ const privateApi = _extends({}, api.private, {
44
+ resolveGroupAggregation
45
+ });
46
+ useGridApiMethod(apiRef, api.public, 'public');
47
+ useGridApiMethod(apiRef, privateApi, 'private');
48
+ useGridRegisterStrategyProcessor(apiRef, strategyProcessor.strategyName, strategyProcessor.group, strategyProcessor.processor);
49
+ useGridRegisterPipeProcessor(apiRef, 'processDataSourceRows', processDataSourceRows);
50
+ Object.entries(events).forEach(([event, handler]) => {
51
+ addEventHandler(apiRef, event, handler);
52
+ });
53
+ };
@@ -32,7 +32,9 @@ const GROUPING_COL_DEF_FORCED_PROPERTIES_DATA_SOURCE = _extends({}, GROUPING_COL
32
32
  * 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).
33
33
  */
34
34
  const groupingFieldIndexComparator = (v1, v2, cellParams1, cellParams2) => {
35
- const model = gridRowGroupingSanitizedModelSelector(cellParams1.api.state, cellParams1.api.instanceId);
35
+ const model = gridRowGroupingSanitizedModelSelector({
36
+ current: cellParams1.api
37
+ });
36
38
  const groupingField1 = cellParams1.rowNode.groupingField ?? null;
37
39
  const groupingField2 = cellParams2.rowNode.groupingField ?? null;
38
40
  if (groupingField1 === groupingField2) {
@@ -63,10 +65,12 @@ const getLeafProperties = leafColDef => ({
63
65
  return groupingFieldIndexComparator(v1, v2, cellParams1, cellParams2);
64
66
  }
65
67
  });
68
+ const groupedByColValueFormatter = groupedByColDef => (value, row, _, apiRef) => groupedByColDef.valueFormatter(value, row, groupedByColDef, apiRef);
66
69
  const getGroupingCriteriaProperties = (groupedByColDef, applyHeaderName) => {
67
70
  const properties = {
68
71
  sortable: groupedByColDef.sortable,
69
72
  filterable: groupedByColDef.filterable,
73
+ valueFormatter: groupedByColDef.valueFormatter ? groupedByColValueFormatter(groupedByColDef) : undefined,
70
74
  valueOptions: isSingleSelectColDef(groupedByColDef) ? groupedByColDef.valueOptions : undefined,
71
75
  sortComparator: (v1, v2, cellParams1, cellParams2) => {
72
76
  // We only want to sort the groups of the current grouping criteria
@@ -1,5 +1,5 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- import { passFilterLogic, GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD, getRowGroupingCriteriaFromGroupingField, isGroupingColumn } from '@mui/x-data-grid-pro/internals';
2
+ import { passFilterLogic, GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD, getRowGroupingCriteriaFromGroupingField, isGroupingColumn, GridStrategyGroup } from '@mui/x-data-grid-pro/internals';
3
3
  import { gridRowGroupingSanitizedModelSelector } from "./gridRowGroupingSelector.js";
4
4
  export { GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD, getRowGroupingCriteriaFromGroupingField, isGroupingColumn };
5
5
  export let RowGroupingStrategy = /*#__PURE__*/function (RowGroupingStrategy) {
@@ -75,7 +75,9 @@ export const filterRowTreeFromGroupingColumns = params => {
75
75
  isPassingFiltering = passFilterLogic(allResults.map(result => result.passingFilterItems), allResults.map(result => result.passingQuickFilterValues), filterModel, params.apiRef, filterCache);
76
76
  }
77
77
  }
78
- filteredRowsLookup[node.id] = isPassingFiltering;
78
+ if (!isPassingFiltering) {
79
+ filteredRowsLookup[node.id] = false;
80
+ }
79
81
  if (!isPassingFiltering) {
80
82
  return 0;
81
83
  }
@@ -124,7 +126,7 @@ export const setStrategyAvailability = (privateApiRef, disableRowGrouping, dataS
124
126
  };
125
127
  }
126
128
  const strategy = dataSource ? RowGroupingStrategy.DataSource : RowGroupingStrategy.Default;
127
- privateApiRef.current.setStrategyAvailability('rowTree', strategy, isAvailable);
129
+ privateApiRef.current.setStrategyAvailability(GridStrategyGroup.RowTree, strategy, isAvailable);
128
130
  };
129
131
  export const getCellGroupingCriteria = ({
130
132
  row,
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
3
  import { useGridApiEventHandler, useGridApiMethod, gridColumnLookupSelector } from '@mui/x-data-grid-pro';
4
- import { useGridRegisterPipeProcessor } from '@mui/x-data-grid-pro/internals';
4
+ import { useGridRegisterPipeProcessor, GridStrategyGroup } from '@mui/x-data-grid-pro/internals';
5
5
  import { gridRowGroupingModelSelector, gridRowGroupingSanitizedModelSelector } from "./gridRowGroupingSelector.js";
6
6
  import { getRowGroupingFieldFromGroupingCriteria, RowGroupingStrategy, isGroupingColumn, mergeStateWithRowGroupingModel, setStrategyAvailability, getGroupingRules, areGroupingRulesEqual } from "./gridRowGroupingUtils.js";
7
7
  export const rowGroupingStateInitializer = (state, props, apiRef) => {
@@ -162,7 +162,7 @@ export const useGridRowGrouping = (apiRef, props) => {
162
162
 
163
163
  // Refresh the row tree creation strategy processing
164
164
  // TODO: Add a clean way to re-run a strategy processing without publishing a private event
165
- if (apiRef.current.getActiveStrategy('rowTree') === RowGroupingStrategy.Default) {
165
+ if (apiRef.current.getActiveStrategy(GridStrategyGroup.RowTree) === RowGroupingStrategy.Default) {
166
166
  apiRef.current.publishEvent('activeStrategyProcessorChange', 'rowTreeCreation');
167
167
  }
168
168
  }