@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,76 @@
|
|
|
1
|
+
import { useGridInitialization, useGridInitializeState, useGridClipboard, useGridColumnMenu, useGridColumns, columnsStateInitializer, useGridDensity, useGridCsvExport, useGridPrintExport, useGridFilter, filterStateInitializer, useGridFocus, useGridKeyboardNavigation, useGridPagination, paginationStateInitializer, useGridPreferencesPanel, useGridEditing_new, useGridEditing_old, editingStateInitializer_old, editingStateInitializer_new, useGridRows, useGridRowsPreProcessors, rowsStateInitializer, useGridRowsMeta, useGridParamsApi, useGridSelection, useGridSorting, sortingStateInitializer, useGridScroll, useGridEvents, useGridDimensions, useGridStatePersistence, useGridSelectionPreProcessors, columnMenuStateInitializer, densityStateInitializer, focusStateInitializer, preferencePanelStateInitializer, rowsMetaStateInitializer, selectionStateInitializer, useGridColumnReorder, columnReorderStateInitializer, useGridColumnResize, columnResizeStateInitializer, useGridTreeData, useGridTreeDataPreProcessors, useGridColumnPinning, columnPinningStateInitializer, useGridColumnPinningPreProcessors, useGridDetailPanel, detailPanelStateInitializer, useGridDetailPanelCache, useGridDetailPanelPreProcessors, useGridInfiniteLoader, useGridColumnSpanning, useGridRowReorder, useGridRowReorderPreProcessors } from '@mui/x-data-grid-pro/internals';
|
|
2
|
+
// Premium-only features
|
|
3
|
+
import { useGridRowGrouping, rowGroupingStateInitializer } from '../hooks/features/rowGrouping/useGridRowGrouping';
|
|
4
|
+
import { useGridRowGroupingPreProcessors } from '../hooks/features/rowGrouping/useGridRowGroupingPreProcessors';
|
|
5
|
+
import { useGridExcelExport } from '../hooks/features/export/useGridExcelExport';
|
|
6
|
+
export const useDataGridPremiumComponent = (inputApiRef, props) => {
|
|
7
|
+
const apiRef = useGridInitialization(inputApiRef, props);
|
|
8
|
+
/**
|
|
9
|
+
* Register all pre-processors called during state initialization here.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
useGridSelectionPreProcessors(apiRef, props);
|
|
13
|
+
useGridRowReorderPreProcessors(apiRef, props);
|
|
14
|
+
useGridRowGroupingPreProcessors(apiRef, props);
|
|
15
|
+
useGridTreeDataPreProcessors(apiRef, props);
|
|
16
|
+
useGridDetailPanelPreProcessors(apiRef, props); // The column pinning `hydrateColumns` pre-processor must be after every other `hydrateColumns` pre-processors
|
|
17
|
+
// Because it changes the order of the columns.
|
|
18
|
+
|
|
19
|
+
useGridColumnPinningPreProcessors(apiRef, props);
|
|
20
|
+
useGridRowsPreProcessors(apiRef);
|
|
21
|
+
/**
|
|
22
|
+
* Register all state initializers here.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
useGridInitializeState(rowGroupingStateInitializer, apiRef, props);
|
|
26
|
+
useGridInitializeState(selectionStateInitializer, apiRef, props);
|
|
27
|
+
useGridInitializeState(detailPanelStateInitializer, apiRef, props);
|
|
28
|
+
useGridInitializeState(columnPinningStateInitializer, apiRef, props);
|
|
29
|
+
useGridInitializeState(columnsStateInitializer, apiRef, props);
|
|
30
|
+
useGridInitializeState(rowsStateInitializer, apiRef, props);
|
|
31
|
+
useGridInitializeState(props.experimentalFeatures?.newEditingApi ? editingStateInitializer_new : editingStateInitializer_old, apiRef, props);
|
|
32
|
+
useGridInitializeState(focusStateInitializer, apiRef, props);
|
|
33
|
+
useGridInitializeState(sortingStateInitializer, apiRef, props);
|
|
34
|
+
useGridInitializeState(preferencePanelStateInitializer, apiRef, props);
|
|
35
|
+
useGridInitializeState(filterStateInitializer, apiRef, props);
|
|
36
|
+
useGridInitializeState(densityStateInitializer, apiRef, props);
|
|
37
|
+
useGridInitializeState(columnReorderStateInitializer, apiRef, props);
|
|
38
|
+
useGridInitializeState(columnResizeStateInitializer, apiRef, props);
|
|
39
|
+
useGridInitializeState(paginationStateInitializer, apiRef, props);
|
|
40
|
+
useGridInitializeState(rowsMetaStateInitializer, apiRef, props);
|
|
41
|
+
useGridInitializeState(columnMenuStateInitializer, apiRef, props);
|
|
42
|
+
useGridRowGrouping(apiRef, props);
|
|
43
|
+
useGridTreeData(apiRef);
|
|
44
|
+
useGridKeyboardNavigation(apiRef, props);
|
|
45
|
+
useGridSelection(apiRef, props);
|
|
46
|
+
useGridDetailPanel(apiRef, props);
|
|
47
|
+
useGridColumnPinning(apiRef, props);
|
|
48
|
+
useGridColumns(apiRef, props);
|
|
49
|
+
useGridRows(apiRef, props);
|
|
50
|
+
useGridParamsApi(apiRef);
|
|
51
|
+
useGridColumnSpanning(apiRef);
|
|
52
|
+
useGridDetailPanelCache(apiRef, props);
|
|
53
|
+
const useGridEditing = props.experimentalFeatures?.newEditingApi ? useGridEditing_new : useGridEditing_old;
|
|
54
|
+
useGridEditing(apiRef, props);
|
|
55
|
+
useGridFocus(apiRef, props);
|
|
56
|
+
useGridPreferencesPanel(apiRef);
|
|
57
|
+
useGridFilter(apiRef, props);
|
|
58
|
+
useGridSorting(apiRef, props);
|
|
59
|
+
useGridDensity(apiRef, props);
|
|
60
|
+
useGridColumnReorder(apiRef, props);
|
|
61
|
+
useGridColumnResize(apiRef, props);
|
|
62
|
+
useGridPagination(apiRef, props);
|
|
63
|
+
useGridRowsMeta(apiRef, props);
|
|
64
|
+
useGridRowReorder(apiRef, props);
|
|
65
|
+
useGridScroll(apiRef, props);
|
|
66
|
+
useGridInfiniteLoader(apiRef, props);
|
|
67
|
+
useGridColumnMenu(apiRef);
|
|
68
|
+
useGridCsvExport(apiRef);
|
|
69
|
+
useGridPrintExport(apiRef, props);
|
|
70
|
+
useGridExcelExport(apiRef);
|
|
71
|
+
useGridClipboard(apiRef);
|
|
72
|
+
useGridDimensions(apiRef, props);
|
|
73
|
+
useGridEvents(apiRef, props);
|
|
74
|
+
useGridStatePersistence(apiRef);
|
|
75
|
+
return apiRef;
|
|
76
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { useThemeProps } from '@mui/material/styles';
|
|
4
|
+
import { DATA_GRID_PRO_PROPS_DEFAULT_VALUES, DATA_GRID_DEFAULT_SLOTS_COMPONENTS, GRID_DEFAULT_LOCALE_TEXT } from '@mui/x-data-grid-pro';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The default values of `DataGridPremiumPropsWithDefaultValue` to inject in the props of DataGridPremium.
|
|
8
|
+
*/
|
|
9
|
+
export const DATA_GRID_PREMIUM_PROPS_DEFAULT_VALUES = _extends({}, DATA_GRID_PRO_PROPS_DEFAULT_VALUES, {
|
|
10
|
+
disableRowGrouping: false,
|
|
11
|
+
rowGroupingColumnMode: 'single'
|
|
12
|
+
});
|
|
13
|
+
export const useDataGridPremiumProps = inProps => {
|
|
14
|
+
const themedProps = useThemeProps({
|
|
15
|
+
props: inProps,
|
|
16
|
+
name: 'MuiDataGrid'
|
|
17
|
+
});
|
|
18
|
+
const localeText = React.useMemo(() => _extends({}, GRID_DEFAULT_LOCALE_TEXT, themedProps.localeText), [themedProps.localeText]);
|
|
19
|
+
const components = React.useMemo(() => {
|
|
20
|
+
const overrides = themedProps.components;
|
|
21
|
+
|
|
22
|
+
if (!overrides) {
|
|
23
|
+
return _extends({}, DATA_GRID_DEFAULT_SLOTS_COMPONENTS);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const mergedComponents = {};
|
|
27
|
+
Object.entries(DATA_GRID_DEFAULT_SLOTS_COMPONENTS).forEach(([key, defaultComponent]) => {
|
|
28
|
+
mergedComponents[key] = overrides[key] === undefined ? defaultComponent : overrides[key];
|
|
29
|
+
});
|
|
30
|
+
return mergedComponents;
|
|
31
|
+
}, [themedProps.components]);
|
|
32
|
+
return React.useMemo(() => _extends({}, DATA_GRID_PREMIUM_PROPS_DEFAULT_VALUES, themedProps, {
|
|
33
|
+
localeText,
|
|
34
|
+
components,
|
|
35
|
+
signature: 'DataGridPremium'
|
|
36
|
+
}), [themedProps, localeText, components]);
|
|
37
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import MenuItem from '@mui/material/MenuItem';
|
|
4
|
+
import { useGridApiContext } from '../hooks/utils/useGridApiContext';
|
|
5
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
+
|
|
7
|
+
const GridExcelExportMenuItem = props => {
|
|
8
|
+
const apiRef = useGridApiContext();
|
|
9
|
+
const {
|
|
10
|
+
hideMenu,
|
|
11
|
+
options
|
|
12
|
+
} = props;
|
|
13
|
+
return /*#__PURE__*/_jsx(MenuItem, {
|
|
14
|
+
onClick: () => {
|
|
15
|
+
apiRef.current.exportDataAsExcel(options);
|
|
16
|
+
hideMenu?.();
|
|
17
|
+
},
|
|
18
|
+
children: apiRef.current.getLocaleText('toolbarExportExcel')
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
process.env.NODE_ENV !== "production" ? GridExcelExportMenuItem.propTypes = {
|
|
23
|
+
// ----------------------------- Warning --------------------------------
|
|
24
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
25
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
26
|
+
// ----------------------------------------------------------------------
|
|
27
|
+
hideMenu: PropTypes.func,
|
|
28
|
+
options: PropTypes.shape({
|
|
29
|
+
disableToolbarButton: PropTypes.bool
|
|
30
|
+
})
|
|
31
|
+
} : void 0;
|
|
32
|
+
export { GridExcelExportMenuItem };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import Box from '@mui/material/Box';
|
|
3
|
+
import { useGridRootProps } from '../hooks/utils/useGridRootProps';
|
|
4
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
|
+
|
|
6
|
+
const GridGroupingColumnLeafCell = props => {
|
|
7
|
+
const {
|
|
8
|
+
rowNode
|
|
9
|
+
} = props;
|
|
10
|
+
const rootProps = useGridRootProps();
|
|
11
|
+
const marginLeft = rootProps.rowGroupingColumnMode === 'multiple' ? 1 : rowNode.depth * 2;
|
|
12
|
+
return /*#__PURE__*/_jsx(Box, {
|
|
13
|
+
sx: {
|
|
14
|
+
ml: marginLeft
|
|
15
|
+
},
|
|
16
|
+
children: props.formattedValue ?? props.value
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export { GridGroupingColumnLeafCell };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { unstable_composeClasses as composeClasses } from '@mui/material';
|
|
3
|
+
import IconButton from '@mui/material/IconButton';
|
|
4
|
+
import Box from '@mui/material/Box';
|
|
5
|
+
import { useGridSelector, gridFilteredDescendantCountLookupSelector, getDataGridUtilityClass } from '@mui/x-data-grid-pro';
|
|
6
|
+
import { useGridApiContext } from '../hooks/utils/useGridApiContext';
|
|
7
|
+
import { useGridRootProps } from '../hooks/utils/useGridRootProps';
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
10
|
+
|
|
11
|
+
const useUtilityClasses = ownerState => {
|
|
12
|
+
const {
|
|
13
|
+
classes
|
|
14
|
+
} = ownerState;
|
|
15
|
+
const slots = {
|
|
16
|
+
root: ['groupingCriteriaCell'],
|
|
17
|
+
toggle: ['groupingCriteriaCellToggle']
|
|
18
|
+
};
|
|
19
|
+
return composeClasses(slots, getDataGridUtilityClass, classes);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const GridGroupingCriteriaCell = props => {
|
|
23
|
+
const {
|
|
24
|
+
id,
|
|
25
|
+
field,
|
|
26
|
+
rowNode,
|
|
27
|
+
hideDescendantCount,
|
|
28
|
+
formattedValue
|
|
29
|
+
} = props;
|
|
30
|
+
const rootProps = useGridRootProps();
|
|
31
|
+
const apiRef = useGridApiContext();
|
|
32
|
+
const ownerState = {
|
|
33
|
+
classes: rootProps.classes
|
|
34
|
+
};
|
|
35
|
+
const classes = useUtilityClasses(ownerState);
|
|
36
|
+
const filteredDescendantCountLookup = useGridSelector(apiRef, gridFilteredDescendantCountLookupSelector);
|
|
37
|
+
const filteredDescendantCount = filteredDescendantCountLookup[rowNode.id] ?? 0;
|
|
38
|
+
const Icon = rowNode.childrenExpanded ? rootProps.components.GroupingCriteriaCollapseIcon : rootProps.components.GroupingCriteriaExpandIcon;
|
|
39
|
+
|
|
40
|
+
const handleKeyDown = event => {
|
|
41
|
+
if (event.key === ' ') {
|
|
42
|
+
event.stopPropagation();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
apiRef.current.publishEvent('cellKeyDown', props, event);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const handleClick = event => {
|
|
49
|
+
apiRef.current.setRowChildrenExpansion(id, !rowNode.childrenExpanded);
|
|
50
|
+
apiRef.current.setCellFocus(id, field);
|
|
51
|
+
event.stopPropagation();
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const marginLeft = rootProps.rowGroupingColumnMode === 'multiple' ? 0 : rowNode.depth * 2;
|
|
55
|
+
return /*#__PURE__*/_jsxs(Box, {
|
|
56
|
+
className: classes.root,
|
|
57
|
+
sx: {
|
|
58
|
+
ml: marginLeft
|
|
59
|
+
},
|
|
60
|
+
children: [/*#__PURE__*/_jsx("div", {
|
|
61
|
+
className: classes.toggle,
|
|
62
|
+
children: filteredDescendantCount > 0 && /*#__PURE__*/_jsx(IconButton, {
|
|
63
|
+
size: "small",
|
|
64
|
+
onClick: handleClick,
|
|
65
|
+
onKeyDown: handleKeyDown,
|
|
66
|
+
tabIndex: -1,
|
|
67
|
+
"aria-label": rowNode.childrenExpanded ? apiRef.current.getLocaleText('treeDataCollapse') : apiRef.current.getLocaleText('treeDataExpand'),
|
|
68
|
+
children: /*#__PURE__*/_jsx(Icon, {
|
|
69
|
+
fontSize: "inherit"
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
}), /*#__PURE__*/_jsxs("span", {
|
|
73
|
+
children: [formattedValue === undefined ? rowNode.groupingKey : formattedValue, !hideDescendantCount && filteredDescendantCount > 0 ? ` (${filteredDescendantCount})` : '']
|
|
74
|
+
})]
|
|
75
|
+
});
|
|
76
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import MenuItem from '@mui/material/MenuItem';
|
|
4
|
+
import { gridColumnLookupSelector, useGridSelector } from '@mui/x-data-grid-pro';
|
|
5
|
+
import { useGridApiContext } from '../hooks/utils/useGridApiContext';
|
|
6
|
+
import { gridRowGroupingSanitizedModelSelector } from '../hooks/features/rowGrouping/gridRowGroupingSelector';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
|
|
9
|
+
const GridRowGroupableColumnMenuItems = props => {
|
|
10
|
+
const {
|
|
11
|
+
column,
|
|
12
|
+
onClick
|
|
13
|
+
} = props;
|
|
14
|
+
const apiRef = useGridApiContext();
|
|
15
|
+
const rowGroupingModel = useGridSelector(apiRef, gridRowGroupingSanitizedModelSelector);
|
|
16
|
+
const columnsLookup = useGridSelector(apiRef, gridColumnLookupSelector);
|
|
17
|
+
|
|
18
|
+
if (!column?.groupable) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const ungroupColumn = event => {
|
|
23
|
+
apiRef.current.removeRowGroupingCriteria(column.field);
|
|
24
|
+
|
|
25
|
+
if (onClick) {
|
|
26
|
+
onClick(event);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const groupColumn = event => {
|
|
31
|
+
apiRef.current.addRowGroupingCriteria(column.field);
|
|
32
|
+
|
|
33
|
+
if (onClick) {
|
|
34
|
+
onClick(event);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const name = columnsLookup[column.field].headerName ?? column.field;
|
|
39
|
+
|
|
40
|
+
if (rowGroupingModel.includes(column.field)) {
|
|
41
|
+
return /*#__PURE__*/_jsx(MenuItem, {
|
|
42
|
+
onClick: ungroupColumn,
|
|
43
|
+
children: apiRef.current.getLocaleText('unGroupColumn')(name)
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return /*#__PURE__*/_jsx(MenuItem, {
|
|
48
|
+
onClick: groupColumn,
|
|
49
|
+
children: apiRef.current.getLocaleText('groupColumn')(name)
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
process.env.NODE_ENV !== "production" ? GridRowGroupableColumnMenuItems.propTypes = {
|
|
54
|
+
// ----------------------------- Warning --------------------------------
|
|
55
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
56
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
57
|
+
// ----------------------------------------------------------------------
|
|
58
|
+
column: PropTypes.object,
|
|
59
|
+
onClick: PropTypes.func
|
|
60
|
+
} : void 0;
|
|
61
|
+
export { GridRowGroupableColumnMenuItems };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import MenuItem from '@mui/material/MenuItem';
|
|
4
|
+
import { useGridSelector, gridColumnLookupSelector } from '@mui/x-data-grid-pro';
|
|
5
|
+
import { useGridApiContext } from '../hooks/utils/useGridApiContext';
|
|
6
|
+
import { gridRowGroupingSanitizedModelSelector } from '../hooks/features/rowGrouping/gridRowGroupingSelector';
|
|
7
|
+
import { getRowGroupingCriteriaFromGroupingField, GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD, isGroupingColumn } from '../hooks/features/rowGrouping/gridRowGroupingUtils';
|
|
8
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
+
|
|
10
|
+
const GridRowGroupingColumnMenuItems = props => {
|
|
11
|
+
const {
|
|
12
|
+
column,
|
|
13
|
+
onClick
|
|
14
|
+
} = props;
|
|
15
|
+
const apiRef = useGridApiContext();
|
|
16
|
+
const rowGroupingModel = useGridSelector(apiRef, gridRowGroupingSanitizedModelSelector);
|
|
17
|
+
const columnsLookup = useGridSelector(apiRef, gridColumnLookupSelector);
|
|
18
|
+
|
|
19
|
+
const renderUnGroupingMenuItem = field => {
|
|
20
|
+
const ungroupColumn = event => {
|
|
21
|
+
apiRef.current.removeRowGroupingCriteria(field);
|
|
22
|
+
|
|
23
|
+
if (onClick) {
|
|
24
|
+
onClick(event);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const name = columnsLookup[field].headerName ?? field;
|
|
29
|
+
return /*#__PURE__*/_jsx(MenuItem, {
|
|
30
|
+
onClick: ungroupColumn,
|
|
31
|
+
children: apiRef.current.getLocaleText('unGroupColumn')(name)
|
|
32
|
+
}, field);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
if (!column || !isGroupingColumn(column.field)) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (column.field === GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD) {
|
|
40
|
+
return /*#__PURE__*/_jsx(React.Fragment, {
|
|
41
|
+
children: rowGroupingModel.map(renderUnGroupingMenuItem)
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return renderUnGroupingMenuItem(getRowGroupingCriteriaFromGroupingField(column.field));
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
process.env.NODE_ENV !== "production" ? GridRowGroupingColumnMenuItems.propTypes = {
|
|
49
|
+
// ----------------------------- Warning --------------------------------
|
|
50
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
51
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
52
|
+
// ----------------------------------------------------------------------
|
|
53
|
+
column: PropTypes.object,
|
|
54
|
+
onClick: PropTypes.func
|
|
55
|
+
} : void 0;
|
|
56
|
+
export { GridRowGroupingColumnMenuItems };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './GridExcelExportMenuItem';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './gridExcelExportInterface';
|
|
@@ -0,0 +1,216 @@
|
|
|
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
|
+
if (typeof cellParams.colDef.valueOptions === 'function') {
|
|
46
|
+
// If value option depends on the row, set specific options to the cell
|
|
47
|
+
// This dataValidation is buggy with LibreOffice and does not allow to have coma
|
|
48
|
+
const valueOptions = cellParams.colDef.valueOptions({
|
|
49
|
+
id,
|
|
50
|
+
row,
|
|
51
|
+
field: cellParams.field
|
|
52
|
+
});
|
|
53
|
+
const formattedValueOptions = getFormattedValueOptions(cellParams.colDef, valueOptions, api);
|
|
54
|
+
dataValidation[column.field] = {
|
|
55
|
+
type: 'list',
|
|
56
|
+
allowBlank: true,
|
|
57
|
+
formulae: [`"${formattedValueOptions.map(x => x.toString().replaceAll(',', 'CHAR(44)')).join(',')}"`]
|
|
58
|
+
};
|
|
59
|
+
} else {
|
|
60
|
+
// If value option is defined for the column, refer to another sheet
|
|
61
|
+
dataValidation[column.field] = {
|
|
62
|
+
type: 'list',
|
|
63
|
+
allowBlank: true,
|
|
64
|
+
formulae: [defaultValueOptionsFormulae[column.field]]
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const formattedValue = api.getCellParams(id, column.field).formattedValue;
|
|
69
|
+
|
|
70
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
71
|
+
if (String(cellParams.formattedValue) === '[object Object]') {
|
|
72
|
+
warnInvalidFormattedValue();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
row[column.field] = formattedValue?.label ?? formattedValue;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
case 'boolean':
|
|
81
|
+
case 'number':
|
|
82
|
+
row[column.field] = api.getCellParams(id, column.field).value;
|
|
83
|
+
break;
|
|
84
|
+
|
|
85
|
+
case 'date':
|
|
86
|
+
case 'dateTime':
|
|
87
|
+
{
|
|
88
|
+
// Excel does not do any timezone conversion, so we create a date using UTC instead of local timezone
|
|
89
|
+
// Solution from: https://github.com/exceljs/exceljs/issues/486#issuecomment-432557582
|
|
90
|
+
// About Date.UTC(): https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/Date/UTC#exemples
|
|
91
|
+
const date = api.getCellParams(id, column.field).value; // value may be `undefined` in auto-generated grouping rows
|
|
92
|
+
|
|
93
|
+
if (!date) {
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const utcDate = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()));
|
|
98
|
+
row[column.field] = utcDate;
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
case 'actions':
|
|
103
|
+
break;
|
|
104
|
+
|
|
105
|
+
default:
|
|
106
|
+
row[column.field] = api.getCellParams(id, column.field).formattedValue;
|
|
107
|
+
|
|
108
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
109
|
+
if (String(cellParams.formattedValue) === '[object Object]') {
|
|
110
|
+
warnInvalidFormattedValue();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
row,
|
|
119
|
+
dataValidation,
|
|
120
|
+
outlineLevel
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const defaultColumnsStyles = {
|
|
125
|
+
[GRID_DATE_COL_DEF.type]: {
|
|
126
|
+
numFmt: 'dd.mm.yyyy'
|
|
127
|
+
},
|
|
128
|
+
[GRID_DATETIME_COL_DEF.type]: {
|
|
129
|
+
numFmt: 'dd.mm.yyyy hh:mm'
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
const serializeColumn = (column, columnsStyles) => {
|
|
134
|
+
const {
|
|
135
|
+
field,
|
|
136
|
+
type
|
|
137
|
+
} = column;
|
|
138
|
+
return {
|
|
139
|
+
key: field,
|
|
140
|
+
// 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)
|
|
141
|
+
// From the example of column width behavior (https://docs.microsoft.com/en-US/office/troubleshoot/excel/determine-column-widths#example-of-column-width-behavior)
|
|
142
|
+
// a value of 10 corresponds to 75px. This is an approximation, because column width depends on the the font-size
|
|
143
|
+
width: Math.min(255, column.width ? column.width / 7.5 : 8.43),
|
|
144
|
+
style: _extends({}, type && defaultColumnsStyles?.[type], columnsStyles?.[field])
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
export async function buildExcel(options, api) {
|
|
149
|
+
const {
|
|
150
|
+
columns,
|
|
151
|
+
rowIds,
|
|
152
|
+
includeHeaders,
|
|
153
|
+
valueOptionsSheetName,
|
|
154
|
+
exceljsPreProcess,
|
|
155
|
+
exceljsPostProcess,
|
|
156
|
+
columnsStyles = {}
|
|
157
|
+
} = options;
|
|
158
|
+
const excelJS = await getExcelJs();
|
|
159
|
+
const workbook = new excelJS.Workbook();
|
|
160
|
+
const worksheet = workbook.addWorksheet('Sheet1');
|
|
161
|
+
worksheet.columns = columns.map(column => serializeColumn(column, columnsStyles));
|
|
162
|
+
|
|
163
|
+
if (exceljsPreProcess) {
|
|
164
|
+
await exceljsPreProcess({
|
|
165
|
+
workbook,
|
|
166
|
+
worksheet
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (includeHeaders) {
|
|
171
|
+
worksheet.addRow(columns.map(column => column.headerName || column.field));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const columnsWithArrayValueOptions = columns.filter(column => column.type === 'singleSelect' && column.valueOptions && typeof column.valueOptions !== 'function');
|
|
175
|
+
const defaultValueOptionsFormulae = {};
|
|
176
|
+
|
|
177
|
+
if (columnsWithArrayValueOptions.length) {
|
|
178
|
+
const valueOptionsWorksheet = workbook.addWorksheet(valueOptionsSheetName);
|
|
179
|
+
valueOptionsWorksheet.columns = columnsWithArrayValueOptions.map(({
|
|
180
|
+
field
|
|
181
|
+
}) => ({
|
|
182
|
+
key: field
|
|
183
|
+
}));
|
|
184
|
+
columnsWithArrayValueOptions.forEach(column => {
|
|
185
|
+
const formattedValueOptions = getFormattedValueOptions(column, column.valueOptions, api);
|
|
186
|
+
valueOptionsWorksheet.getColumn(column.field).values = [column.headerName || column.field, ...formattedValueOptions];
|
|
187
|
+
const columnLetter = valueOptionsWorksheet.getColumn(column.field).letter;
|
|
188
|
+
defaultValueOptionsFormulae[column.field] = `${valueOptionsSheetName}!$${columnLetter}$2:$${columnLetter}$${1 + formattedValueOptions.length}`;
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
rowIds.forEach(id => {
|
|
193
|
+
const {
|
|
194
|
+
row,
|
|
195
|
+
dataValidation,
|
|
196
|
+
outlineLevel
|
|
197
|
+
} = serializeRow(id, columns, api, defaultValueOptionsFormulae);
|
|
198
|
+
const newRow = worksheet.addRow(row);
|
|
199
|
+
Object.keys(dataValidation).forEach(field => {
|
|
200
|
+
newRow.getCell(field).dataValidation = _extends({}, dataValidation[field]);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
if (outlineLevel) {
|
|
204
|
+
newRow.outlineLevel = outlineLevel;
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
if (exceljsPostProcess) {
|
|
209
|
+
await exceljsPostProcess({
|
|
210
|
+
workbook,
|
|
211
|
+
worksheet
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
return workbook;
|
|
216
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
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
|
+
logger.debug(`Get data as excel`);
|
|
19
|
+
const getRowsToExport = options.getRowsToExport ?? defaultGetRowsToExport;
|
|
20
|
+
const exportedRowIds = getRowsToExport({
|
|
21
|
+
apiRef
|
|
22
|
+
});
|
|
23
|
+
const exportedColumns = getColumnsToExport({
|
|
24
|
+
apiRef,
|
|
25
|
+
options
|
|
26
|
+
});
|
|
27
|
+
return buildExcel({
|
|
28
|
+
columns: exportedColumns,
|
|
29
|
+
rowIds: exportedRowIds,
|
|
30
|
+
includeHeaders: options.includeHeaders ?? true,
|
|
31
|
+
valueOptionsSheetName: options?.valueOptionsSheetName || 'Options',
|
|
32
|
+
columnsStyles: options?.columnsStyles,
|
|
33
|
+
exceljsPreProcess: options?.exceljsPreProcess,
|
|
34
|
+
exceljsPostProcess: options?.exceljsPostProcess
|
|
35
|
+
}, apiRef.current);
|
|
36
|
+
}, [logger, apiRef]);
|
|
37
|
+
const exportDataAsExcel = React.useCallback(async options => {
|
|
38
|
+
logger.debug(`Export data as excel`);
|
|
39
|
+
const workbook = await getDataAsExcel(options);
|
|
40
|
+
|
|
41
|
+
if (workbook === null) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const content = await workbook.xlsx.writeBuffer();
|
|
46
|
+
const blob = new Blob([content], {
|
|
47
|
+
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
48
|
+
});
|
|
49
|
+
exportAs(blob, 'xlsx', options?.fileName);
|
|
50
|
+
}, [logger, getDataAsExcel]);
|
|
51
|
+
const excelExportApi = {
|
|
52
|
+
getDataAsExcel,
|
|
53
|
+
exportDataAsExcel
|
|
54
|
+
};
|
|
55
|
+
useGridApiMethod(apiRef, excelExportApi, 'GridExcelExportApi');
|
|
56
|
+
/**
|
|
57
|
+
* PRE-PROCESSING
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
const addExportMenuButtons = React.useCallback((initialValue, options) => {
|
|
61
|
+
if (options.excelOptions?.disableToolbarButton) {
|
|
62
|
+
return initialValue;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return [...initialValue, {
|
|
66
|
+
component: /*#__PURE__*/_jsx(GridExcelExportMenuItem, {
|
|
67
|
+
options: options.excelOptions
|
|
68
|
+
}),
|
|
69
|
+
componentName: 'excelExport'
|
|
70
|
+
}];
|
|
71
|
+
}, []);
|
|
72
|
+
useGridRegisterPipeProcessor(apiRef, 'exportMenu', addExportMenuButtons);
|
|
73
|
+
};
|