@mui/x-data-grid-premium 6.0.0-beta.4 → 6.0.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 (94) hide show
  1. package/CHANGELOG.md +204 -29
  2. package/DataGridPremium/DataGridPremium.js +21 -4
  3. package/DataGridPremium/useDataGridPremiumComponent.js +1 -1
  4. package/DataGridPremium/useDataGridPremiumProps.js +26 -19
  5. package/components/GridAggregationHeader.js +3 -2
  6. package/components/GridColumnMenuAggregationItem.js +1 -1
  7. package/components/GridColumnMenuRowGroupItem.js +1 -1
  8. package/components/GridColumnMenuRowUngroupItem.js +2 -2
  9. package/components/GridExcelExportMenuItem.js +2 -1
  10. package/components/GridFooterCell.js +1 -3
  11. package/components/GridGroupingCriteriaCell.js +4 -4
  12. package/components/index.d.ts +1 -1
  13. package/components/index.js +1 -1
  14. package/constants/dataGridPremiumDefaultSlotsComponents.d.ts +1 -2
  15. package/constants/dataGridPremiumDefaultSlotsComponents.js +2 -7
  16. package/hooks/features/aggregation/gridAggregationInterfaces.d.ts +2 -0
  17. package/hooks/features/aggregation/useGridAggregationPreProcessors.d.ts +1 -1
  18. package/hooks/features/export/gridExcelExportInterface.d.ts +11 -0
  19. package/hooks/features/export/index.d.ts +1 -0
  20. package/hooks/features/export/index.js +2 -1
  21. package/hooks/features/export/serializer/excelSerializer.d.ts +52 -3
  22. package/hooks/features/export/serializer/excelSerializer.js +137 -51
  23. package/hooks/features/export/useGridExcelExport.d.ts +2 -1
  24. package/hooks/features/export/useGridExcelExport.js +67 -12
  25. package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +1 -1
  26. package/index.d.ts +1 -0
  27. package/index.js +2 -1
  28. package/legacy/DataGridPremium/DataGridPremium.js +21 -4
  29. package/legacy/DataGridPremium/useDataGridPremiumComponent.js +1 -1
  30. package/legacy/DataGridPremium/useDataGridPremiumProps.js +21 -20
  31. package/legacy/components/GridAggregationHeader.js +3 -2
  32. package/legacy/components/GridColumnMenuAggregationItem.js +1 -1
  33. package/legacy/components/GridColumnMenuRowGroupItem.js +1 -1
  34. package/legacy/components/GridColumnMenuRowUngroupItem.js +2 -2
  35. package/legacy/components/GridExcelExportMenuItem.js +2 -1
  36. package/legacy/components/GridFooterCell.js +1 -3
  37. package/legacy/components/GridGroupingCriteriaCell.js +4 -4
  38. package/legacy/components/index.js +1 -1
  39. package/legacy/constants/dataGridPremiumDefaultSlotsComponents.js +2 -7
  40. package/legacy/hooks/features/export/index.js +2 -1
  41. package/legacy/hooks/features/export/serializer/excelSerializer.js +227 -72
  42. package/legacy/hooks/features/export/useGridExcelExport.js +125 -36
  43. package/legacy/index.js +2 -1
  44. package/legacy/material/index.js +9 -0
  45. package/legacy/utils/releaseInfo.js +1 -1
  46. package/material/index.d.ts +7 -0
  47. package/material/index.js +9 -0
  48. package/material/package.json +6 -0
  49. package/models/dataGridPremiumProps.d.ts +13 -3
  50. package/models/gridPremiumSlotsComponent.d.ts +4 -1
  51. package/modern/DataGridPremium/DataGridPremium.js +21 -4
  52. package/modern/DataGridPremium/useDataGridPremiumComponent.js +1 -1
  53. package/modern/DataGridPremium/useDataGridPremiumProps.js +21 -17
  54. package/modern/components/GridAggregationHeader.js +3 -2
  55. package/modern/components/GridColumnMenuAggregationItem.js +1 -1
  56. package/modern/components/GridColumnMenuRowGroupItem.js +1 -1
  57. package/modern/components/GridColumnMenuRowUngroupItem.js +2 -2
  58. package/modern/components/GridExcelExportMenuItem.js +2 -1
  59. package/modern/components/GridFooterCell.js +1 -3
  60. package/modern/components/GridGroupingCriteriaCell.js +3 -3
  61. package/modern/components/index.js +1 -1
  62. package/modern/constants/dataGridPremiumDefaultSlotsComponents.js +2 -7
  63. package/modern/hooks/features/export/index.js +2 -1
  64. package/modern/hooks/features/export/serializer/excelSerializer.js +131 -47
  65. package/modern/hooks/features/export/useGridExcelExport.js +67 -12
  66. package/modern/index.js +2 -1
  67. package/modern/material/index.js +9 -0
  68. package/modern/utils/releaseInfo.js +1 -1
  69. package/node/DataGridPremium/DataGridPremium.js +19 -2
  70. package/node/DataGridPremium/useDataGridPremiumComponent.js +1 -1
  71. package/node/DataGridPremium/useDataGridPremiumProps.js +21 -17
  72. package/node/components/GridAggregationHeader.js +3 -2
  73. package/node/components/GridColumnMenuAggregationItem.js +1 -1
  74. package/node/components/GridColumnMenuRowGroupItem.js +1 -1
  75. package/node/components/GridColumnMenuRowUngroupItem.js +2 -2
  76. package/node/components/GridExcelExportMenuItem.js +2 -1
  77. package/node/components/GridFooterCell.js +1 -3
  78. package/node/components/GridGroupingCriteriaCell.js +3 -3
  79. package/node/components/index.js +1 -1
  80. package/node/constants/dataGridPremiumDefaultSlotsComponents.js +3 -9
  81. package/node/hooks/features/export/index.js +12 -1
  82. package/node/hooks/features/export/serializer/excelSerializer.js +136 -45
  83. package/node/hooks/features/export/useGridExcelExport.js +66 -10
  84. package/node/index.js +9 -1
  85. package/node/material/index.js +17 -0
  86. package/node/utils/releaseInfo.js +1 -1
  87. package/package.json +4 -4
  88. package/typeOverloads/modules.d.ts +6 -0
  89. package/utils/releaseInfo.js +1 -1
  90. /package/legacy/{components → material}/icons.js +0 -0
  91. /package/{components → material}/icons.d.ts +0 -0
  92. /package/{components → material}/icons.js +0 -0
  93. /package/modern/{components → material}/icons.js +0 -0
  94. /package/node/{components → material}/icons.js +0 -0
