@mui/x-data-grid-premium 8.7.0 → 8.9.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 (40) hide show
  1. package/CHANGELOG.md +199 -24
  2. package/DataGridPremium/DataGridPremium.js +1 -1
  3. package/DataGridPremium/useDataGridPremiumComponent.js +19 -7
  4. package/DataGridPremium/useDataGridPremiumProps.js +2 -1
  5. package/esm/DataGridPremium/DataGridPremium.js +1 -1
  6. package/esm/DataGridPremium/useDataGridPremiumComponent.js +21 -8
  7. package/esm/DataGridPremium/useDataGridPremiumProps.js +2 -1
  8. package/esm/hooks/features/aggregation/createAggregationLookup.d.ts +9 -4
  9. package/esm/hooks/features/aggregation/createAggregationLookup.js +78 -41
  10. package/esm/hooks/features/aggregation/gridAggregationFunctions.js +2 -2
  11. package/esm/hooks/features/aggregation/gridAggregationInterfaces.d.ts +13 -1
  12. package/esm/hooks/features/aggregation/gridAggregationUtils.d.ts +2 -1
  13. package/esm/hooks/features/aggregation/gridAggregationUtils.js +2 -1
  14. package/esm/hooks/features/aggregation/useGridAggregation.js +94 -18
  15. package/esm/hooks/features/pivoting/gridPivotingInterfaces.d.ts +12 -2
  16. package/esm/hooks/features/pivoting/useGridPivoting.d.ts +2 -1
  17. package/esm/hooks/features/pivoting/useGridPivoting.js +57 -35
  18. package/esm/hooks/features/pivoting/utils.d.ts +3 -1
  19. package/esm/hooks/features/pivoting/utils.js +22 -14
  20. package/esm/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -1
  21. package/esm/hooks/features/rowGrouping/useGridDataSourceRowGroupingPreProcessors.js +2 -2
  22. package/esm/index.js +3 -3
  23. package/esm/typeOverloads/modules.d.ts +2 -1
  24. package/hooks/features/aggregation/createAggregationLookup.d.ts +9 -4
  25. package/hooks/features/aggregation/createAggregationLookup.js +79 -41
  26. package/hooks/features/aggregation/gridAggregationFunctions.js +2 -2
  27. package/hooks/features/aggregation/gridAggregationInterfaces.d.ts +13 -1
  28. package/hooks/features/aggregation/gridAggregationUtils.d.ts +2 -1
  29. package/hooks/features/aggregation/gridAggregationUtils.js +4 -2
  30. package/hooks/features/aggregation/useGridAggregation.js +92 -16
  31. package/hooks/features/pivoting/gridPivotingInterfaces.d.ts +12 -2
  32. package/hooks/features/pivoting/useGridPivoting.d.ts +2 -1
  33. package/hooks/features/pivoting/useGridPivoting.js +60 -37
  34. package/hooks/features/pivoting/utils.d.ts +3 -1
  35. package/hooks/features/pivoting/utils.js +22 -14
  36. package/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -1
  37. package/hooks/features/rowGrouping/useGridDataSourceRowGroupingPreProcessors.js +1 -1
  38. package/index.js +3 -3
  39. package/package.json +6 -6
  40. package/typeOverloads/modules.d.ts +2 -1
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.useGridPivoting = exports.pivotingStateInitializer = void 0;
8
+ exports.useGridPivotingExportState = exports.useGridPivoting = exports.pivotingStateInitializer = void 0;
9
9
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
10
  var React = _interopRequireWildcard(require("react"));
11
11
  var _xDataGridPro = require("@mui/x-data-grid-pro");
@@ -21,6 +21,14 @@ const emptyPivotModel = {
21
21
  values: []
22
22
  };
