@mui/x-data-grid-premium 5.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4052 -0
- package/DataGridPremium/DataGridPremium.d.ts +9 -0
- package/DataGridPremium/DataGridPremium.js +986 -0
- package/DataGridPremium/index.d.ts +2 -0
- package/DataGridPremium/index.js +2 -0
- package/DataGridPremium/package.json +6 -0
- package/DataGridPremium/useDataGridPremiumComponent.d.ts +4 -0
- package/DataGridPremium/useDataGridPremiumComponent.js +78 -0
- package/DataGridPremium/useDataGridPremiumProps.d.ts +6 -0
- package/DataGridPremium/useDataGridPremiumProps.js +37 -0
- package/LICENSE +12 -0
- package/README.md +31 -0
- package/components/GridExcelExportMenuItem.d.ts +9 -0
- package/components/GridExcelExportMenuItem.js +32 -0
- package/components/GridGroupingColumnLeafCell.d.ts +4 -0
- package/components/GridGroupingColumnLeafCell.js +22 -0
- package/components/GridGroupingCriteriaCell.d.ts +7 -0
- package/components/GridGroupingCriteriaCell.js +78 -0
- package/components/GridRowGroupableColumnMenuItems.d.ts +11 -0
- package/components/GridRowGroupableColumnMenuItems.js +63 -0
- package/components/GridRowGroupingColumnMenuItems.d.ts +11 -0
- package/components/GridRowGroupingColumnMenuItems.js +58 -0
- package/components/index.d.ts +1 -0
- package/components/index.js +1 -0
- package/components/package.json +6 -0
- package/hooks/features/export/gridExcelExportInterface.d.ts +58 -0
- package/hooks/features/export/gridExcelExportInterface.js +1 -0
- package/hooks/features/export/index.d.ts +1 -0
- package/hooks/features/export/index.js +1 -0
- package/hooks/features/export/serializer/excelSerializer.d.ts +14 -0
- package/hooks/features/export/serializer/excelSerializer.js +218 -0
- package/hooks/features/export/useGridExcelExport.d.ts +10 -0
- package/hooks/features/export/useGridExcelExport.js +77 -0
- package/hooks/features/index.d.ts +2 -0
- package/hooks/features/index.js +3 -0
- package/hooks/features/rowGrouping/createGroupingColDef.d.ts +42 -0
- package/hooks/features/rowGrouping/createGroupingColDef.js +318 -0
- package/hooks/features/rowGrouping/gridRowGroupingInterfaces.d.ts +37 -0
- package/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +1 -0
- package/hooks/features/rowGrouping/gridRowGroupingSelector.d.ts +4 -0
- package/hooks/features/rowGrouping/gridRowGroupingSelector.js +5 -0
- package/hooks/features/rowGrouping/gridRowGroupingUtils.d.ts +27 -0
- package/hooks/features/rowGrouping/gridRowGroupingUtils.js +139 -0
- package/hooks/features/rowGrouping/index.d.ts +3 -0
- package/hooks/features/rowGrouping/index.js +3 -0
- package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +11 -0
- package/hooks/features/rowGrouping/useGridRowGrouping.js +200 -0
- package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.d.ts +4 -0
- package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +201 -0
- package/hooks/index.d.ts +2 -0
- package/hooks/index.js +3 -0
- package/hooks/package.json +6 -0
- package/hooks/utils/index.d.ts +1 -0
- package/hooks/utils/index.js +1 -0
- package/hooks/utils/useGridApiContext.d.ts +4 -0
- package/hooks/utils/useGridApiContext.js +2 -0
- package/hooks/utils/useGridApiRef.d.ts +4 -0
- package/hooks/utils/useGridApiRef.js +2 -0
- package/hooks/utils/useGridRootProps.d.ts +2 -0
- package/hooks/utils/useGridRootProps.js +2 -0
- package/hooks/utils/useKeepGroupedColumnsHidden.d.ts +12 -0
- package/hooks/utils/useKeepGroupedColumnsHidden.js +50 -0
- package/index.d.ts +22 -0
- package/index.js +25 -0
- package/legacy/DataGridPremium/DataGridPremium.js +986 -0
- package/legacy/DataGridPremium/index.js +2 -0
- package/legacy/DataGridPremium/useDataGridPremiumComponent.js +78 -0
- package/legacy/DataGridPremium/useDataGridPremiumProps.js +46 -0
- package/legacy/components/GridExcelExportMenuItem.js +30 -0
- package/legacy/components/GridGroupingColumnLeafCell.js +20 -0
- package/legacy/components/GridGroupingCriteriaCell.js +74 -0
- package/legacy/components/GridRowGroupableColumnMenuItems.js +61 -0
- package/legacy/components/GridRowGroupingColumnMenuItems.js +56 -0
- package/legacy/components/index.js +1 -0
- package/legacy/hooks/features/export/gridExcelExportInterface.js +1 -0
- package/legacy/hooks/features/export/index.js +1 -0
- package/legacy/hooks/features/export/serializer/excelSerializer.js +260 -0
- package/legacy/hooks/features/export/useGridExcelExport.js +111 -0
- package/legacy/hooks/features/index.js +3 -0
- package/legacy/hooks/features/rowGrouping/createGroupingColDef.js +319 -0
- package/legacy/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +1 -0
- package/legacy/hooks/features/rowGrouping/gridRowGroupingSelector.js +13 -0
- package/legacy/hooks/features/rowGrouping/gridRowGroupingUtils.js +147 -0
- package/legacy/hooks/features/rowGrouping/index.js +3 -0
- package/legacy/hooks/features/rowGrouping/useGridRowGrouping.js +206 -0
- package/legacy/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +215 -0
- package/legacy/hooks/index.js +3 -0
- package/legacy/hooks/utils/index.js +1 -0
- package/legacy/hooks/utils/useGridApiContext.js +2 -0
- package/legacy/hooks/utils/useGridApiRef.js +2 -0
- package/legacy/hooks/utils/useGridRootProps.js +2 -0
- package/legacy/hooks/utils/useKeepGroupedColumnsHidden.js +50 -0
- package/legacy/index.js +25 -0
- package/legacy/models/dataGridPremiumProps.js +1 -0
- package/legacy/models/gridApiPremium.js +1 -0
- package/legacy/models/gridGroupingValueGetterParams.js +1 -0
- package/legacy/models/gridStatePremium.js +1 -0
- package/legacy/models/index.js +1 -0
- package/legacy/typeOverloads/index.js +1 -0
- package/legacy/typeOverloads/modules.js +33 -0
- package/legacy/typeOverloads/reexports.js +6 -0
- package/legacy/utils/releaseInfo.js +15 -0
- package/models/dataGridPremiumProps.d.ts +64 -0
- package/models/dataGridPremiumProps.js +1 -0
- package/models/gridApiPremium.d.ts +13 -0
- package/models/gridApiPremium.js +1 -0
- package/models/gridGroupingValueGetterParams.d.ts +31 -0
- package/models/gridGroupingValueGetterParams.js +1 -0
- package/models/gridStatePremium.d.ts +14 -0
- package/models/gridStatePremium.js +1 -0
- package/models/index.d.ts +1 -0
- package/models/index.js +1 -0
- package/models/package.json +6 -0
- package/modern/DataGridPremium/DataGridPremium.js +986 -0
- package/modern/DataGridPremium/index.js +2 -0
- package/modern/DataGridPremium/useDataGridPremiumComponent.js +76 -0
- package/modern/DataGridPremium/useDataGridPremiumProps.js +37 -0
- package/modern/components/GridExcelExportMenuItem.js +32 -0
- package/modern/components/GridGroupingColumnLeafCell.js +20 -0
- package/modern/components/GridGroupingCriteriaCell.js +76 -0
- package/modern/components/GridRowGroupableColumnMenuItems.js +61 -0
- package/modern/components/GridRowGroupingColumnMenuItems.js +56 -0
- package/modern/components/index.js +1 -0
- package/modern/hooks/features/export/gridExcelExportInterface.js +1 -0
- package/modern/hooks/features/export/index.js +1 -0
- package/modern/hooks/features/export/serializer/excelSerializer.js +216 -0
- package/modern/hooks/features/export/useGridExcelExport.js +73 -0
- package/modern/hooks/features/index.js +3 -0
- package/modern/hooks/features/rowGrouping/createGroupingColDef.js +302 -0
- package/modern/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +1 -0
- package/modern/hooks/features/rowGrouping/gridRowGroupingSelector.js +5 -0
- package/modern/hooks/features/rowGrouping/gridRowGroupingUtils.js +137 -0
- package/modern/hooks/features/rowGrouping/index.js +3 -0
- package/modern/hooks/features/rowGrouping/useGridRowGrouping.js +192 -0
- package/modern/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +201 -0
- package/modern/hooks/index.js +3 -0
- package/modern/hooks/utils/index.js +1 -0
- package/modern/hooks/utils/useGridApiContext.js +2 -0
- package/modern/hooks/utils/useGridApiRef.js +2 -0
- package/modern/hooks/utils/useGridRootProps.js +2 -0
- package/modern/hooks/utils/useKeepGroupedColumnsHidden.js +46 -0
- package/modern/index.js +25 -0
- package/modern/models/dataGridPremiumProps.js +1 -0
- package/modern/models/gridApiPremium.js +1 -0
- package/modern/models/gridGroupingValueGetterParams.js +1 -0
- package/modern/models/gridStatePremium.js +1 -0
- package/modern/models/index.js +1 -0
- package/modern/typeOverloads/index.js +1 -0
- package/modern/typeOverloads/modules.js +33 -0
- package/modern/typeOverloads/reexports.js +6 -0
- package/modern/utils/releaseInfo.js +15 -0
- package/node/DataGridPremium/DataGridPremium.js +1009 -0
- package/node/DataGridPremium/index.js +30 -0
- package/node/DataGridPremium/useDataGridPremiumComponent.js +91 -0
- package/node/DataGridPremium/useDataGridPremiumProps.js +57 -0
- package/node/components/GridExcelExportMenuItem.js +49 -0
- package/node/components/GridGroupingColumnLeafCell.js +38 -0
- package/node/components/GridGroupingCriteriaCell.js +99 -0
- package/node/components/GridRowGroupableColumnMenuItems.js +82 -0
- package/node/components/GridRowGroupingColumnMenuItems.js +78 -0
- package/node/components/index.js +18 -0
- package/node/hooks/features/export/gridExcelExportInterface.js +5 -0
- package/node/hooks/features/export/index.js +18 -0
- package/node/hooks/features/export/serializer/excelSerializer.js +233 -0
- package/node/hooks/features/export/useGridExcelExport.js +95 -0
- package/node/hooks/features/index.js +31 -0
- package/node/hooks/features/rowGrouping/createGroupingColDef.js +341 -0
- package/node/hooks/features/rowGrouping/gridRowGroupingInterfaces.js +5 -0
- package/node/hooks/features/rowGrouping/gridRowGroupingSelector.js +18 -0
- package/node/hooks/features/rowGrouping/gridRowGroupingUtils.js +172 -0
- package/node/hooks/features/rowGrouping/index.js +51 -0
- package/node/hooks/features/rowGrouping/useGridRowGrouping.js +228 -0
- package/node/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +223 -0
- package/node/hooks/index.js +31 -0
- package/node/hooks/utils/index.js +18 -0
- package/node/hooks/utils/useGridApiContext.js +11 -0
- package/node/hooks/utils/useGridApiRef.js +11 -0
- package/node/hooks/utils/useGridRootProps.js +11 -0
- package/node/hooks/utils/useKeepGroupedColumnsHidden.js +66 -0
- package/node/index.js +272 -0
- package/node/models/dataGridPremiumProps.js +5 -0
- package/node/models/gridApiPremium.js +5 -0
- package/node/models/gridGroupingValueGetterParams.js +5 -0
- package/node/models/gridStatePremium.js +5 -0
- package/node/models/index.js +18 -0
- package/node/typeOverloads/index.js +3 -0
- package/node/typeOverloads/modules.js +34 -0
- package/node/typeOverloads/reexports.js +29 -0
- package/node/utils/releaseInfo.js +25 -0
- package/package.json +63 -0
- package/typeOverloads/index.d.ts +1 -0
- package/typeOverloads/index.js +1 -0
- package/typeOverloads/modules.d.ts +0 -0
- package/typeOverloads/modules.js +33 -0
- package/typeOverloads/package.json +6 -0
- package/typeOverloads/reexports.d.ts +22 -0
- package/typeOverloads/reexports.js +6 -0
- package/utils/releaseInfo.d.ts +1 -0
- package/utils/releaseInfo.js +15 -0
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { GRID_DATE_COL_DEF, GRID_DATETIME_COL_DEF } from '@mui/x-data-grid-pro';
|
|
3
|
+
import { buildWarning } from '@mui/x-data-grid/internals';
|
|
4
|
+
|
|
5
|
+
const getExcelJs = () => import('exceljs');
|
|
6
|
+
|
|
7
|
+
const warnInvalidFormattedValue = buildWarning(['MUI: When the value of a field is an object or a `renderCell` is provided, the Excel export might not display the value correctly.', 'You can provide a `valueFormatter` with a string representation to be used.']);
|
|
8
|
+
|
|
9
|
+
const getFormattedValueOptions = (colDef, valueOptions, api) => {
|
|
10
|
+
if (!colDef.valueOptions) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let valueOptionsFormatted = valueOptions;
|
|
15
|
+
|
|
16
|
+
if (colDef.valueFormatter) {
|
|
17
|
+
valueOptionsFormatted = valueOptionsFormatted.map(option => {
|
|
18
|
+
if (typeof option === 'object') {
|
|
19
|
+
return option;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const params = {
|
|
23
|
+
field: colDef.field,
|
|
24
|
+
api,
|
|
25
|
+
value: option
|
|
26
|
+
};
|
|
27
|
+
return String(colDef.valueFormatter(params));
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return valueOptionsFormatted.map(option => typeof option === 'object' ? option.label : option);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const serializeRow = (id, columns, api, defaultValueOptionsFormulae) => {
|
|
35
|
+
const row = {};
|
|
36
|
+
const dataValidation = {};
|
|
37
|
+
const firstCellParams = api.getCellParams(id, columns[0].field);
|
|
38
|
+
const outlineLevel = firstCellParams.rowNode.depth;
|
|
39
|
+
columns.forEach(column => {
|
|
40
|
+
const cellParams = api.getCellParams(id, column.field);
|
|
41
|
+
|
|
42
|
+
switch (cellParams.colDef.type) {
|
|
43
|
+
case 'singleSelect':
|
|
44
|
+
{
|
|
45
|
+
var _formattedValue$label;
|
|
46
|
+
|
|
47
|
+
if (typeof cellParams.colDef.valueOptions === 'function') {
|
|
48
|
+
// If value option depends on the row, set specific options to the cell
|
|
49
|
+
// This dataValidation is buggy with LibreOffice and does not allow to have coma
|
|
50
|
+
const valueOptions = cellParams.colDef.valueOptions({
|
|
51
|
+
id,
|
|
52
|
+
row,
|
|
53
|
+
field: cellParams.field
|
|
54
|
+
});
|
|
55
|
+
const formattedValueOptions = getFormattedValueOptions(cellParams.colDef, valueOptions, api);
|
|
56
|
+
dataValidation[column.field] = {
|
|
57
|
+
type: 'list',
|
|
58
|
+
allowBlank: true,
|
|
59
|
+
formulae: [`"${formattedValueOptions.map(x => x.toString().replaceAll(',', 'CHAR(44)')).join(',')}"`]
|
|
60
|
+
};
|
|
61
|
+
} else {
|
|
62
|
+
// If value option is defined for the column, refer to another sheet
|
|
63
|
+
dataValidation[column.field] = {
|
|
64
|
+
type: 'list',
|
|
65
|
+
allowBlank: true,
|
|
66
|
+
formulae: [defaultValueOptionsFormulae[column.field]]
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const formattedValue = api.getCellParams(id, column.field).formattedValue;
|
|
71
|
+
|
|
72
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
73
|
+
if (String(cellParams.formattedValue) === '[object Object]') {
|
|
74
|
+
warnInvalidFormattedValue();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
row[column.field] = (_formattedValue$label = formattedValue == null ? void 0 : formattedValue.label) != null ? _formattedValue$label : formattedValue;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
case 'boolean':
|
|
83
|
+
case 'number':
|
|
84
|
+
row[column.field] = api.getCellParams(id, column.field).value;
|
|
85
|
+
break;
|
|
86
|
+
|
|
87
|
+
case 'date':
|
|
88
|
+
case 'dateTime':
|
|
89
|
+
{
|
|
90
|
+
// Excel does not do any timezone conversion, so we create a date using UTC instead of local timezone
|
|
91
|
+
// Solution from: https://github.com/exceljs/exceljs/issues/486#issuecomment-432557582
|
|
92
|
+
// About Date.UTC(): https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC#exemples
|
|
93
|
+
const date = api.getCellParams(id, column.field).value; // value may be `undefined` in auto-generated grouping rows
|
|
94
|
+
|
|
95
|
+
if (!date) {
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const utcDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()));
|
|
100
|
+
row[column.field] = utcDate;
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
case 'actions':
|
|
105
|
+
break;
|
|
106
|
+
|
|
107
|
+
default:
|
|
108
|
+
row[column.field] = api.getCellParams(id, column.field).formattedValue;
|
|
109
|
+
|
|
110
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
111
|
+
if (String(cellParams.formattedValue) === '[object Object]') {
|
|
112
|
+
warnInvalidFormattedValue();
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
return {
|
|
120
|
+
row,
|
|
121
|
+
dataValidation,
|
|
122
|
+
outlineLevel
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
const defaultColumnsStyles = {
|
|
127
|
+
[GRID_DATE_COL_DEF.type]: {
|
|
128
|
+
numFmt: 'dd.mm.yyyy'
|
|
129
|
+
},
|
|
130
|
+
[GRID_DATETIME_COL_DEF.type]: {
|
|
131
|
+
numFmt: 'dd.mm.yyyy hh:mm'
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
const serializeColumn = (column, columnsStyles) => {
|
|
136
|
+
const {
|
|
137
|
+
field,
|
|
138
|
+
type
|
|
139
|
+
} = column;
|
|
140
|
+
return {
|
|
141
|
+
key: field,
|
|
142
|
+
// 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)
|
|
143
|
+
// From the example of column width behavior (https://docs.microsoft.com/en-US/office/troubleshoot/excel/determine-column-widths#example-of-column-width-behavior)
|
|
144
|
+
// a value of 10 corresponds to 75px. This is an approximation, because column width depends on the the font-size
|
|
145
|
+
width: Math.min(255, column.width ? column.width / 7.5 : 8.43),
|
|
146
|
+
style: _extends({}, type && (defaultColumnsStyles == null ? void 0 : defaultColumnsStyles[type]), columnsStyles == null ? void 0 : columnsStyles[field])
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export async function buildExcel(options, api) {
|
|
151
|
+
const {
|
|
152
|
+
columns,
|
|
153
|
+
rowIds,
|
|
154
|
+
includeHeaders,
|
|
155
|
+
valueOptionsSheetName,
|
|
156
|
+
exceljsPreProcess,
|
|
157
|
+
exceljsPostProcess,
|
|
158
|
+
columnsStyles = {}
|
|
159
|
+
} = options;
|
|
160
|
+
const excelJS = await getExcelJs();
|
|
161
|
+
const workbook = new excelJS.Workbook();
|
|
162
|
+
const worksheet = workbook.addWorksheet('Sheet1');
|
|
163
|
+
worksheet.columns = columns.map(column => serializeColumn(column, columnsStyles));
|
|
164
|
+
|
|
165
|
+
if (exceljsPreProcess) {
|
|
166
|
+
await exceljsPreProcess({
|
|
167
|
+
workbook,
|
|
168
|
+
worksheet
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (includeHeaders) {
|
|
173
|
+
worksheet.addRow(columns.map(column => column.headerName || column.field));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const columnsWithArrayValueOptions = columns.filter(column => column.type === 'singleSelect' && column.valueOptions && typeof column.valueOptions !== 'function');
|
|
177
|
+
const defaultValueOptionsFormulae = {};
|
|
178
|
+
|
|
179
|
+
if (columnsWithArrayValueOptions.length) {
|
|
180
|
+
const valueOptionsWorksheet = workbook.addWorksheet(valueOptionsSheetName);
|
|
181
|
+
valueOptionsWorksheet.columns = columnsWithArrayValueOptions.map(({
|
|
182
|
+
field
|
|
183
|
+
}) => ({
|
|
184
|
+
key: field
|
|
185
|
+
}));
|
|
186
|
+
columnsWithArrayValueOptions.forEach(column => {
|
|
187
|
+
const formattedValueOptions = getFormattedValueOptions(column, column.valueOptions, api);
|
|
188
|
+
valueOptionsWorksheet.getColumn(column.field).values = [column.headerName || column.field, ...formattedValueOptions];
|
|
189
|
+
const columnLetter = valueOptionsWorksheet.getColumn(column.field).letter;
|
|
190
|
+
defaultValueOptionsFormulae[column.field] = `${valueOptionsSheetName}!$${columnLetter}$2:$${columnLetter}$${1 + formattedValueOptions.length}`;
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
rowIds.forEach(id => {
|
|
195
|
+
const {
|
|
196
|
+
row,
|
|
197
|
+
dataValidation,
|
|
198
|
+
outlineLevel
|
|
199
|
+
} = serializeRow(id, columns, api, defaultValueOptionsFormulae);
|
|
200
|
+
const newRow = worksheet.addRow(row);
|
|
201
|
+
Object.keys(dataValidation).forEach(field => {
|
|
202
|
+
newRow.getCell(field).dataValidation = _extends({}, dataValidation[field]);
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
if (outlineLevel) {
|
|
206
|
+
newRow.outlineLevel = outlineLevel;
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
if (exceljsPostProcess) {
|
|
211
|
+
await exceljsPostProcess({
|
|
212
|
+
workbook,
|
|
213
|
+
worksheet
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
return workbook;
|
|
218
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { GridApiPremium } from '../../../models/gridApiPremium';
|
|
3
|
+
/**
|
|
4
|
+
* @requires useGridColumns (state)
|
|
5
|
+
* @requires useGridFilter (state)
|
|
6
|
+
* @requires useGridSorting (state)
|
|
7
|
+
* @requires useGridSelection (state)
|
|
8
|
+
* @requires useGridParamsApi (method)
|
|
9
|
+
*/
|
|
10
|
+
export declare const useGridExcelExport: (apiRef: React.MutableRefObject<GridApiPremium>) => void;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useGridApiMethod, useGridLogger } from '@mui/x-data-grid';
|
|
3
|
+
import { useGridRegisterPipeProcessor, exportAs, getColumnsToExport, defaultGetRowsToExport } from '@mui/x-data-grid/internals';
|
|
4
|
+
import { buildExcel } from './serializer/excelSerializer';
|
|
5
|
+
import { GridExcelExportMenuItem } from '../../../components';
|
|
6
|
+
/**
|
|
7
|
+
* @requires useGridColumns (state)
|
|
8
|
+
* @requires useGridFilter (state)
|
|
9
|
+
* @requires useGridSorting (state)
|
|
10
|
+
* @requires useGridSelection (state)
|
|
11
|
+
* @requires useGridParamsApi (method)
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
|
+
export const useGridExcelExport = apiRef => {
|
|
16
|
+
const logger = useGridLogger(apiRef, 'useGridExcelExport');
|
|
17
|
+
const getDataAsExcel = React.useCallback((options = {}) => {
|
|
18
|
+
var _options$getRowsToExp, _options$includeHeade;
|
|
19
|
+
|
|
20
|
+
logger.debug(`Get data as excel`);
|
|
21
|
+
const getRowsToExport = (_options$getRowsToExp = options.getRowsToExport) != null ? _options$getRowsToExp : defaultGetRowsToExport;
|
|
22
|
+
const exportedRowIds = getRowsToExport({
|
|
23
|
+
apiRef
|
|
24
|
+
});
|
|
25
|
+
const exportedColumns = getColumnsToExport({
|
|
26
|
+
apiRef,
|
|
27
|
+
options
|
|
28
|
+
});
|
|
29
|
+
return buildExcel({
|
|
30
|
+
columns: exportedColumns,
|
|
31
|
+
rowIds: exportedRowIds,
|
|
32
|
+
includeHeaders: (_options$includeHeade = options.includeHeaders) != null ? _options$includeHeade : true,
|
|
33
|
+
valueOptionsSheetName: (options == null ? void 0 : options.valueOptionsSheetName) || 'Options',
|
|
34
|
+
columnsStyles: options == null ? void 0 : options.columnsStyles,
|
|
35
|
+
exceljsPreProcess: options == null ? void 0 : options.exceljsPreProcess,
|
|
36
|
+
exceljsPostProcess: options == null ? void 0 : options.exceljsPostProcess
|
|
37
|
+
}, apiRef.current);
|
|
38
|
+
}, [logger, apiRef]);
|
|
39
|
+
const exportDataAsExcel = React.useCallback(async options => {
|
|
40
|
+
logger.debug(`Export data as excel`);
|
|
41
|
+
const workbook = await getDataAsExcel(options);
|
|
42
|
+
|
|
43
|
+
if (workbook === null) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const content = await workbook.xlsx.writeBuffer();
|
|
48
|
+
const blob = new Blob([content], {
|
|
49
|
+
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
50
|
+
});
|
|
51
|
+
exportAs(blob, 'xlsx', options == null ? void 0 : options.fileName);
|
|
52
|
+
}, [logger, getDataAsExcel]);
|
|
53
|
+
const excelExportApi = {
|
|
54
|
+
getDataAsExcel,
|
|
55
|
+
exportDataAsExcel
|
|
56
|
+
};
|
|
57
|
+
useGridApiMethod(apiRef, excelExportApi, 'GridExcelExportApi');
|
|
58
|
+
/**
|
|
59
|
+
* PRE-PROCESSING
|
|
60
|
+
*/
|
|
61
|
+
|
|
62
|
+
const addExportMenuButtons = React.useCallback((initialValue, options) => {
|
|
63
|
+
var _options$excelOptions;
|
|
64
|
+
|
|
65
|
+
if ((_options$excelOptions = options.excelOptions) != null && _options$excelOptions.disableToolbarButton) {
|
|
66
|
+
return initialValue;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return [...initialValue, {
|
|
70
|
+
component: /*#__PURE__*/_jsx(GridExcelExportMenuItem, {
|
|
71
|
+
options: options.excelOptions
|
|
72
|
+
}),
|
|
73
|
+
componentName: 'excelExport'
|
|
74
|
+
}];
|
|
75
|
+
}, []);
|
|
76
|
+
useGridRegisterPipeProcessor(apiRef, 'exportMenu', addExportMenuButtons);
|
|
77
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { GridColDef, GridStateColDef, GridGroupingColDefOverride } from '@mui/x-data-grid-pro';
|
|
3
|
+
import { GridColumnRawLookup } from '@mui/x-data-grid-pro/internals';
|
|
4
|
+
import { GridApiPremium } from '../../../models/gridApiPremium';
|
|
5
|
+
interface CreateGroupingColDefMonoCriteriaParams {
|
|
6
|
+
columnsLookup: GridColumnRawLookup;
|
|
7
|
+
/**
|
|
8
|
+
* The field from which we are grouping the rows.
|
|
9
|
+
*/
|
|
10
|
+
groupingCriteria: string;
|
|
11
|
+
/**
|
|
12
|
+
* The col def from which we are grouping the rows.
|
|
13
|
+
*/
|
|
14
|
+
groupedByColDef: GridColDef | GridStateColDef;
|
|
15
|
+
/**
|
|
16
|
+
* The col def properties the user wants to override.
|
|
17
|
+
* This value comes `prop.groupingColDef`.
|
|
18
|
+
*/
|
|
19
|
+
colDefOverride: GridGroupingColDefOverride | null | undefined;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Creates the `GridColDef` for a grouping column that only takes care of a single grouping criteria
|
|
23
|
+
*/
|
|
24
|
+
export declare const createGroupingColDefForOneGroupingCriteria: ({ columnsLookup, groupedByColDef, groupingCriteria, colDefOverride, }: CreateGroupingColDefMonoCriteriaParams) => GridColDef;
|
|
25
|
+
interface CreateGroupingColDefSeveralCriteriaParams {
|
|
26
|
+
apiRef: React.MutableRefObject<GridApiPremium>;
|
|
27
|
+
columnsLookup: GridColumnRawLookup;
|
|
28
|
+
/**
|
|
29
|
+
* The fields from which we are grouping the rows.
|
|
30
|
+
*/
|
|
31
|
+
rowGroupingModel: string[];
|
|
32
|
+
/**
|
|
33
|
+
* The col def properties the user wants to override.
|
|
34
|
+
* This value comes `prop.groupingColDef`.
|
|
35
|
+
*/
|
|
36
|
+
colDefOverride: GridGroupingColDefOverride | null | undefined;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Creates the `GridColDef` for a grouping column that takes care of all the grouping criteria
|
|
40
|
+
*/
|
|
41
|
+
export declare const createGroupingColDefForAllGroupingCriteria: ({ apiRef, columnsLookup, rowGroupingModel, colDefOverride, }: CreateGroupingColDefSeveralCriteriaParams) => GridColDef;
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
+
const _excluded = ["leafField", "mainGroupingCriteria", "hideDescendantCount"],
|
|
4
|
+
_excluded2 = ["leafField", "mainGroupingCriteria", "hideDescendantCount"];
|
|
5
|
+
import * as React from 'react';
|
|
6
|
+
import { GRID_STRING_COL_DEF } from '@mui/x-data-grid-pro';
|
|
7
|
+
import { GridGroupingCriteriaCell } from '../../../components/GridGroupingCriteriaCell';
|
|
8
|
+
import { GridGroupingColumnLeafCell } from '../../../components/GridGroupingColumnLeafCell';
|
|
9
|
+
import { getRowGroupingFieldFromGroupingCriteria, GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD } from './gridRowGroupingUtils';
|
|
10
|
+
import { gridRowGroupingSanitizedModelSelector } from './gridRowGroupingSelector';
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
|
|
13
|
+
const GROUPING_COL_DEF_DEFAULT_PROPERTIES = _extends({}, GRID_STRING_COL_DEF, {
|
|
14
|
+
disableReorder: true
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const GROUPING_COL_DEF_FORCED_PROPERTIES = {
|
|
18
|
+
type: 'rowGroupByColumnsGroup',
|
|
19
|
+
editable: false,
|
|
20
|
+
groupable: false
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* When sorting two cells with different grouping criteria, we consider that the cell with the grouping criteria coming first in the model should be displayed below.
|
|
24
|
+
* This can occur when some rows don't have all the fields. In which case we want the rows with the missing field to be displayed above.
|
|
25
|
+
* 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).
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
const groupingFieldIndexComparator = (v1, v2, cellParams1, cellParams2) => {
|
|
29
|
+
const model = gridRowGroupingSanitizedModelSelector(cellParams1.api.state, cellParams1.api.instanceId);
|
|
30
|
+
const groupingField1 = cellParams1.rowNode.groupingField;
|
|
31
|
+
const groupingField2 = cellParams2.rowNode.groupingField;
|
|
32
|
+
|
|
33
|
+
if (groupingField1 === groupingField2) {
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (groupingField1 == null) {
|
|
38
|
+
return -1;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (groupingField2 == null) {
|
|
42
|
+
return 1;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (model.indexOf(groupingField1) < model.indexOf(groupingField2)) {
|
|
46
|
+
return -1;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return 1;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const getLeafProperties = leafColDef => {
|
|
53
|
+
var _leafColDef$headerNam, _leafColDef$filterOpe;
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
headerName: (_leafColDef$headerNam = leafColDef.headerName) != null ? _leafColDef$headerNam : leafColDef.field,
|
|
57
|
+
sortable: leafColDef.sortable,
|
|
58
|
+
filterable: leafColDef.filterable,
|
|
59
|
+
filterOperators: (_leafColDef$filterOpe = leafColDef.filterOperators) == null ? void 0 : _leafColDef$filterOpe.map(operator => _extends({}, operator, {
|
|
60
|
+
getApplyFilterFn: (filterItem, column) => {
|
|
61
|
+
const originalFn = operator.getApplyFilterFn(filterItem, column);
|
|
62
|
+
|
|
63
|
+
if (!originalFn) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return params => {
|
|
68
|
+
// We only want to filter leaves
|
|
69
|
+
if (params.rowNode.groupingField != null) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return originalFn(params);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
})),
|
|
77
|
+
sortComparator: (v1, v2, cellParams1, cellParams2) => {
|
|
78
|
+
// We only want to sort the leaves
|
|
79
|
+
if (cellParams1.rowNode.groupingField === null && cellParams2.rowNode.groupingField === null) {
|
|
80
|
+
return leafColDef.sortComparator(v1, v2, cellParams1, cellParams2);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return groupingFieldIndexComparator(v1, v2, cellParams1, cellParams2);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const getGroupingCriteriaProperties = (groupedByColDef, applyHeaderName) => {
|
|
89
|
+
var _groupedByColDef$filt;
|
|
90
|
+
|
|
91
|
+
const properties = {
|
|
92
|
+
sortable: groupedByColDef.sortable,
|
|
93
|
+
filterable: groupedByColDef.filterable,
|
|
94
|
+
sortComparator: (v1, v2, cellParams1, cellParams2) => {
|
|
95
|
+
// We only want to sort the groups of the current grouping criteria
|
|
96
|
+
if (cellParams1.rowNode.groupingField === groupedByColDef.field && cellParams2.rowNode.groupingField === groupedByColDef.field) {
|
|
97
|
+
return groupedByColDef.sortComparator(v1, v2, cellParams1, cellParams2);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return groupingFieldIndexComparator(v1, v2, cellParams1, cellParams2);
|
|
101
|
+
},
|
|
102
|
+
filterOperators: (_groupedByColDef$filt = groupedByColDef.filterOperators) == null ? void 0 : _groupedByColDef$filt.map(operator => _extends({}, operator, {
|
|
103
|
+
getApplyFilterFn: (filterItem, column) => {
|
|
104
|
+
const originalFn = operator.getApplyFilterFn(filterItem, column);
|
|
105
|
+
|
|
106
|
+
if (!originalFn) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return params => {
|
|
111
|
+
// We only want to filter the groups of the current grouping criteria
|
|
112
|
+
if (params.rowNode.groupingField !== groupedByColDef.field) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return originalFn(params);
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}))
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
if (applyHeaderName) {
|
|
123
|
+
var _groupedByColDef$head;
|
|
124
|
+
|
|
125
|
+
properties.headerName = (_groupedByColDef$head = groupedByColDef.headerName) != null ? _groupedByColDef$head : groupedByColDef.field;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return properties;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Creates the `GridColDef` for a grouping column that only takes care of a single grouping criteria
|
|
133
|
+
*/
|
|
134
|
+
export const createGroupingColDefForOneGroupingCriteria = ({
|
|
135
|
+
columnsLookup,
|
|
136
|
+
groupedByColDef,
|
|
137
|
+
groupingCriteria,
|
|
138
|
+
colDefOverride
|
|
139
|
+
}) => {
|
|
140
|
+
var _groupedByColDef$widt, _leafColDef$width;
|
|
141
|
+
|
|
142
|
+
const _ref = colDefOverride != null ? colDefOverride : {},
|
|
143
|
+
{
|
|
144
|
+
leafField,
|
|
145
|
+
mainGroupingCriteria,
|
|
146
|
+
hideDescendantCount
|
|
147
|
+
} = _ref,
|
|
148
|
+
colDefOverrideProperties = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
149
|
+
|
|
150
|
+
const leafColDef = leafField ? columnsLookup[leafField] : null; // The properties that do not depend on the presence of a `leafColDef` and that can be overridden by `colDefOverride`
|
|
151
|
+
|
|
152
|
+
const commonProperties = {
|
|
153
|
+
width: Math.max(((_groupedByColDef$widt = groupedByColDef.width) != null ? _groupedByColDef$widt : GRID_STRING_COL_DEF.width) + 40, (_leafColDef$width = leafColDef == null ? void 0 : leafColDef.width) != null ? _leafColDef$width : 0),
|
|
154
|
+
renderCell: params => {
|
|
155
|
+
// Render leaves
|
|
156
|
+
if (params.rowNode.groupingField == null) {
|
|
157
|
+
if (leafColDef) {
|
|
158
|
+
const leafParams = _extends({}, params.api.getCellParams(params.id, leafField), {
|
|
159
|
+
api: params.api
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
if (leafColDef.renderCell) {
|
|
163
|
+
return leafColDef.renderCell(leafParams);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return /*#__PURE__*/_jsx(GridGroupingColumnLeafCell, _extends({}, leafParams));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return '';
|
|
170
|
+
} // Render current grouping criteria groups
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
if (params.rowNode.groupingField === groupingCriteria) {
|
|
174
|
+
return /*#__PURE__*/_jsx(GridGroupingCriteriaCell, _extends({}, params, {
|
|
175
|
+
hideDescendantCount: hideDescendantCount
|
|
176
|
+
}));
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return '';
|
|
180
|
+
},
|
|
181
|
+
valueGetter: params => {
|
|
182
|
+
if (!params.rowNode) {
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (params.rowNode.groupingField == null) {
|
|
187
|
+
if (leafColDef) {
|
|
188
|
+
return params.api.getCellValue(params.id, leafField);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
return undefined;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
if (params.rowNode.groupingField === groupingCriteria) {
|
|
195
|
+
return params.rowNode.groupingKey;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
}; // If we have a `mainGroupingCriteria` defined and matching the `groupingCriteria`
|
|
201
|
+
// Then we apply the sorting / filtering on the groups of this column's grouping criteria based on the properties of `groupedByColDef`.
|
|
202
|
+
// It can be useful to define a `leafField` for leaves rendering but still use the grouping criteria for the sorting / filtering
|
|
203
|
+
//
|
|
204
|
+
// If we have a `leafField` defined and matching an existing column
|
|
205
|
+
// Then we apply the sorting / filtering on the leaves based on the properties of `leavesColDef`
|
|
206
|
+
//
|
|
207
|
+
// By default, we apply the sorting / filtering on the groups of this column's grouping criteria based on the properties of `groupedColDef`.
|
|
208
|
+
|
|
209
|
+
let sourceProperties;
|
|
210
|
+
|
|
211
|
+
if (mainGroupingCriteria && mainGroupingCriteria === groupingCriteria) {
|
|
212
|
+
sourceProperties = getGroupingCriteriaProperties(groupedByColDef, true);
|
|
213
|
+
} else if (leafColDef) {
|
|
214
|
+
sourceProperties = getLeafProperties(leafColDef);
|
|
215
|
+
} else {
|
|
216
|
+
sourceProperties = getGroupingCriteriaProperties(groupedByColDef, true);
|
|
217
|
+
} // The properties that can't be overridden with `colDefOverride`
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
const forcedProperties = _extends({
|
|
221
|
+
field: getRowGroupingFieldFromGroupingCriteria(groupingCriteria)
|
|
222
|
+
}, GROUPING_COL_DEF_FORCED_PROPERTIES);
|
|
223
|
+
|
|
224
|
+
return _extends({}, GROUPING_COL_DEF_DEFAULT_PROPERTIES, commonProperties, sourceProperties, colDefOverrideProperties, forcedProperties);
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Creates the `GridColDef` for a grouping column that takes care of all the grouping criteria
|
|
229
|
+
*/
|
|
230
|
+
export const createGroupingColDefForAllGroupingCriteria = ({
|
|
231
|
+
apiRef,
|
|
232
|
+
columnsLookup,
|
|
233
|
+
rowGroupingModel,
|
|
234
|
+
colDefOverride
|
|
235
|
+
}) => {
|
|
236
|
+
var _leafColDef$width2;
|
|
237
|
+
|
|
238
|
+
const _ref2 = colDefOverride != null ? colDefOverride : {},
|
|
239
|
+
{
|
|
240
|
+
leafField,
|
|
241
|
+
mainGroupingCriteria,
|
|
242
|
+
hideDescendantCount
|
|
243
|
+
} = _ref2,
|
|
244
|
+
colDefOverrideProperties = _objectWithoutPropertiesLoose(_ref2, _excluded2);
|
|
245
|
+
|
|
246
|
+
const leafColDef = leafField ? columnsLookup[leafField] : null; // The properties that do not depend on the presence of a `leafColDef` and that can be overridden by `colDefOverride`
|
|
247
|
+
|
|
248
|
+
const commonProperties = {
|
|
249
|
+
headerName: apiRef.current.getLocaleText('groupingColumnHeaderName'),
|
|
250
|
+
width: Math.max(...rowGroupingModel.map(field => {
|
|
251
|
+
var _columnsLookup$field$;
|
|
252
|
+
|
|
253
|
+
return ((_columnsLookup$field$ = columnsLookup[field].width) != null ? _columnsLookup$field$ : GRID_STRING_COL_DEF.width) + 40;
|
|
254
|
+
}), (_leafColDef$width2 = leafColDef == null ? void 0 : leafColDef.width) != null ? _leafColDef$width2 : 0),
|
|
255
|
+
renderCell: params => {
|
|
256
|
+
// Render the leaves
|
|
257
|
+
if (params.rowNode.groupingField == null) {
|
|
258
|
+
if (leafColDef) {
|
|
259
|
+
const leafParams = _extends({}, params.api.getCellParams(params.id, leafField), {
|
|
260
|
+
api: params.api
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
if (leafColDef.renderCell) {
|
|
264
|
+
return leafColDef.renderCell(leafParams);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return /*#__PURE__*/_jsx(GridGroupingColumnLeafCell, _extends({}, leafParams));
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return '';
|
|
271
|
+
} // Render the groups
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
return /*#__PURE__*/_jsx(GridGroupingCriteriaCell, _extends({}, params, {
|
|
275
|
+
hideDescendantCount: hideDescendantCount
|
|
276
|
+
}));
|
|
277
|
+
},
|
|
278
|
+
valueGetter: params => {
|
|
279
|
+
if (!params.rowNode) {
|
|
280
|
+
return undefined;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (params.rowNode.groupingField == null) {
|
|
284
|
+
if (leafColDef) {
|
|
285
|
+
return params.api.getCellValue(params.id, leafField);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return undefined;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return params.rowNode.groupingKey;
|
|
292
|
+
}
|
|
293
|
+
}; // If we have a `mainGroupingCriteria` defined and matching one of the `orderedGroupedByFields`
|
|
294
|
+
// Then we apply the sorting / filtering on the groups of this column's grouping criteria based on the properties of `columnsLookup[mainGroupingCriteria]`.
|
|
295
|
+
// It can be useful to use another grouping criteria than the top level one for the sorting / filtering
|
|
296
|
+
//
|
|
297
|
+
// If we have a `leafField` defined and matching an existing column
|
|
298
|
+
// Then we apply the sorting / filtering on the leaves based on the properties of `leavesColDef`
|
|
299
|
+
//
|
|
300
|
+
// By default, we apply the sorting / filtering on the groups of the top level grouping criteria based on the properties of `columnsLookup[orderedGroupedByFields[0]]`.
|
|
301
|
+
|
|
302
|
+
let sourceProperties;
|
|
303
|
+
|
|
304
|
+
if (mainGroupingCriteria && rowGroupingModel.includes(mainGroupingCriteria)) {
|
|
305
|
+
sourceProperties = getGroupingCriteriaProperties(columnsLookup[mainGroupingCriteria], true);
|
|
306
|
+
} else if (leafColDef) {
|
|
307
|
+
sourceProperties = getLeafProperties(leafColDef);
|
|
308
|
+
} else {
|
|
309
|
+
sourceProperties = getGroupingCriteriaProperties(columnsLookup[rowGroupingModel[0]], rowGroupingModel.length === 1);
|
|
310
|
+
} // The properties that can't be overridden with `colDefOverride`
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
const forcedProperties = _extends({
|
|
314
|
+
field: GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD
|
|
315
|
+
}, GROUPING_COL_DEF_FORCED_PROPERTIES);
|
|
316
|
+
|
|
317
|
+
return _extends({}, GROUPING_COL_DEF_DEFAULT_PROPERTIES, commonProperties, sourceProperties, colDefOverrideProperties, forcedProperties);
|
|
318
|
+
};
|