@@ -1,12 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import { DATA_GRID_PRO_DEFAULT_SLOTS_COMPONENTS } from '@mui/x-data-grid-pro/internals';
3
- import { GridWorkspacesIcon, GridGroupWorkIcon, GridFunctionsIcon } from '../components';
4
3
  import { GridPremiumColumnMenu } from '../components/GridPremiumColumnMenu';
5
- export const DEFAULT_GRID_PREMIUM_ICON_SLOTS_COMPONENTS = {
6
- ColumnMenuUngroupIcon: GridWorkspacesIcon,
7
- ColumnMenuGroupIcon: GridGroupWorkIcon,
8
- ColumnMenuAggregationIcon: GridFunctionsIcon
9
- };
10
- export const DATA_GRID_PREMIUM_DEFAULT_SLOTS_COMPONENTS = _extends({}, DATA_GRID_PRO_DEFAULT_SLOTS_COMPONENTS, DEFAULT_GRID_PREMIUM_ICON_SLOTS_COMPONENTS, {
4
+ import materialSlots from '../material';
5
+ export const DATA_GRID_PREMIUM_DEFAULT_SLOTS_COMPONENTS = _extends({}, DATA_GRID_PRO_DEFAULT_SLOTS_COMPONENTS, materialSlots, {
11
6
  ColumnMenu: GridPremiumColumnMenu
12
7
  });
@@ -25,6 +25,8 @@ export interface GridAggregationGetCellValueParams {
25
25
  }
26
26
  /**
27
27
  * Grid aggregation function definition interface.
28
+ * @demos
29
+ * - [Aggregation functions](/x/react-data-grid/aggregation/#aggregation-functions)
28
30
  */
29
31
  export interface GridAggregationFunction<V = any, AV = V, FAV = AV> {
30
32
  /**
@@ -1,4 +1,4 @@
1
1
  import * as React from 'react';
2
2
  import { GridPrivateApiPremium } from '../../../models/gridApiPremium';
3
3
  import { DataGridPremiumProcessedProps } from '../../../models/dataGridPremiumProps';
4
- export declare const useGridAggregationPreProcessors: (apiRef: React.MutableRefObject<GridPrivateApiPremium>, props: Pick<DataGridPremiumProcessedProps, 'aggregationFunctions' | 'disableAggregation' | 'getAggregationPosition' | 'componentsProps' | 'components'>) => void;
4
+ export declare const useGridAggregationPreProcessors: (apiRef: React.MutableRefObject<GridPrivateApiPremium>, props: Pick<DataGridPremiumProcessedProps, 'aggregationFunctions' | 'disableAggregation' | 'getAggregationPosition' | 'slotProps' | 'slots'>) => void;
@@ -11,8 +11,15 @@ export interface ColumnsStylesInterface {
11
11
  }
12
12
  /**
13
13
  * The options to apply on the Excel export.
14
+ * @demos
15
+ * - [Excel export](/x/react-data-grid/export/#excel-export)
14
16
  */
15
17
  export interface GridExcelExportOptions extends GridFileExportOptions {
18
+ /**
19
+ * Function to return the Worker instance to be called.
20
+ * @returns {() => Worker} A Worker instance.
21
+ */
22
+ worker?: () => Worker;
16
23
  /**
17
24
  * Name given to the worksheet containing the columns valueOptions.
18
25
  * valueOptions are added to this worksheet if they are provided as an array.
@@ -20,12 +27,16 @@ export interface GridExcelExportOptions extends GridFileExportOptions {
20
27
  valueOptionsSheetName?: string;
21
28
  /**
22
29
  * Method called before adding the rows to the workbook.
30
+ * Not supported when `worker` is set.
31
+ * To use with web workers, use the option in `setupExcelExportWebWorker`.
23
32
  * @param {GridExceljsProcessInput} processInput object containing the workbook and the worksheet.
24
33
  * @returns {Promise<void>} A promise which resolves after processing the input.
25
34
  * */
26
35
  exceljsPreProcess?: (processInput: GridExceljsProcessInput) => Promise<void>;
27
36
  /**
28
37
  * Method called after adding the rows to the workbook.
38
+ * Not supported when `worker` is set.
39
+ * To use with web workers, use the option in `setupExcelExportWebWorker`.
29
40
  * @param {GridExceljsProcessInput} processInput object containing the workbook and the worksheet.
30
41
  * @returns {Promise<void>} A promise which resolves after processing the input.
31
42
  * */
@@ -1 +1,2 @@
1
1
  export * from './gridExcelExportInterface';
2
+ export { setupExcelExportWebWorker } from './serializer/excelSerializer';
@@ -1 +1,2 @@
1
- export * from './gridExcelExportInterface';
1
+ export * from './gridExcelExportInterface';
2
+ export { setupExcelExportWebWorker } from './serializer/excelSerializer';
@@ -1,8 +1,47 @@
1
1
  import type * as Excel from 'exceljs';
2
- import { GridRowId } from '@mui/x-data-grid-pro';
3
- import { GridStateColDef } from '@mui/x-data-grid/internals';
4
- import { GridExceljsProcessInput, ColumnsStylesInterface } from '../gridExcelExportInterface';
2
+ import { GridRowId, GridColDef } from '@mui/x-data-grid-pro';
3
+ import { GridStateColDef, GridColumnGroupLookup } from '@mui/x-data-grid/internals';
4
+ import { GridExceljsProcessInput, ColumnsStylesInterface, GridExcelExportOptions } from '../gridExcelExportInterface';
5
5
  import { GridPrivateApiPremium } from '../../../../models/gridApiPremium';
6
+ interface SerializedRow {
7
+ row: Record<string, undefined | number | boolean | string | Date>;
8
+ dataValidation: Record<string, Excel.DataValidation>;
9
+ outlineLevel: number;
10
+ mergedCells: {
11
+ leftIndex: number;
12
+ rightIndex: number;
13
+ }[];
14
+ }
15
+ export declare const serializeRow: (id: GridRowId, columns: GridStateColDef[], api: GridPrivateApiPremium, defaultValueOptionsFormulae: {
16
+ [field: string]: {
17
+ address: string;
18
+ };
19
+ }) => SerializedRow;
20
+ export declare const serializeColumn: (column: GridColDef, columnsStyles: ColumnsStylesInterface) => {
21
+ key: string;
22
+ headerText: string;
23
+ width: number;
24
+ style: {
25
+ numFmt: string;
26
+ font: Partial<Excel.Font>;
27
+ alignment: Partial<Excel.Alignment>;
28
+ protection: Partial<Excel.Protection>;
29
+ border: Partial<Excel.Borders>;
30
+ fill: Excel.Fill;
31
+ };
32
+ };
33
+ type SerializedColumns = Array<{
34
+ key: string;
35
+ width: number;
36
+ style: Excel.Style;
37
+ headerText: string;
38
+ }>;
39
+ export declare function serializeColumns(columns: GridStateColDef[], styles: ColumnsStylesInterface): SerializedColumns;
40
+ type ValueOptionsData = Record<string, {
41
+ values: (string | number)[];
42
+ address: string;
43
+ }>;
44
+ export declare function getDataForValueOptionsSheet(columns: GridStateColDef[], valueOptionsSheetName: string, api: GridPrivateApiPremium): Promise<ValueOptionsData>;
6
45
  interface BuildExcelOptions {
7
46
  columns: GridStateColDef[];
8
47
  rowIds: GridRowId[];
@@ -14,4 +53,14 @@ interface BuildExcelOptions {
14
53
  columnsStyles?: ColumnsStylesInterface;
15
54
  }
16
55
  export declare function buildExcel(options: BuildExcelOptions, api: GridPrivateApiPremium): Promise<Excel.Workbook>;
56
+ export interface ExcelExportInitEvent {
57
+ serializedColumns: SerializedColumns;
58
+ serializedRows: SerializedRow[];
59
+ valueOptionsSheetName: string;
60
+ columnGroupPaths: Record<string, string[]>;
61
+ columnGroupDetails: GridColumnGroupLookup;
62
+ valueOptionsData: ValueOptionsData;
63
+ options: Omit<GridExcelExportOptions, 'exceljsPreProcess' | 'exceljsPostProcess' | 'columnsStyles' | 'valueOptionsSheetName'>;
64
+ }
65
+ export declare function setupExcelExportWebWorker(workerOptions?: Pick<GridExcelExportOptions, 'exceljsPostProcess' | 'exceljsPreProcess'>): void;
17
66
  export {};
@@ -27,7 +27,7 @@ const getFormattedValueOptions = (colDef, valueOptions, api) => {
27
27
  }
28
28
  return valueOptionsFormatted.map(option => typeof option === 'object' ? option.label : option);
29
29
  };
30
- const serializeRow = (id, columns, api, defaultValueOptionsFormulae) => {
30
+ export const serializeRow = (id, columns, api, defaultValueOptionsFormulae) => {
31
31
  const row = {};
32
32
  const dataValidation = {};
33
33
  const mergedCells = [];
@@ -72,11 +72,13 @@ const serializeRow = (id, columns, api, defaultValueOptionsFormulae) => {
72
72
  formulae: [`"${formattedValueOptions.map(x => x.toString().replaceAll(',', 'CHAR(44)')).join(',')}"`]
73
73
  };
74
74
  } else {
75
+ const address = defaultValueOptionsFormulae[column.field].address;
76
+
75
77
  // If value option is defined for the column, refer to another sheet
76
78
  dataValidation[castColumn.field] = {
77
79
  type: 'list',
78
80
  allowBlank: true,
79
- formulae: [defaultValueOptionsFormulae[castColumn.field]]
81
+ formulae: [address]
80
82
  };
81
83
  }
82
84
  const formattedValue = api.getCellParams(id, castColumn.field).formattedValue;
@@ -138,13 +140,15 @@ const defaultColumnsStyles = {
138
140
  numFmt: 'dd.mm.yyyy hh:mm'
139
141
  }
140
142
  };
141
- const serializeColumn = (column, columnsStyles) => {
143
+ export const serializeColumn = (column, columnsStyles) => {
144
+ var _column$headerName;
142
145
  const {
143
146
  field,
144
147
  type
145
148
  } = column;
146
149
  return {
147
150
  key: field,
151
+ headerText: (_column$headerName = column.headerName) != null ? _column$headerName : column.field,
148
152
  // Excel width must stay between 0 and 255 (https://support.microsoft.com/en-us/office/change-the-column-width-and-row-height-72f5e3cc-994d-43e8-ae58-9774a0905f46)
149
153
  // From the example of column width behavior (https://docs.microsoft.com/en-US/office/troubleshoot/excel/determine-column-widths#example-of-column-width-behavior)
150
154
  // a value of 10 corresponds to 75px. This is an approximation, because column width depends on the the font-size
@@ -152,22 +156,21 @@ const serializeColumn = (column, columnsStyles) => {
152
156
  style: _extends({}, type && (defaultColumnsStyles == null ? void 0 : defaultColumnsStyles[type]), columnsStyles == null ? void 0 : columnsStyles[field])
153
157
  };
154
158
  };
155
- const addColumnGroupingHeaders = (worksheet, columns, api) => {
159
+ const addColumnGroupingHeaders = (worksheet, columns, columnGroupPaths, columnGroupDetails) => {
156
160
  const maxDepth = Math.max(...columns.map(({
157
- field
161
+ key
158
162
  }) => {
159
- var _api$unstable_getColu, _api$unstable_getColu2;
160
- return (_api$unstable_getColu = (_api$unstable_getColu2 = api.unstable_getColumnGroupPath(field)) == null ? void 0 : _api$unstable_getColu2.length) != null ? _api$unstable_getColu : 0;
163
+ var _columnGroupPaths$key, _columnGroupPaths$key2;
164
+ return (_columnGroupPaths$key = (_columnGroupPaths$key2 = columnGroupPaths[key]) == null ? void 0 : _columnGroupPaths$key2.length) != null ? _columnGroupPaths$key : 0;
161
165
  }));
162
166
  if (maxDepth === 0) {
163
167
  return;
164
168
  }
165
- const columnGroupDetails = api.unstable_getAllGroupDetails();
166
169
  for (let rowIndex = 0; rowIndex < maxDepth; rowIndex += 1) {
167
170
  const row = columns.map(({
168
- field
171
+ key
169
172
  }) => {
170
- const groupingPath = api.unstable_getColumnGroupPath(field);
173
+ const groupingPath = columnGroupPaths[key];
171
174
  if (groupingPath.length <= rowIndex) {
172
175
  return {
173
176
  groupId: null,
@@ -212,13 +215,76 @@ const addColumnGroupingHeaders = (worksheet, columns, api) => {
212
215
  }
213
216
  }
214
217
  };
218
+ export function serializeColumns(columns, styles) {
219
+ return columns.map(column => serializeColumn(column, styles));
220
+ }
221
+ export async function getDataForValueOptionsSheet(columns, valueOptionsSheetName, api) {
222
+ const candidateColumns = columns.filter(column => isSingleSelectColDef(column) && Array.isArray(column.valueOptions));
223
+
224
+ // Creates a temp worksheet to obtain the column letters
225
+ const excelJS = await getExcelJs();
226
+ const workbook = new excelJS.Workbook();
227
+ const worksheet = workbook.addWorksheet('Sheet1');
228
+ worksheet.columns = candidateColumns.map(column => ({
229
+ key: column.field
230
+ }));
231
+ return candidateColumns.reduce((acc, column) => {
232
+ var _column$headerName2;
233
+ const singleSelectColumn = column;
234
+ const formattedValueOptions = getFormattedValueOptions(singleSelectColumn, singleSelectColumn.valueOptions, api);
235
+ const header = (_column$headerName2 = column.headerName) != null ? _column$headerName2 : column.field;
236
+ const values = [header, ...formattedValueOptions];
237
+ const letter = worksheet.getColumn(column.field).letter;
238
+ const address = `${valueOptionsSheetName}!$${letter}$2:$${letter}$${values.length}`;
239
+ acc[column.field] = {
240
+ values,
241
+ address
242
+ };
243
+ return acc;
244
+ }, {});
245
+ }
246
+ function addSerializedRowToWorksheet(serializedRow, worksheet) {
247
+ const {
248
+ row,
249
+ dataValidation,
250
+ outlineLevel,
251
+ mergedCells
252
+ } = serializedRow;
253
+ const newRow = worksheet.addRow(row);
254
+ Object.keys(dataValidation).forEach(field => {
255
+ newRow.getCell(field).dataValidation = _extends({}, dataValidation[field]);
256
+ });
257
+ if (outlineLevel) {
258
+ newRow.outlineLevel = outlineLevel;
259
+ }
260
+
261
+ // use `rowCount`, since worksheet can have additional rows added in `exceljsPreProcess`
262
+ const lastRowIndex = newRow.worksheet.rowCount;
263
+ mergedCells.forEach(mergedCell => {
264
+ worksheet.mergeCells(lastRowIndex, mergedCell.leftIndex, lastRowIndex, mergedCell.rightIndex);
265
+ });
266
+ }
267
+ async function createValueOptionsSheetIfNeeded(valueOptionsData, sheetName, workbook) {
268
+ if (Object.keys(valueOptionsData).length === 0) {
269
+ return;
270
+ }
271
+ const valueOptionsWorksheet = workbook.addWorksheet(sheetName);
272
+ valueOptionsWorksheet.columns = Object.keys(valueOptionsData).map(key => ({
273
+ key
274
+ }));
275
+ Object.entries(valueOptionsData).forEach(([field, {
276
+ values
277
+ }]) => {
278
+ valueOptionsWorksheet.getColumn(field).values = values;
279
+ });
280
+ }
215
281
  export async function buildExcel(options, api) {
216
282
  const {
217
283
  columns,
218
284
  rowIds,
219
285
  includeHeaders,
220
286
  includeColumnGroupsHeaders,
221
- valueOptionsSheetName,
287
+ valueOptionsSheetName = 'Options',
222
288
  exceljsPreProcess,
223
289
  exceljsPostProcess,
224
290
  columnsStyles = {}
@@ -226,7 +292,8 @@ export async function buildExcel(options, api) {
226
292
  const excelJS = await getExcelJs();
227
293
  const workbook = new excelJS.Workbook();
228
294
  const worksheet = workbook.addWorksheet('Sheet1');
229
- worksheet.columns = columns.map(column => serializeColumn(column, columnsStyles));
295
+ const serializedColumns = serializeColumns(columns, columnsStyles);
296
+ worksheet.columns = serializedColumns;
230
297
  if (exceljsPreProcess) {
231
298
  await exceljsPreProcess({
232
299
  workbook,
@@ -234,51 +301,23 @@ export async function buildExcel(options, api) {
234
301
  });
235
302
  }
236
303
  if (includeColumnGroupsHeaders) {
237
- addColumnGroupingHeaders(worksheet, columns, api);
304
+ const columnGroupPaths = columns.reduce((acc, column) => {
305
+ acc[column.field] = api.unstable_getColumnGroupPath(column.field);
306
+ return acc;
307
+ }, {});
308
+ addColumnGroupingHeaders(worksheet, serializedColumns, columnGroupPaths, api.unstable_getAllGroupDetails());
238
309
  }
239
310
  if (includeHeaders) {
240
311
  worksheet.addRow(columns.map(column => {
241
- var _column$headerName;
242
- return (_column$headerName = column.headerName) != null ? _column$headerName : column.field;
312
+ var _column$headerName3;
313
+ return (_column$headerName3 = column.headerName) != null ? _column$headerName3 : column.field;
243
314
  }));
244
315
  }
245
- const columnsWithArrayValueOptions = columns.filter(column => isSingleSelectColDef(column) && column.valueOptions && typeof column.valueOptions !== 'function');
246
- const defaultValueOptionsFormulae = {};
247
- if (columnsWithArrayValueOptions.length) {
248
- const valueOptionsWorksheet = workbook.addWorksheet(valueOptionsSheetName);
249
- valueOptionsWorksheet.columns = columnsWithArrayValueOptions.map(({
250
- field
251
- }) => ({
252
- key: field
253
- }));
254
- columnsWithArrayValueOptions.forEach(column => {
255
- var _column$headerName2;
256
- const formattedValueOptions = getFormattedValueOptions(column, column.valueOptions, api);
257
- valueOptionsWorksheet.getColumn(column.field).values = [(_column$headerName2 = column.headerName) != null ? _column$headerName2 : column.field, ...formattedValueOptions];
258
- const columnLetter = valueOptionsWorksheet.getColumn(column.field).letter;
259
- defaultValueOptionsFormulae[column.field] = `${valueOptionsSheetName}!$${columnLetter}$2:$${columnLetter}$${1 + formattedValueOptions.length}`;
260
- });
261
- }
316
+ const valueOptionsData = await getDataForValueOptionsSheet(columns, valueOptionsSheetName, api);
317
+ createValueOptionsSheetIfNeeded(valueOptionsData, valueOptionsSheetName, workbook);
262
318
  rowIds.forEach(id => {
263
- const {
264
- row,
265
- dataValidation,
266
- outlineLevel,
267
- mergedCells
268
- } = serializeRow(id, columns, api, defaultValueOptionsFormulae);
269
- const newRow = worksheet.addRow(row);
270
- Object.keys(dataValidation).forEach(field => {
271
- newRow.getCell(field).dataValidation = _extends({}, dataValidation[field]);
272
- });
273
- if (outlineLevel) {
274
- newRow.outlineLevel = outlineLevel;
275
- }
276
-
277
- // use `rowCount`, since worksheet can have additional rows added in `exceljsPreProcess`
278
- const lastRowIndex = newRow.worksheet.rowCount;
279
- mergedCells.forEach(mergedCell => {
280
- worksheet.mergeCells(lastRowIndex, mergedCell.leftIndex, lastRowIndex, mergedCell.rightIndex);
281
- });
319
+ const serializedRow = serializeRow(id, columns, api, valueOptionsData);
320
+ addSerializedRowToWorksheet(serializedRow, worksheet);
282
321
  });
283
322
  if (exceljsPostProcess) {
284
323
  await exceljsPostProcess({
@@ -287,4 +326,51 @@ export async function buildExcel(options, api) {
287
326
  });
288
327
  }
289
328
  return workbook;
329
+ }
330
+ export function setupExcelExportWebWorker(workerOptions = {}) {
331
+ // eslint-disable-next-line no-restricted-globals
332
+ addEventListener('message', async event => {
333
+ var _options$includeHeade;
334
+ const {
335
+ serializedColumns,
336
+ serializedRows,
337
+ options,
338
+ valueOptionsSheetName,
339
+ valueOptionsData,
340
+ columnGroupDetails,
341
+ columnGroupPaths
342
+ } = event.data;
343
+ const {
344
+ exceljsPostProcess,
345
+ exceljsPreProcess
346
+ } = workerOptions;
347
+ const excelJS = await getExcelJs();
348
+ const workbook = new excelJS.Workbook();
349
+ const worksheet = workbook.addWorksheet('Sheet1');
350
+ worksheet.columns = serializedColumns;
351
+ if (exceljsPreProcess) {
352
+ await exceljsPreProcess({
353
+ workbook,
354
+ worksheet
355
+ });
356
+ }
357
+ if (options.includeColumnGroupsHeaders) {
358
+ addColumnGroupingHeaders(worksheet, serializedColumns, columnGroupPaths, columnGroupDetails);
359
+ }
360
+ const includeHeaders = (_options$includeHeade = options.includeHeaders) != null ? _options$includeHeade : true;
361
+ if (includeHeaders) {
362
+ worksheet.addRow(serializedColumns.map(column => column.headerText));
363
+ }
364
+ createValueOptionsSheetIfNeeded(valueOptionsData, valueOptionsSheetName, workbook);
365
+ serializedRows.forEach(serializedRow => {
366
+ addSerializedRowToWorksheet(serializedRow, worksheet);
367
+ });
368
+ if (exceljsPostProcess) {
369
+ await exceljsPostProcess({
370
+ workbook,
371
+ worksheet
372
+ });
373
+ }
374
+ postMessage(await workbook.xlsx.writeBuffer());
375
+ });
290
376
  }
@@ -1,5 +1,6 @@
1
1
  import * as React from 'react';
2
2
  import { GridPrivateApiPremium } from '../../../models/gridApiPremium';
3
+ import { DataGridPremiumProps } from '../../../models/dataGridPremiumProps';
3
4
  /**
4
5
  * @requires useGridColumns (state)
5
6
  * @requires useGridFilter (state)
@@ -7,4 +8,4 @@ import { GridPrivateApiPremium } from '../../../models/gridApiPremium';
7
8
  * @requires useGridSelection (state)
8
9
  * @requires useGridParamsApi (method)
9
10
  */
10
- export declare const useGridExcelExport: (apiRef: React.MutableRefObject<GridPrivateApiPremium>) => void;
11
+ export declare const useGridExcelExport: (apiRef: React.MutableRefObject<GridPrivateApiPremium>, props: DataGridPremiumProps) => void;
@@ -1,7 +1,9 @@
1
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
+ const _excluded = ["worker", "exceljsPostProcess", "exceljsPreProcess", "columnsStyles", "includeHeaders", "getRowsToExport", "valueOptionsSheetName"];
1
3
  import * as React from 'react';
2
- import { useGridApiMethod, useGridLogger } from '@mui/x-data-grid';
4
+ import { useGridApiMethod, useGridLogger, useGridApiOptionHandler } from '@mui/x-data-grid';
3
5
  import { useGridRegisterPipeProcessor, exportAs, getColumnsToExport, defaultGetRowsToExport } from '@mui/x-data-grid/internals';
4
- import { buildExcel } from './serializer/excelSerializer';
6
+ import { buildExcel, getDataForValueOptionsSheet, serializeColumns, serializeRow } from './serializer/excelSerializer';
5
7
  import { GridExcelExportMenuItem } from '../../../components';
6
8
 
7
9
  /**
@@ -12,7 +14,7 @@ import { GridExcelExportMenuItem } from '../../../components';
12
14
  * @requires useGridParamsApi (method)
13
15
  */
14
16
  import { jsx as _jsx } from "react/jsx-runtime";
15
- export const useGridExcelExport = apiRef => {
17
+ export const useGridExcelExport = (apiRef, props) => {
16
18
  const logger = useGridLogger(apiRef, 'useGridExcelExport');
17
19
  const getDataAsExcel = React.useCallback((options = {}) => {
18
20
  var _options$getRowsToExp, _options$includeHeade, _options$includeColum;
@@ -36,18 +38,70 @@ export const useGridExcelExport = apiRef => {
36
38
  exceljsPostProcess: options == null ? void 0 : options.exceljsPostProcess
37
39
  }, apiRef.current);
38
40
  }, [logger, apiRef]);
39
- const exportDataAsExcel = React.useCallback(async options => {
40
- logger.debug(`Export data as excel`);
41
- const workbook = await getDataAsExcel(options);
42
- if (workbook === null) {
41
+ const exportDataAsExcel = React.useCallback(async (options = {}) => {
42
+ const {
43
+ worker: workerFn,
44
+ exceljsPostProcess,
45
+ exceljsPreProcess,
46
+ getRowsToExport = defaultGetRowsToExport,
47
+ valueOptionsSheetName = 'Options'
48
+ } = options,
49
+ cloneableOptions = _objectWithoutPropertiesLoose(options, _excluded);
50
+ const sendExcelToUser = buffer => {
51
+ const blob = new Blob([buffer], {
52
+ type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
53
+ });
54
+ exportAs(blob, 'xlsx', options == null ? void 0 : options.fileName);
55
+ };
56
+ if (!workerFn) {
57
+ apiRef.current.publishEvent('excelExportStateChange', 'pending');
58
+ const workbook = await getDataAsExcel(options);
59
+ if (workbook === null) {
60
+ return;
61
+ }
62
+ const content = await workbook.xlsx.writeBuffer();
63
+ apiRef.current.publishEvent('excelExportStateChange', 'finished');
64
+ sendExcelToUser(content);
43
65
  return;
44
66
  }
45
- const content = await workbook.xlsx.writeBuffer();
46
- const blob = new Blob([content], {
47
- type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
67
+ if (exceljsPostProcess && process.env.NODE_ENV !== 'production') {
68
+ console.warn([`MUI: The exceljsPostProcess option is not supported when a web worker is used.`, 'As alternative, pass the callback to the same option in setupExcelExportWebWorker.'].join('\n'));
69
+ }
70
+ if (exceljsPreProcess && process.env.NODE_ENV !== 'production') {
71
+ console.warn([`MUI: The exceljsPreProcess option is not supported when a web worker is used.`, 'As alternative, pass the callback to the same option in setupExcelExportWebWorker.'].join('\n'));
72
+ }
73
+ const worker = workerFn();
74
+ apiRef.current.publishEvent('excelExportStateChange', 'pending');
75
+ worker.onmessage = async event => {
76
+ sendExcelToUser(event.data);
77
+ apiRef.current.publishEvent('excelExportStateChange', 'finished');
78
+ worker.terminate();
79
+ };
80
+ const exportedRowIds = getRowsToExport({
81
+ apiRef
82
+ });
83
+ const exportedColumns = getColumnsToExport({
84
+ apiRef,
85
+ options
48
86
  });
49
- exportAs(blob, 'xlsx', options == null ? void 0 : options.fileName);
50
- }, [logger, getDataAsExcel]);
87
+ const valueOptionsData = await getDataForValueOptionsSheet(exportedColumns, valueOptionsSheetName, apiRef.current);
88
+ const serializedColumns = serializeColumns(exportedColumns, options.columnsStyles || {});
89
+ const serializedRows = exportedRowIds.map(id => serializeRow(id, exportedColumns, apiRef.current, valueOptionsData));
90
+ const columnGroupPaths = exportedColumns.reduce((acc, column) => {
91
+ acc[column.field] = apiRef.current.unstable_getColumnGroupPath(column.field);
92
+ return acc;
93
+ }, {});
94
+ const message = {
95
+ serializedColumns,
96
+ serializedRows,
97
+ valueOptionsData,
98
+ columnGroupPaths,
99
+ columnGroupDetails: apiRef.current.unstable_getAllGroupDetails(),
100
+ options: cloneableOptions,
101
+ valueOptionsSheetName
102
+ };
103
+ worker.postMessage(message);
104
+ }, [apiRef, getDataAsExcel]);
51
105
  const excelExportApi = {
52
106
  getDataAsExcel,
53
107
  exportDataAsExcel
@@ -70,4 +124,5 @@ export const useGridExcelExport = apiRef => {
70
124
  }];
71
125
  }, []);
72
126
  useGridRegisterPipeProcessor(apiRef, 'exportMenu', addExportMenuButtons);
127
+ useGridApiOptionHandler(apiRef, 'excelExportStateChange', props.onExcelExportStateChange);
73
128
  };
@@ -8,4 +8,4 @@ export declare const rowGroupingStateInitializer: GridStateInitializer<Pick<Data
8
8
  * @requires useGridRows (state, method) - can be after, async only
9
9
  * @requires useGridParamsApi (method) - can be after, async only
10
10
  */
11
- export declare const useGridRowGrouping: (apiRef: React.MutableRefObject<GridPrivateApiPremium>, props: Pick<DataGridPremiumProcessedProps, 'initialState' | 'rowGroupingModel' | 'onRowGroupingModelChange' | 'defaultGroupingExpansionDepth' | 'isGroupExpandedByDefault' | 'groupingColDef' | 'rowGroupingColumnMode' | 'disableRowGrouping' | 'componentsProps' | 'components'>) => void;
11
+ export declare const useGridRowGrouping: (apiRef: React.MutableRefObject<GridPrivateApiPremium>, props: Pick<DataGridPremiumProcessedProps, 'initialState' | 'rowGroupingModel' | 'onRowGroupingModelChange' | 'defaultGroupingExpansionDepth' | 'isGroupExpandedByDefault' | 'groupingColDef' | 'rowGroupingColumnMode' | 'disableRowGrouping' | 'slotProps' | 'slots'>) => void;
package/index.d.ts CHANGED
@@ -16,6 +16,7 @@ export * from './DataGridPremium';
16
16
  export * from './hooks';
17
17
  export * from './models';
18
18
  export * from './components';
19
+ export { GridColumnHeaders } from '@mui/x-data-grid-pro';
19
20
  export type { DataGridPremiumProps, GridExperimentalPremiumFeatures, } from './models/dataGridPremiumProps';
20
21
  export { useGridApiContext, useGridApiRef, useGridRootProps } from './typeOverloads/reexports';
21
22
  export type { GridApi, GridInitialState, GridState } from './typeOverloads/reexports';
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-data-grid-premium v6.0.0-beta.4
2
+ * @mui/x-data-grid-premium v6.0.0
3
3
  *
4
4
  * @license MUI X Commercial
5
5
  * This source code is licensed under the commercial license found in the
@@ -23,5 +23,6 @@ export * from './DataGridPremium';
23
23
  export * from './hooks';
24
24
  export * from './models';
25
25
  export * from './components';
26
+ export { GridColumnHeaders } from '@mui/x-data-grid-pro';
26
27
  export { useGridApiContext, useGridApiRef, useGridRootProps } from './typeOverloads/reexports';
27
28
  export { GridColumnMenu, GRID_COLUMN_MENU_COMPONENTS, GRID_COLUMN_MENU_COMPONENTS_PROPS } from './components/reexports';
@@ -2,8 +2,8 @@ import * as React from 'react';
2
2
  import PropTypes from 'prop-types';
3
3
  import { useLicenseVerifier, Watermark } from '@mui/x-license-pro';
4
4
  import { chainPropTypes } from '@mui/utils';
5
- import { GridBody, GridFooterPlaceholder, GridHeader, GridRoot, GridContextProvider } from '@mui/x-data-grid-pro';
6
- import { DataGridProVirtualScroller, DataGridProColumnHeaders } from '@mui/x-data-grid-pro/internals';
5
+ import { GridBody, GridFooterPlaceholder, GridHeader, GridRoot, GridContextProvider, useGridSelector, gridPinnedColumnsSelector } from '@mui/x-data-grid-pro';
6
+ import { DataGridProVirtualScroller } from '@mui/x-data-grid-pro/internals';
7
7
  import { useDataGridPremiumComponent } from './useDataGridPremiumComponent';
8
8
  import { useDataGridPremiumProps } from './useDataGridPremiumProps';
9
9
  import { getReleaseInfo } from '../utils/releaseInfo';
@@ -14,6 +14,7 @@ var DataGridPremiumRaw = /*#__PURE__*/React.forwardRef(function DataGridPremium(
14
14
  var props = useDataGridPremiumProps(inProps);
15
15
  var privateApiRef = useDataGridPremiumComponent(props.apiRef, props);
16
16
  useLicenseVerifier('x-data-grid-premium', releaseInfo);
17
+ var pinnedColumns = useGridSelector(privateApiRef, gridPinnedColumnsSelector);
17
18
  return /*#__PURE__*/_jsx(GridContextProvider, {
18
19
  privateApiRef: privateApiRef,
19
20
  props: props,
@@ -23,8 +24,10 @@ var DataGridPremiumRaw = /*#__PURE__*/React.forwardRef(function DataGridPremium(
23
24
  sx: props.sx,
24
25
  ref: ref,
25
26
  children: [/*#__PURE__*/_jsx(GridHeader, {}), /*#__PURE__*/_jsx(GridBody, {
26
- ColumnHeadersComponent: DataGridProColumnHeaders,
27
27
  VirtualScrollerComponent: DataGridProVirtualScroller,
28
+ ColumnHeadersProps: {
29
+ pinnedColumns: pinnedColumns
30
+ },
28
31
  children: /*#__PURE__*/_jsx(Watermark, {
29
32
  packageName: "x-data-grid-premium",
30
33
  releaseInfo: releaseInfo
@@ -130,10 +133,12 @@ process.env.NODE_ENV !== "production" ? DataGridPremiumRaw.propTypes = {
130
133
  columnVisibilityModel: PropTypes.object,
131
134
  /**
132
135
  * Overrideable components.
136
+ * @deprecated Use the `slots` prop instead.
133
137
  */
134
138
  components: PropTypes.object,
135
139
  /**
136
140
  * Overrideable components props dynamically passed to the component at rendering.
141
+ * @deprecated Use the `slotProps` prop instead.
137
142
  */
138
143
  componentsProps: PropTypes.object,
139
144
  /**
@@ -243,7 +248,6 @@ process.env.NODE_ENV !== "production" ? DataGridPremiumRaw.propTypes = {
243
248
  experimentalFeatures: PropTypes.shape({
244
249
  columnGrouping: PropTypes.bool,
245
250
  lazyLoading: PropTypes.bool,
246
- rowPinning: PropTypes.bool,
247
251
  warnIfFocusStateIsNotSynced: PropTypes.bool
248
252
  }),
249
253
  /**
@@ -552,6 +556,11 @@ process.env.NODE_ENV !== "production" ? DataGridPremiumRaw.propTypes = {
552
556
  * @param {GridCallbackDetails} details Additional details for this callback.
553
557
  */
554
558
  onDetailPanelExpandedRowIdsChange: PropTypes.func,
559
+ /**
560
+ * Callback fired when the state of the Excel export changes.
561
+ * @param {string} inProgress Indicates if the task is in progress.
562
+ */
563
+ onExcelExportStateChange: PropTypes.func,
555
564
  /**
556
565
  * Callback fired when rowCount is set and the next batch of virtualized rows is rendered.
557
566
  * @param {GridFetchRowsParams} params With all properties from [[GridFetchRowsParams]].
@@ -825,6 +834,14 @@ process.env.NODE_ENV !== "production" ? DataGridPremiumRaw.propTypes = {
825
834
  * @default false
826
835
  */
827
836
  showColumnVerticalBorder: PropTypes.bool,
837
+ /**
838
+ * Overrideable components props dynamically passed to the component at rendering.
839
+ */
840
+ slotProps: PropTypes.object,
841
+ /**
842
+ * Overrideable components.
843
+ */
844
+ slots: PropTypes.object,
828
845
  /**
829
846
  * Sorting can be processed on the server or client-side.
830
847
  * Set it to 'client' if you would like to handle sorting on the client-side.
@@ -80,7 +80,7 @@ export var useDataGridPremiumComponent = function useDataGridPremiumComponent(in
80
80
  useGridColumnMenu(privateApiRef);
81
81
  useGridCsvExport(privateApiRef);
82
82
  useGridPrintExport(privateApiRef, props);
83
- useGridExcelExport(privateApiRef);
83
+ useGridExcelExport(privateApiRef, props);
84
84
  useGridClipboard(privateApiRef);
85
85
  useGridDimensions(privateApiRef, props);
86
86
  useGridEvents(privateApiRef, props);