23
23
  const pivotingStateInitializer = (state, props, apiRef) => {
24
+ apiRef.current.caches.pivoting = {
25
+ exportedStateRef: {
26
+ current: null
27
+ },
28
+ nonPivotDataRef: {
29
+ current: undefined
30
+ }
31
+ };
24
32
  if (!(0, _utils.isPivotingAvailable)(props)) {
25
33
  return (0, _extends2.default)({}, state, {
26
34
  pivoting: {
@@ -43,8 +51,10 @@ const pivotingStateInitializer = (state, props, apiRef) => {
43
51
  exports.pivotingStateInitializer = pivotingStateInitializer;
44
52
  const useGridPivoting = (apiRef, props, originalColumnsProp, originalRowsProp) => {
45
53
  const isPivotActive = (0, _internals.useGridSelector)(apiRef, _gridPivotingSelectors.gridPivotActiveSelector);
46
- const exportedStateRef = React.useRef(null);
47
- const nonPivotDataRef = React.useRef(undefined);
54
+ const {
55
+ exportedStateRef,
56
+ nonPivotDataRef
57
+ } = apiRef.current.caches.pivoting;
48
58
  const isPivotingAvailable = (0, _utils.isPivotingAvailable)(props);
49
59
  apiRef.current.registerControlState({
50
60
  stateId: 'pivotModel',
@@ -77,9 +87,10 @@ const useGridPivoting = (apiRef, props, originalColumnsProp, originalRowsProp) =
77
87
  const initialColumns = (0, _utils.getInitialColumns)(originalColumnsProp, props.getPivotDerivedColumns, apiRef.current.getLocaleText);
78
88
  return {
79
89
  rows,
80
- columns: initialColumns
90
+ columns: initialColumns,
91
+ originalRowsProp
81
92
  };
82
- }, [apiRef, props.getPivotDerivedColumns, originalColumnsProp]);
93
+ }, [apiRef, props.getPivotDerivedColumns, originalColumnsProp, originalRowsProp, exportedStateRef]);
83
94
  const computePivotingState = React.useCallback(({
84
95
  active,
85
96
  model: pivotModel
@@ -100,51 +111,44 @@ const useGridPivoting = (apiRef, props, originalColumnsProp, originalRowsProp) =
100
111
  columns,
101
112
  pivotModel,
102
113
  apiRef: apiRef,
103
- pivotingColDef: props.pivotingColDef
114
+ pivotingColDef: props.pivotingColDef,
115
+ groupingColDef: props.groupingColDef
104
116
  })
105
117
  };
106
118
  }
107
119
  return undefined;
108
- }, [apiRef, props.pivotingColDef]);
120
+ }, [apiRef, props.pivotingColDef, props.groupingColDef, nonPivotDataRef]);
109
121
  (0, _useOnMount.default)(() => {
110
122
  if (!isPivotingAvailable || !isPivotActive) {
111
123
  return undefined;
112
124
  }
125
+ nonPivotDataRef.current = getInitialData();
113
126
  const isLoading = (0, _xDataGridPro.gridRowsLoadingSelector)(apiRef) ?? false;
114
- const runPivoting = () => {
115
- nonPivotDataRef.current = getInitialData();
116
- apiRef.current.setState(state => {
117
- const pivotingState = (0, _extends2.default)({}, state.pivoting, computePivotingState(state.pivoting));
118
- return (0, _extends2.default)({}, state, {
119
- pivoting: pivotingState
120
- });
121
- });
122
- };
123
- if (!isLoading) {
124
- runPivoting();
127
+ if (isLoading) {
125
128
  return undefined;
126
129
  }
127
- const unsubscribe = apiRef.current?.store.subscribe(() => {
128
- const loading = (0, _xDataGridPro.gridRowsLoadingSelector)(apiRef);
129
- if (loading === false) {
130
- unsubscribe();
131
- runPivoting();
132
- }
130
+ apiRef.current.setState(state => {
131
+ const pivotingState = (0, _extends2.default)({}, state.pivoting, computePivotingState(state.pivoting));
132
+ return (0, _extends2.default)({}, state, {
133
+ pivoting: pivotingState
134
+ });
133
135
  });
134
- return unsubscribe;
136
+ return undefined;
135
137
  });
136
138
  (0, _useEnhancedEffect.default)(() => {
137
139
  if (!isPivotingAvailable || !isPivotActive) {
138
- if (exportedStateRef.current) {
139
- apiRef.current.restoreState(exportedStateRef.current);
140
- exportedStateRef.current = null;
141
- }
142
140
  if (nonPivotDataRef.current) {
141
+ // Prevent rows from being resynced from the original rows prop
142
+ apiRef.current.caches.rows.rowsBeforePartialUpdates = nonPivotDataRef.current.originalRowsProp;
143
143
  apiRef.current.setRows(nonPivotDataRef.current.rows);
144
144
  nonPivotDataRef.current = undefined;
145
145
  }
146
+ if (exportedStateRef.current) {
147
+ apiRef.current.restoreState(exportedStateRef.current);
148
+ exportedStateRef.current = null;
149
+ }
146
150
  }
147
- }, [isPivotActive, apiRef, isPivotingAvailable]);
151
+ }, [isPivotActive, apiRef, isPivotingAvailable, nonPivotDataRef, exportedStateRef]);
148
152
  const setPivotModel = React.useCallback(callback => {
149
153
  if (!isPivotingAvailable) {
150
154
  return;
@@ -230,7 +234,6 @@ const useGridPivoting = (apiRef, props, originalColumnsProp, originalRowsProp) =
230
234
  if (!isPivotingAvailable) {
231
235
  return;
232
236
  }
233
- apiRef.current.selectRows([], false, true);
234
237
  apiRef.current.setState(state => {
235
238
  const newPivotMode = typeof callback === 'function' ? callback(state.pivoting?.active) : callback;
236
239
  if (state.pivoting?.active === newPivotMode) {
@@ -249,7 +252,8 @@ const useGridPivoting = (apiRef, props, originalColumnsProp, originalRowsProp) =
249
252
  });
250
253
  return newState;
251
254
  });
252
- }, [apiRef, computePivotingState, getInitialData, isPivotingAvailable]);
255
+ apiRef.current.selectRows([], false, true);
256
+ }, [apiRef, computePivotingState, getInitialData, isPivotingAvailable, nonPivotDataRef]);
253
257
  const setPivotPanelOpen = React.useCallback(callback => {
254
258
  if (!isPivotingAvailable) {
255
259
  return;
@@ -285,9 +289,9 @@ const useGridPivoting = (apiRef, props, originalColumnsProp, originalRowsProp) =
285
289
  })
286
290
  });
287
291
  });
288
- }, [isPivotingAvailable, apiRef, props.getPivotDerivedColumns, computePivotingState]);
292
+ }, [isPivotingAvailable, apiRef, props.getPivotDerivedColumns, computePivotingState, nonPivotDataRef]);
289
293
  const updateNonPivotRows = React.useCallback((rows, keepPreviousRows = true) => {
290
- if (!nonPivotDataRef.current || !rows || rows.length === 0) {
294
+ if (!nonPivotDataRef.current || !isPivotingAvailable || !rows || rows.length === 0) {
291
295
  return;
292
296
  }
293
297
  if (keepPreviousRows) {
@@ -313,7 +317,7 @@ const useGridPivoting = (apiRef, props, originalColumnsProp, originalRowsProp) =
313
317
  pivoting: (0, _extends2.default)({}, state.pivoting, computePivotingState(state.pivoting))
314
318
  });
315
319
  });
316
- }, [apiRef, computePivotingState]);
320
+ }, [apiRef, computePivotingState, isPivotingAvailable, nonPivotDataRef]);
317
321
  (0, _internals.useGridApiMethod)(apiRef, {
318
322
  setPivotModel,
319
323
  setPivotActive,
@@ -329,7 +333,10 @@ const useGridPivoting = (apiRef, props, originalColumnsProp, originalRowsProp) =
329
333
  }, [originalColumnsProp, apiRef]);
330
334
  (0, _useEnhancedEffect.default)(() => {
331
335
  apiRef.current.updateNonPivotRows(originalRowsProp, false);
332
- }, [originalRowsProp, apiRef]);
336
+ if (nonPivotDataRef.current) {
337
+ nonPivotDataRef.current.originalRowsProp = originalRowsProp;
338
+ }
339
+ }, [originalRowsProp, apiRef, nonPivotDataRef]);
333
340
  (0, _useEnhancedEffect.default)(() => {
334
341
  if (props.pivotModel !== undefined) {
335
342
  apiRef.current.setPivotModel(props.pivotModel);
@@ -346,4 +353,20 @@ const useGridPivoting = (apiRef, props, originalColumnsProp, originalRowsProp) =
346
353
  }
347
354
  }, [apiRef, props.pivotPanelOpen]);
348
355
  };
349
- exports.useGridPivoting = useGridPivoting;
356
+ exports.useGridPivoting = useGridPivoting;
357
+ const useGridPivotingExportState = apiRef => {
358
+ const stateExportPreProcessing = React.useCallback(state => {
359
+ const isPivotActive = (0, _gridPivotingSelectors.gridPivotActiveSelector)(apiRef);
360
+ if (!isPivotActive) {
361
+ return state;
362
+ }
363
+
364
+ // To-do: implement context.exportOnlyDirtyModels
365
+ const newState = (0, _extends2.default)({}, state, apiRef.current.caches.pivoting.exportedStateRef.current, {
366
+ sorting: state.sorting
367
+ });
368
+ return newState;
369
+ }, [apiRef]);
370
+ (0, _internals.useGridRegisterPipeProcessor)(apiRef, 'exportState', stateExportPreProcessing);
371
+ };
372
+ exports.useGridPivotingExportState = useGridPivotingExportState;
@@ -11,11 +11,13 @@ export declare const getPivotedData: ({
11
11
  columns,
12
12
  pivotModel,
13
13
  apiRef,
14
- pivotingColDef
14
+ pivotingColDef,
15
+ groupingColDef
15
16
  }: {
16
17
  rows: GridRowModel[];
17
18
  columns: Map<string, GridColDef>;
18
19
  pivotModel: GridPivotModel;
19
20
  apiRef: RefObject<GridApiPremium>;
20
21
  pivotingColDef: DataGridPremiumProcessedProps["pivotingColDef"];
22
+ groupingColDef: DataGridPremiumProcessedProps["groupingColDef"];
21
23
  }) => GridPivotingPropsOverrides;
@@ -9,6 +9,7 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
9
9
  var _xDataGridPro = require("@mui/x-data-grid-pro");
10
10
  var _internals = require("@mui/x-data-grid-pro/internals");
11
11
  var _rowGrouping = require("../rowGrouping");
12
+ var _gridAggregationUtils = require("../aggregation/gridAggregationUtils");
12
13
  const columnGroupIdSeparator = '>->';
13
14
  const isPivotingAvailable = props => {
14
15
  return !props.disablePivoting;
@@ -74,7 +75,8 @@ const getPivotedData = ({
74
75
  columns,
75
76
  pivotModel,
76
77
  apiRef,
77
- pivotingColDef
78
+ pivotingColDef,
79
+ groupingColDef
78
80
  }) => {
79
81
  const visibleColumns = pivotModel.columns.filter(column => !column.hidden);
80
82
  const visibleRows = pivotModel.rows.filter(row => !row.hidden);
@@ -139,26 +141,31 @@ const getPivotedData = ({
139
141
  const row = rows[i];
140
142
  const newRow = (0, _extends2.default)({}, row);
141
143
  const columnGroupPath = [];
142
- visibleColumns.forEach(({
143
- field: colGroupField
144
- }, depth) => {
144
+ for (let j = 0; j < visibleColumns.length; j += 1) {
145
+ const {
146
+ field: colGroupField
147
+ } = visibleColumns[j];
148
+ const depth = j;
145
149
  const column = initialColumns.get(colGroupField);
146
150
  if (!column) {
147
- return;
151
+ continue;
148
152
  }
149
153
  let colValue = apiRef.current.getRowValue(row, column) ?? '(No value)';
154
+ if (column.type !== 'number') {
155
+ colValue = String(colValue);
156
+ }
150
157
  if (column.type === 'singleSelect') {
151
158
  const singleSelectColumn = column;
152
159
  if (singleSelectColumn.getOptionLabel) {
153
160
  colValue = singleSelectColumn.getOptionLabel(colValue);
154
161
  }
155
162
  }
156
- columnGroupPath.push(String(colValue));
163
+ columnGroupPath.push(colValue);
157
164
  const groupId = columnGroupPath.join(columnGroupIdSeparator);
158
165
  if (!columnGroupingModelLookup.has(groupId)) {
159
166
  const columnGroup = {
160
167
  groupId,
161
- headerName: String(colValue),
168
+ headerName: colValue,
162
169
  children: []
163
170
  };
164
171
  columnGroupingModelLookup.set(groupId, columnGroup);
@@ -184,7 +191,7 @@ const getPivotedData = ({
184
191
  newRow[valueKey] = apiRef.current.getRowValue(row, originalColumn);
185
192
  });
186
193
  }
187
- });
194
+ }
188
195
  newRows.push(newRow);
189
196
  }
190
197
  sortColumnGroups(columnGroupingModel, visibleColumns);
@@ -249,19 +256,20 @@ const getPivotedData = ({
249
256
  }
250
257
  }
251
258
  createColumns(columnGroupingModel);
259
+ const groupingColDefOverrides = params => (0, _extends2.default)({}, typeof groupingColDef === 'function' ? groupingColDef(params) : groupingColDef || {}, {
260
+ filterable: false,
261
+ aggregable: false,
262
+ hideable: false
263
+ });
252
264
  return {
253
265
  rows: visibleRows.length > 0 ? newRows : [],
254
266
  columns: pivotColumns,
255
267
  rowGroupingModel: visibleRows.map(row => row.field),
256
268
  aggregationModel,
257
- getAggregationPosition: groupNode => groupNode.depth === -1 ? 'footer' : 'inline',
269
+ getAggregationPosition: _gridAggregationUtils.defaultGetAggregationPosition,
258
270
  columnVisibilityModel,
259
271
  columnGroupingModel,
260
- groupingColDef: {
261
- filterable: false,
262
- aggregable: false,
263
- hideable: false
264
- },
272
+ groupingColDef: groupingColDefOverrides,
265
273
  headerFilters: false,
266
274
  disableAggregation: false,
267
275
  disableRowGrouping: false
@@ -146,6 +146,11 @@ const mergeStateWithRowGroupingModel = rowGroupingModel => state => (0, _extends
146
146
  });
147
147
  exports.mergeStateWithRowGroupingModel = mergeStateWithRowGroupingModel;
148
148
  const setStrategyAvailability = (privateApiRef, disableRowGrouping, dataSource) => {
149
+ const strategy = dataSource ? RowGroupingStrategy.DataSource : RowGroupingStrategy.Default;
150
+ if (privateApiRef.current.getActiveStrategy(_internals.GridStrategyGroup.RowTree) === strategy) {
151
+ // If the strategy is already active, we don't need to set it again
152
+ return;
153
+ }
149
154
  let isAvailable;
150
155
  if (disableRowGrouping) {
151
156
  isAvailable = () => false;
@@ -155,7 +160,6 @@ const setStrategyAvailability = (privateApiRef, disableRowGrouping, dataSource)
155
160
  return rowGroupingSanitizedModel.length > 0;
156
161
  };
157
162
  }
158
- const strategy = dataSource ? RowGroupingStrategy.DataSource : RowGroupingStrategy.Default;
159
163
  privateApiRef.current.setStrategyAvailability(_internals.GridStrategyGroup.RowTree, strategy, isAvailable);
160
164
  };
161
165
  exports.setStrategyAvailability = setStrategyAvailability;
@@ -28,7 +28,7 @@ const useGridDataSourceRowGroupingPreProcessors = (apiRef, props) => {
28
28
  });
29
29
  apiRef.current.caches.rowGrouping.rulesOnLastRowTreeCreation = groupingRules;
30
30
  const getRowTreeBuilderNode = rowId => {
31
- const parentPath = params.updates.groupKeys ?? [];
31
+ const parentPath = params.updates.groupKeys ?? (0, _internals.getParentPath)(rowId, params);
32
32
  const leafKey = getGroupKey(params.dataRowIdToModelLookup[rowId]);
33
33
  return {
34
34
  id: rowId,
package/index.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
- * @mui/x-data-grid-premium v8.7.0
2
+ * @mui/x-data-grid-premium v8.9.0
3
3
  *
4
- * @license MUI X Commercial
5
- * This source code is licensed under the commercial license found in the
4
+ * @license SEE LICENSE IN LICENSE
5
+ * This source code is licensed under the SEE LICENSE IN LICENSE license found in the
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  "use strict";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-data-grid-premium",
3
- "version": "8.7.0",
3
+ "version": "8.9.0",
4
4
  "author": "MUI Team",
5
5
  "description": "The Premium plan edition of the MUI X Data Grid Components.",
6
6
  "main": "./index.js",
@@ -36,15 +36,15 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@babel/runtime": "^7.27.6",
39
- "@mui/utils": "^7.1.1",
39
+ "@mui/utils": "^7.2.0",
40
40
  "@types/format-util": "^1.0.4",
41
41
  "clsx": "^2.1.1",
42
42
  "exceljs": "^4.4.0",
43
43
  "prop-types": "^15.8.1",
44
- "@mui/x-data-grid": "8.7.0",
45
- "@mui/x-internals": "8.7.0",
46
- "@mui/x-data-grid-pro": "8.7.0",
47
- "@mui/x-license": "8.7.0"
44
+ "@mui/x-data-grid": "8.8.0",
45
+ "@mui/x-data-grid-pro": "8.9.0",
46
+ "@mui/x-license": "8.9.0",
47
+ "@mui/x-internals": "8.8.0"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "@emotion/react": "^11.9.0",
@@ -5,7 +5,7 @@ import type { GridRowGroupingModel, GridAggregationModel, GridAggregationCellMet
5
5
  import { GridRowGroupingInternalCache } from "../hooks/features/rowGrouping/gridRowGroupingInterfaces.js";
6
6
  import { GridAggregationInternalCache } from "../hooks/features/aggregation/gridAggregationInterfaces.js";
7
7
  import type { GridExcelExportOptions } from "../hooks/features/export/gridExcelExportInterface.js";
8
- import type { GridPivotModel } from "../hooks/features/pivoting/gridPivotingInterfaces.js";
8
+ import type { GridPivotingInternalCache, GridPivotModel } from "../hooks/features/pivoting/gridPivotingInterfaces.js";
9
9
  export interface GridControlledStateEventLookupPremium {
10
10
  /**
11
11
  * Fired when the aggregation model changes.
@@ -105,6 +105,7 @@ export interface GridColumnHeaderParamsPremium<R extends GridValidRowModel = any
105
105
  aggregation?: GridAggregationHeaderMeta;
106
106
  }
107
107
  export interface GridApiCachesPremium extends GridApiCachesPro {
108
+ pivoting: GridPivotingInternalCache;
108
109
  rowGrouping: GridRowGroupingInternalCache;
109
110
  aggregation: GridAggregationInternalCache;
110
111
  }