@mui/x-data-grid-premium 5.13.0 → 5.15.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 +156 -6
- package/DataGridPremium/DataGridPremium.js +56 -0
- package/DataGridPremium/useDataGridPremiumComponent.js +10 -2
- package/DataGridPremium/useDataGridPremiumProps.js +17 -7
- package/components/GridAggregationColumnMenuItem.d.ts +9 -0
- package/components/GridAggregationColumnMenuItem.js +93 -0
- package/components/GridAggregationHeader.d.ts +4 -0
- package/components/GridAggregationHeader.js +94 -0
- package/components/GridExcelExportMenuItem.js +11 -4
- package/components/GridFooterCell.d.ts +9 -0
- package/components/GridFooterCell.js +51 -0
- package/components/GridGroupingColumnFooterCell.d.ts +4 -0
- package/components/GridGroupingColumnFooterCell.js +29 -0
- package/hooks/features/aggregation/createAggregationLookup.d.ts +10 -0
- package/hooks/features/aggregation/createAggregationLookup.js +128 -0
- package/hooks/features/aggregation/gridAggregationFunctions.d.ts +8 -0
- package/hooks/features/aggregation/gridAggregationFunctions.js +96 -0
- package/hooks/features/aggregation/gridAggregationInterfaces.d.ts +103 -0
- package/hooks/features/aggregation/gridAggregationInterfaces.js +1 -0
- package/hooks/features/aggregation/gridAggregationSelectors.d.ts +4 -0
- package/hooks/features/aggregation/gridAggregationSelectors.js +4 -0
- package/hooks/features/aggregation/gridAggregationUtils.d.ts +41 -0
- package/hooks/features/aggregation/gridAggregationUtils.js +188 -0
- package/hooks/features/aggregation/index.d.ts +4 -0
- package/hooks/features/aggregation/index.js +4 -0
- package/hooks/features/aggregation/useGridAggregation.d.ts +6 -0
- package/hooks/features/aggregation/useGridAggregation.js +94 -0
- package/hooks/features/aggregation/useGridAggregationPreProcessors.d.ts +4 -0
- package/hooks/features/aggregation/useGridAggregationPreProcessors.js +138 -0
- package/hooks/features/aggregation/wrapColumnWithAggregation.d.ts +29 -0
- package/hooks/features/aggregation/wrapColumnWithAggregation.js +257 -0
- package/hooks/features/export/serializer/excelSerializer.js +2 -1
- package/hooks/features/index.d.ts +1 -0
- package/hooks/features/index.js +1 -0
- package/hooks/features/rowGrouping/createGroupingColDef.js +13 -2
- package/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -1
- package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +1 -1
- package/hooks/features/rowGrouping/useGridRowGrouping.js +20 -10
- package/index.js +1 -1
- package/legacy/DataGridPremium/DataGridPremium.js +56 -0
- package/legacy/DataGridPremium/useDataGridPremiumComponent.js +10 -2
- package/legacy/DataGridPremium/useDataGridPremiumProps.js +12 -2
- package/legacy/components/GridAggregationColumnMenuItem.js +95 -0
- package/legacy/components/GridAggregationHeader.js +95 -0
- package/legacy/components/GridExcelExportMenuItem.js +11 -4
- package/legacy/components/GridFooterCell.js +63 -0
- package/legacy/components/GridGroupingColumnFooterCell.js +27 -0
- package/legacy/hooks/features/aggregation/createAggregationLookup.js +127 -0
- package/legacy/hooks/features/aggregation/gridAggregationFunctions.js +94 -0
- package/legacy/hooks/features/aggregation/gridAggregationInterfaces.js +1 -0
- package/legacy/hooks/features/aggregation/gridAggregationSelectors.js +10 -0
- package/legacy/hooks/features/aggregation/gridAggregationUtils.js +200 -0
- package/legacy/hooks/features/aggregation/index.js +4 -0
- package/legacy/hooks/features/aggregation/useGridAggregation.js +95 -0
- package/legacy/hooks/features/aggregation/useGridAggregationPreProcessors.js +141 -0
- package/legacy/hooks/features/aggregation/wrapColumnWithAggregation.js +262 -0
- package/legacy/hooks/features/export/serializer/excelSerializer.js +2 -1
- package/legacy/hooks/features/index.js +1 -0
- package/legacy/hooks/features/rowGrouping/createGroupingColDef.js +13 -2
- package/legacy/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -1
- package/legacy/hooks/features/rowGrouping/useGridRowGrouping.js +24 -10
- package/legacy/index.js +1 -1
- package/legacy/typeOverloads/index.js +1 -1
- package/legacy/utils/releaseInfo.js +1 -1
- package/models/dataGridPremiumProps.d.ts +40 -1
- package/models/gridApiPremium.d.ts +3 -3
- package/models/gridStatePremium.d.ts +3 -1
- package/modern/DataGridPremium/DataGridPremium.js +56 -0
- package/modern/DataGridPremium/useDataGridPremiumComponent.js +10 -2
- package/modern/DataGridPremium/useDataGridPremiumProps.js +8 -2
- package/modern/components/GridAggregationColumnMenuItem.js +93 -0
- package/modern/components/GridAggregationHeader.js +92 -0
- package/modern/components/GridExcelExportMenuItem.js +11 -4
- package/modern/components/GridFooterCell.js +51 -0
- package/modern/components/GridGroupingColumnFooterCell.js +29 -0
- package/modern/hooks/features/aggregation/createAggregationLookup.js +122 -0
- package/modern/hooks/features/aggregation/gridAggregationFunctions.js +96 -0
- package/modern/hooks/features/aggregation/gridAggregationInterfaces.js +1 -0
- package/modern/hooks/features/aggregation/gridAggregationSelectors.js +4 -0
- package/modern/hooks/features/aggregation/gridAggregationUtils.js +186 -0
- package/modern/hooks/features/aggregation/index.js +4 -0
- package/modern/hooks/features/aggregation/useGridAggregation.js +92 -0
- package/modern/hooks/features/aggregation/useGridAggregationPreProcessors.js +136 -0
- package/modern/hooks/features/aggregation/wrapColumnWithAggregation.js +251 -0
- package/modern/hooks/features/export/serializer/excelSerializer.js +2 -1
- package/modern/hooks/features/index.js +1 -0
- package/modern/hooks/features/rowGrouping/createGroupingColDef.js +13 -2
- package/modern/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -1
- package/modern/hooks/features/rowGrouping/useGridRowGrouping.js +17 -11
- package/modern/index.js +1 -1
- package/modern/typeOverloads/index.js +1 -1
- package/modern/utils/releaseInfo.js +1 -1
- package/node/DataGridPremium/DataGridPremium.js +56 -0
- package/node/DataGridPremium/useDataGridPremiumComponent.js +11 -1
- package/node/DataGridPremium/useDataGridPremiumProps.js +17 -6
- package/node/components/GridAggregationColumnMenuItem.js +120 -0
- package/node/components/GridAggregationHeader.js +115 -0
- package/node/components/GridExcelExportMenuItem.js +12 -4
- package/node/components/GridFooterCell.js +73 -0
- package/node/components/GridGroupingColumnFooterCell.js +46 -0
- package/node/hooks/features/aggregation/createAggregationLookup.js +139 -0
- package/node/hooks/features/aggregation/gridAggregationFunctions.js +105 -0
- package/node/hooks/features/aggregation/gridAggregationInterfaces.js +5 -0
- package/node/hooks/features/aggregation/gridAggregationSelectors.js +16 -0
- package/node/hooks/features/aggregation/gridAggregationUtils.js +223 -0
- package/node/hooks/features/aggregation/index.js +65 -0
- package/node/hooks/features/aggregation/useGridAggregation.js +118 -0
- package/node/hooks/features/aggregation/useGridAggregationPreProcessors.js +162 -0
- package/node/hooks/features/aggregation/wrapColumnWithAggregation.js +279 -0
- package/node/hooks/features/export/serializer/excelSerializer.js +2 -1
- package/node/hooks/features/index.js +13 -0
- package/node/hooks/features/rowGrouping/createGroupingColDef.js +14 -2
- package/node/hooks/features/rowGrouping/gridRowGroupingUtils.js +5 -1
- package/node/hooks/features/rowGrouping/useGridRowGrouping.js +19 -10
- package/node/index.js +1 -1
- package/node/typeOverloads/index.js +16 -1
- package/node/utils/releaseInfo.js +1 -1
- package/package.json +5 -5
- package/typeOverloads/index.d.ts +1 -1
- package/typeOverloads/index.js +1 -1
- package/typeOverloads/modules.d.ts +32 -2
- package/utils/releaseInfo.js +1 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { GridStateInitializer } from '@mui/x-data-grid-pro/internals';
|
|
3
|
+
import { DataGridPremiumProcessedProps } from '../../../models/dataGridPremiumProps';
|
|
4
|
+
import { GridApiPremium } from '../../../models/gridApiPremium';
|
|
5
|
+
export declare const aggregationStateInitializer: GridStateInitializer<Pick<DataGridPremiumProcessedProps, 'aggregationModel' | 'initialState'>, GridApiPremium>;
|
|
6
|
+
export declare const useGridAggregation: (apiRef: React.MutableRefObject<GridApiPremium>, props: Pick<DataGridPremiumProcessedProps, 'onAggregationModelChange' | 'initialState' | 'aggregationModel' | 'getAggregationPosition' | 'aggregationFunctions' | 'aggregationRowsScope' | 'disableAggregation' | 'rowGroupingColumnMode'>) => void;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { gridColumnLookupSelector, useGridApiEventHandler, useGridApiMethod } from '@mui/x-data-grid-pro';
|
|
4
|
+
import { gridAggregationModelSelector } from './gridAggregationSelectors';
|
|
5
|
+
import { getAggregationRules, mergeStateWithAggregationModel, hasAggregationRulesChanged } from './gridAggregationUtils';
|
|
6
|
+
import { createAggregationLookup } from './createAggregationLookup';
|
|
7
|
+
export const aggregationStateInitializer = (state, props, apiRef) => {
|
|
8
|
+
var _ref, _props$aggregationMod, _props$initialState, _props$initialState$a;
|
|
9
|
+
|
|
10
|
+
apiRef.current.unstable_caches.aggregation = {
|
|
11
|
+
rulesOnLastColumnHydration: {},
|
|
12
|
+
rulesOnLastRowHydration: {}
|
|
13
|
+
};
|
|
14
|
+
return _extends({}, state, {
|
|
15
|
+
aggregation: {
|
|
16
|
+
model: (_ref = (_props$aggregationMod = props.aggregationModel) != null ? _props$aggregationMod : (_props$initialState = props.initialState) == null ? void 0 : (_props$initialState$a = _props$initialState.aggregation) == null ? void 0 : _props$initialState$a.model) != null ? _ref : {}
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
export const useGridAggregation = (apiRef, props) => {
|
|
21
|
+
apiRef.current.unstable_registerControlState({
|
|
22
|
+
stateId: 'aggregation',
|
|
23
|
+
propModel: props.aggregationModel,
|
|
24
|
+
propOnChange: props.onAggregationModelChange,
|
|
25
|
+
stateSelector: gridAggregationModelSelector,
|
|
26
|
+
changeEvent: 'aggregationModelChange'
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* API METHODS
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
const setAggregationModel = React.useCallback(model => {
|
|
33
|
+
const currentModel = gridAggregationModelSelector(apiRef);
|
|
34
|
+
|
|
35
|
+
if (currentModel !== model) {
|
|
36
|
+
apiRef.current.setState(mergeStateWithAggregationModel(model));
|
|
37
|
+
apiRef.current.forceUpdate();
|
|
38
|
+
}
|
|
39
|
+
}, [apiRef]);
|
|
40
|
+
const applyAggregation = React.useCallback(() => {
|
|
41
|
+
const aggregationLookup = createAggregationLookup({
|
|
42
|
+
apiRef,
|
|
43
|
+
getAggregationPosition: props.getAggregationPosition,
|
|
44
|
+
aggregationFunctions: props.aggregationFunctions,
|
|
45
|
+
aggregationRowsScope: props.aggregationRowsScope
|
|
46
|
+
});
|
|
47
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
48
|
+
aggregation: _extends({}, state.aggregation, {
|
|
49
|
+
lookup: aggregationLookup
|
|
50
|
+
})
|
|
51
|
+
}));
|
|
52
|
+
}, [apiRef, props.getAggregationPosition, props.aggregationFunctions, props.aggregationRowsScope]);
|
|
53
|
+
const aggregationApi = {
|
|
54
|
+
setAggregationModel
|
|
55
|
+
};
|
|
56
|
+
useGridApiMethod(apiRef, aggregationApi, 'GridAggregationApi');
|
|
57
|
+
/**
|
|
58
|
+
* EVENTS
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
const checkAggregationRulesDiff = React.useCallback(() => {
|
|
62
|
+
const {
|
|
63
|
+
rulesOnLastRowHydration,
|
|
64
|
+
rulesOnLastColumnHydration
|
|
65
|
+
} = apiRef.current.unstable_caches.aggregation;
|
|
66
|
+
const aggregationRules = props.disableAggregation ? {} : getAggregationRules({
|
|
67
|
+
columnsLookup: gridColumnLookupSelector(apiRef),
|
|
68
|
+
aggregationModel: gridAggregationModelSelector(apiRef),
|
|
69
|
+
aggregationFunctions: props.aggregationFunctions
|
|
70
|
+
}); // Re-apply the row hydration to add / remove the aggregation footers
|
|
71
|
+
|
|
72
|
+
if (hasAggregationRulesChanged(rulesOnLastRowHydration, aggregationRules)) {
|
|
73
|
+
apiRef.current.unstable_requestPipeProcessorsApplication('hydrateRows');
|
|
74
|
+
applyAggregation();
|
|
75
|
+
} // Re-apply the column hydration to wrap / unwrap the aggregated columns
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if (hasAggregationRulesChanged(rulesOnLastColumnHydration, aggregationRules)) {
|
|
79
|
+
apiRef.current.unstable_requestPipeProcessorsApplication('hydrateColumns');
|
|
80
|
+
}
|
|
81
|
+
}, [apiRef, applyAggregation, props.aggregationFunctions, props.disableAggregation]);
|
|
82
|
+
useGridApiEventHandler(apiRef, 'aggregationModelChange', checkAggregationRulesDiff);
|
|
83
|
+
useGridApiEventHandler(apiRef, 'columnsChange', checkAggregationRulesDiff);
|
|
84
|
+
useGridApiEventHandler(apiRef, 'filteredRowsSet', applyAggregation);
|
|
85
|
+
/**
|
|
86
|
+
* EFFECTS
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
React.useEffect(() => {
|
|
90
|
+
if (props.aggregationModel !== undefined) {
|
|
91
|
+
apiRef.current.setAggregationModel(props.aggregationModel);
|
|
92
|
+
}
|
|
93
|
+
}, [apiRef, props.aggregationModel]);
|
|
94
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { GridApiPremium } from '../../../models/gridApiPremium';
|
|
3
|
+
import { DataGridPremiumProcessedProps } from '../../../models/dataGridPremiumProps';
|
|
4
|
+
export declare const useGridAggregationPreProcessors: (apiRef: React.MutableRefObject<GridApiPremium>, props: Pick<DataGridPremiumProcessedProps, 'aggregationFunctions' | 'disableAggregation' | 'getAggregationPosition'>) => void;
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import MuiDivider from '@mui/material/Divider';
|
|
4
|
+
import { gridColumnLookupSelector } from '@mui/x-data-grid-pro';
|
|
5
|
+
import { useGridRegisterPipeProcessor } from '@mui/x-data-grid-pro/internals';
|
|
6
|
+
import { getAvailableAggregationFunctions, addFooterRows, getAggregationRules, mergeStateWithAggregationModel } from './gridAggregationUtils';
|
|
7
|
+
import { wrapColumnWithAggregationValue, unwrapColumnFromAggregation } from './wrapColumnWithAggregation';
|
|
8
|
+
import { GridAggregationColumnMenuItem } from '../../../components/GridAggregationColumnMenuItem';
|
|
9
|
+
import { gridAggregationModelSelector } from './gridAggregationSelectors';
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
|
|
12
|
+
const Divider = () => /*#__PURE__*/_jsx(MuiDivider, {
|
|
13
|
+
onClick: event => event.stopPropagation()
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export const useGridAggregationPreProcessors = (apiRef, props) => {
|
|
17
|
+
const updateAggregatedColumns = React.useCallback(columnsState => {
|
|
18
|
+
const {
|
|
19
|
+
rulesOnLastColumnHydration
|
|
20
|
+
} = apiRef.current.unstable_caches.aggregation;
|
|
21
|
+
const aggregationRules = props.disableAggregation ? {} : getAggregationRules({
|
|
22
|
+
columnsLookup: columnsState.lookup,
|
|
23
|
+
aggregationModel: gridAggregationModelSelector(apiRef),
|
|
24
|
+
aggregationFunctions: props.aggregationFunctions
|
|
25
|
+
});
|
|
26
|
+
columnsState.all.forEach(field => {
|
|
27
|
+
const shouldHaveAggregationValue = !!aggregationRules[field];
|
|
28
|
+
const haveAggregationColumnValue = !!rulesOnLastColumnHydration[field];
|
|
29
|
+
let column = columnsState.lookup[field];
|
|
30
|
+
|
|
31
|
+
if (haveAggregationColumnValue) {
|
|
32
|
+
column = unwrapColumnFromAggregation({
|
|
33
|
+
column
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (shouldHaveAggregationValue) {
|
|
38
|
+
column = wrapColumnWithAggregationValue({
|
|
39
|
+
column,
|
|
40
|
+
aggregationRule: aggregationRules[field],
|
|
41
|
+
apiRef
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
columnsState.lookup[field] = column;
|
|
46
|
+
});
|
|
47
|
+
apiRef.current.unstable_caches.aggregation.rulesOnLastColumnHydration = aggregationRules;
|
|
48
|
+
return columnsState;
|
|
49
|
+
}, [apiRef, props.aggregationFunctions, props.disableAggregation]);
|
|
50
|
+
const addGroupFooterRows = React.useCallback(groupingParams => {
|
|
51
|
+
let newGroupingParams;
|
|
52
|
+
let rulesOnLastRowHydration;
|
|
53
|
+
|
|
54
|
+
if (props.disableAggregation) {
|
|
55
|
+
newGroupingParams = groupingParams;
|
|
56
|
+
rulesOnLastRowHydration = {};
|
|
57
|
+
} else {
|
|
58
|
+
const aggregationRules = getAggregationRules({
|
|
59
|
+
columnsLookup: gridColumnLookupSelector(apiRef),
|
|
60
|
+
aggregationModel: gridAggregationModelSelector(apiRef),
|
|
61
|
+
aggregationFunctions: props.aggregationFunctions
|
|
62
|
+
});
|
|
63
|
+
rulesOnLastRowHydration = aggregationRules; // If no column have an aggregation rule
|
|
64
|
+
// Then don't create the footer rows
|
|
65
|
+
|
|
66
|
+
if (Object.values(aggregationRules).length === 0) {
|
|
67
|
+
newGroupingParams = groupingParams;
|
|
68
|
+
} else {
|
|
69
|
+
newGroupingParams = addFooterRows({
|
|
70
|
+
groupingParams,
|
|
71
|
+
aggregationRules,
|
|
72
|
+
getAggregationPosition: props.getAggregationPosition,
|
|
73
|
+
apiRef
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
apiRef.current.unstable_caches.aggregation.rulesOnLastRowHydration = rulesOnLastRowHydration;
|
|
79
|
+
return newGroupingParams;
|
|
80
|
+
}, [apiRef, props.disableAggregation, props.getAggregationPosition, props.aggregationFunctions]);
|
|
81
|
+
const addColumnMenuButtons = React.useCallback((initialValue, column) => {
|
|
82
|
+
if (props.disableAggregation) {
|
|
83
|
+
return initialValue;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const availableAggregationFunctions = getAvailableAggregationFunctions({
|
|
87
|
+
aggregationFunctions: props.aggregationFunctions,
|
|
88
|
+
column
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
if (availableAggregationFunctions.length === 0) {
|
|
92
|
+
return initialValue;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return [...initialValue, /*#__PURE__*/_jsx(Divider, {}), /*#__PURE__*/_jsx(GridAggregationColumnMenuItem, {
|
|
96
|
+
column: column,
|
|
97
|
+
label: apiRef.current.getLocaleText('aggregationMenuItemHeader'),
|
|
98
|
+
availableAggregationFunctions: availableAggregationFunctions
|
|
99
|
+
})];
|
|
100
|
+
}, [apiRef, props.aggregationFunctions, props.disableAggregation]);
|
|
101
|
+
const stateExportPreProcessing = React.useCallback(prevState => {
|
|
102
|
+
if (props.disableAggregation) {
|
|
103
|
+
return prevState;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const aggregationModelToExport = gridAggregationModelSelector(apiRef);
|
|
107
|
+
|
|
108
|
+
if (Object.values(aggregationModelToExport).length === 0) {
|
|
109
|
+
return prevState;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return _extends({}, prevState, {
|
|
113
|
+
aggregation: {
|
|
114
|
+
model: aggregationModelToExport
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
}, [apiRef, props.disableAggregation]);
|
|
118
|
+
const stateRestorePreProcessing = React.useCallback((params, context) => {
|
|
119
|
+
var _context$stateToResto;
|
|
120
|
+
|
|
121
|
+
if (props.disableAggregation) {
|
|
122
|
+
return params;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const aggregationModel = (_context$stateToResto = context.stateToRestore.aggregation) == null ? void 0 : _context$stateToResto.model;
|
|
126
|
+
|
|
127
|
+
if (aggregationModel != null) {
|
|
128
|
+
apiRef.current.setState(mergeStateWithAggregationModel(aggregationModel));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return params;
|
|
132
|
+
}, [apiRef, props.disableAggregation]);
|
|
133
|
+
useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', updateAggregatedColumns);
|
|
134
|
+
useGridRegisterPipeProcessor(apiRef, 'hydrateRows', addGroupFooterRows);
|
|
135
|
+
useGridRegisterPipeProcessor(apiRef, 'columnMenu', addColumnMenuButtons);
|
|
136
|
+
useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
|
|
137
|
+
useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
|
|
138
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { GridColDef } from '@mui/x-data-grid-pro';
|
|
3
|
+
import { GridApiPremium } from '../../../models/gridApiPremium';
|
|
4
|
+
import { GridAggregationRule } from './gridAggregationInterfaces';
|
|
5
|
+
declare const AGGREGATION_WRAPPABLE_PROPERTIES: readonly ["valueGetter", "valueFormatter", "renderCell", "renderHeader", "filterOperators"];
|
|
6
|
+
declare type WrappableColumnProperty = typeof AGGREGATION_WRAPPABLE_PROPERTIES[number];
|
|
7
|
+
interface GridColDefWithAggregationWrappers extends GridColDef {
|
|
8
|
+
aggregationWrappedProperties?: {
|
|
9
|
+
[P in WrappableColumnProperty]?: {
|
|
10
|
+
original: GridColDef[P];
|
|
11
|
+
wrapped: GridColDef[P];
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Add a wrapper around each wrappable property of the column to customize the behavior of the aggregation cells.
|
|
17
|
+
*/
|
|
18
|
+
export declare const wrapColumnWithAggregationValue: ({ column, apiRef, aggregationRule, }: {
|
|
19
|
+
column: GridColDef;
|
|
20
|
+
apiRef: React.MutableRefObject<GridApiPremium>;
|
|
21
|
+
aggregationRule: GridAggregationRule;
|
|
22
|
+
}) => GridColDef;
|
|
23
|
+
/**
|
|
24
|
+
* Remove the aggregation wrappers around the wrappable properties of the column.
|
|
25
|
+
*/
|
|
26
|
+
export declare const unwrapColumnFromAggregation: ({ column, }: {
|
|
27
|
+
column: GridColDefWithAggregationWrappers;
|
|
28
|
+
}) => GridColDef<any, any, any>;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { gridAggregationLookupSelector } from './gridAggregationSelectors';
|
|
4
|
+
import { GridFooterCell } from '../../../components/GridFooterCell';
|
|
5
|
+
import { GridAggregationHeader } from '../../../components/GridAggregationHeader';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
const AGGREGATION_WRAPPABLE_PROPERTIES = ['valueGetter', 'valueFormatter', 'renderCell', 'renderHeader', 'filterOperators'];
|
|
8
|
+
|
|
9
|
+
const getAggregationValueWrappedValueGetter = ({
|
|
10
|
+
value: valueGetter,
|
|
11
|
+
getCellAggregationResult
|
|
12
|
+
}) => {
|
|
13
|
+
const wrappedValueGetter = params => {
|
|
14
|
+
const cellAggregationResult = getCellAggregationResult(params.id, params.field);
|
|
15
|
+
|
|
16
|
+
if (cellAggregationResult != null) {
|
|
17
|
+
var _cellAggregationResul;
|
|
18
|
+
|
|
19
|
+
return (_cellAggregationResul = cellAggregationResult == null ? void 0 : cellAggregationResult.value) != null ? _cellAggregationResul : null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (valueGetter) {
|
|
23
|
+
return valueGetter(params);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return params.row[params.field];
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return wrappedValueGetter;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const getAggregationValueWrappedValueFormatter = ({
|
|
33
|
+
value: valueFormatter,
|
|
34
|
+
aggregationRule,
|
|
35
|
+
getCellAggregationResult
|
|
36
|
+
}) => {
|
|
37
|
+
// If neither the inline aggregation function nor the footer aggregation function have a custom value formatter,
|
|
38
|
+
// Then we don't wrap the column value formatter
|
|
39
|
+
if (!aggregationRule.aggregationFunction.valueFormatter) {
|
|
40
|
+
return valueFormatter;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const wrappedValueFormatter = params => {
|
|
44
|
+
if (params.id != null) {
|
|
45
|
+
const cellAggregationResult = getCellAggregationResult(params.id, params.field);
|
|
46
|
+
|
|
47
|
+
if (cellAggregationResult != null) {
|
|
48
|
+
return aggregationRule.aggregationFunction.valueFormatter(params);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (valueFormatter) {
|
|
53
|
+
return valueFormatter(params);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return params.value;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
return wrappedValueFormatter;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const getAggregationValueWrappedRenderCell = ({
|
|
63
|
+
value: renderCell,
|
|
64
|
+
aggregationRule,
|
|
65
|
+
getCellAggregationResult
|
|
66
|
+
}) => {
|
|
67
|
+
const wrappedRenderCell = params => {
|
|
68
|
+
const cellAggregationResult = getCellAggregationResult(params.id, params.field);
|
|
69
|
+
|
|
70
|
+
if (cellAggregationResult != null) {
|
|
71
|
+
var _aggregationFunction$;
|
|
72
|
+
|
|
73
|
+
if (!renderCell) {
|
|
74
|
+
if (cellAggregationResult.position === 'footer') {
|
|
75
|
+
return /*#__PURE__*/_jsx(GridFooterCell, _extends({}, params));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return params.formattedValue;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const aggregationMeta = {
|
|
82
|
+
hasCellUnit: (_aggregationFunction$ = aggregationRule.aggregationFunction.hasCellUnit) != null ? _aggregationFunction$ : true,
|
|
83
|
+
aggregationFunctionName: aggregationRule.aggregationFunctionName
|
|
84
|
+
};
|
|
85
|
+
return renderCell(_extends({}, params, {
|
|
86
|
+
aggregation: aggregationMeta
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (!renderCell) {
|
|
91
|
+
return params.formattedValue;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return renderCell(params);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
return wrappedRenderCell;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* Skips the filtering for aggregated rows
|
|
101
|
+
*/
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
const getWrappedFilterOperators = ({
|
|
105
|
+
value: filterOperators,
|
|
106
|
+
getCellAggregationResult
|
|
107
|
+
}) => filterOperators.map(operator => {
|
|
108
|
+
return _extends({}, operator, {
|
|
109
|
+
getApplyFilterFn: (filterItem, column) => {
|
|
110
|
+
const originalFn = operator.getApplyFilterFn(filterItem, column);
|
|
111
|
+
|
|
112
|
+
if (!originalFn) {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return params => {
|
|
117
|
+
if (getCellAggregationResult(params.id, params.field) != null) {
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return originalFn(params);
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
/**
|
|
127
|
+
* Add the aggregation method around the header name
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
const getWrappedRenderHeader = ({
|
|
132
|
+
value: renderHeader,
|
|
133
|
+
aggregationRule
|
|
134
|
+
}) => {
|
|
135
|
+
const wrappedRenderCell = params => {
|
|
136
|
+
const aggregationMeta = {
|
|
137
|
+
aggregationRule
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
if (!renderHeader) {
|
|
141
|
+
return /*#__PURE__*/_jsx(GridAggregationHeader, _extends({}, params, {
|
|
142
|
+
aggregation: aggregationMeta
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return renderHeader(_extends({}, params, {
|
|
147
|
+
aggregation: aggregationMeta
|
|
148
|
+
}));
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
return wrappedRenderCell;
|
|
152
|
+
};
|
|
153
|
+
/**
|
|
154
|
+
* Add a wrapper around each wrappable property of the column to customize the behavior of the aggregation cells.
|
|
155
|
+
*/
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
export const wrapColumnWithAggregationValue = ({
|
|
159
|
+
column,
|
|
160
|
+
apiRef,
|
|
161
|
+
aggregationRule
|
|
162
|
+
}) => {
|
|
163
|
+
const getCellAggregationResult = (id, field) => {
|
|
164
|
+
var _parent, _gridAggregationLooku;
|
|
165
|
+
|
|
166
|
+
let cellAggregationPosition = null;
|
|
167
|
+
|
|
168
|
+
if (id.toString().startsWith('auto-generated-row-')) {
|
|
169
|
+
cellAggregationPosition = 'inline';
|
|
170
|
+
} else if (id.toString().startsWith('auto-generated-group-footer-')) {
|
|
171
|
+
cellAggregationPosition = 'footer';
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (cellAggregationPosition == null) {
|
|
175
|
+
return null;
|
|
176
|
+
} // TODO: Add custom root id
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
const groupId = cellAggregationPosition === 'inline' ? id : (_parent = apiRef.current.getRowNode(id).parent) != null ? _parent : '';
|
|
180
|
+
const aggregationResult = (_gridAggregationLooku = gridAggregationLookupSelector(apiRef)[groupId]) == null ? void 0 : _gridAggregationLooku[field];
|
|
181
|
+
|
|
182
|
+
if (!aggregationResult || aggregationResult.position !== cellAggregationPosition) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return aggregationResult;
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const aggregationWrappedProperties = {};
|
|
190
|
+
|
|
191
|
+
const wrappedColumn = _extends({}, column, {
|
|
192
|
+
aggregationWrappedProperties
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
const wrapColumnProperty = (property, wrapper) => {
|
|
196
|
+
const originalValue = column[property];
|
|
197
|
+
const wrappedProperty = wrapper({
|
|
198
|
+
apiRef,
|
|
199
|
+
value: originalValue,
|
|
200
|
+
colDef: column,
|
|
201
|
+
aggregationRule,
|
|
202
|
+
getCellAggregationResult
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
if (wrappedProperty !== originalValue) {
|
|
206
|
+
aggregationWrappedProperties[property] = {
|
|
207
|
+
original: originalValue,
|
|
208
|
+
wrapped: wrappedProperty
|
|
209
|
+
};
|
|
210
|
+
wrappedColumn[property] = wrappedProperty;
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
wrapColumnProperty('valueGetter', getAggregationValueWrappedValueGetter);
|
|
215
|
+
wrapColumnProperty('valueFormatter', getAggregationValueWrappedValueFormatter);
|
|
216
|
+
wrapColumnProperty('renderCell', getAggregationValueWrappedRenderCell);
|
|
217
|
+
wrapColumnProperty('renderHeader', getWrappedRenderHeader);
|
|
218
|
+
wrapColumnProperty('filterOperators', getWrappedFilterOperators);
|
|
219
|
+
|
|
220
|
+
if (Object.keys(aggregationWrappedProperties).length === 0) {
|
|
221
|
+
return column;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return wrappedColumn;
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* Remove the aggregation wrappers around the wrappable properties of the column.
|
|
228
|
+
*/
|
|
229
|
+
|
|
230
|
+
export const unwrapColumnFromAggregation = ({
|
|
231
|
+
column
|
|
232
|
+
}) => {
|
|
233
|
+
if (!column.aggregationWrappedProperties) {
|
|
234
|
+
return column;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
const originalProperties = Object.entries(column.aggregationWrappedProperties);
|
|
238
|
+
|
|
239
|
+
if (originalProperties.length === 0) {
|
|
240
|
+
return column;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const unwrappedColumn = _extends({}, column);
|
|
244
|
+
|
|
245
|
+
originalProperties.forEach(([propertyName, {
|
|
246
|
+
original,
|
|
247
|
+
wrapped
|
|
248
|
+
}]) => {
|
|
249
|
+
// The value changed since we wrapped it
|
|
250
|
+
if (wrapped !== column[propertyName]) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
unwrappedColumn[propertyName] = original;
|
|
255
|
+
});
|
|
256
|
+
return unwrappedColumn;
|
|
257
|
+
};
|
|
@@ -46,7 +46,8 @@ const serializeRow = (id, columns, api, defaultValueOptionsFormulae) => {
|
|
|
46
46
|
api.unstable_calculateColSpan({
|
|
47
47
|
rowId: id,
|
|
48
48
|
minFirstColumn: 0,
|
|
49
|
-
maxLastColumn: columns.length
|
|
49
|
+
maxLastColumn: columns.length,
|
|
50
|
+
columns
|
|
50
51
|
});
|
|
51
52
|
columns.forEach((column, colIndex) => {
|
|
52
53
|
const colSpanInfo = api.unstable_getCellColSpanInfo(id, colIndex);
|
package/hooks/features/index.js
CHANGED
|
@@ -4,6 +4,7 @@ const _excluded = ["leafField", "mainGroupingCriteria", "hideDescendantCount"],
|
|
|
4
4
|
_excluded2 = ["leafField", "mainGroupingCriteria", "hideDescendantCount"];
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import { GRID_STRING_COL_DEF } from '@mui/x-data-grid-pro';
|
|
7
|
+
import { GridGroupingColumnFooterCell } from '../../../components/GridGroupingColumnFooterCell';
|
|
7
8
|
import { GridGroupingCriteriaCell } from '../../../components/GridGroupingCriteriaCell';
|
|
8
9
|
import { GridGroupingColumnLeafCell } from '../../../components/GridGroupingColumnLeafCell';
|
|
9
10
|
import { getRowGroupingFieldFromGroupingCriteria, GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD } from './gridRowGroupingUtils';
|
|
@@ -152,7 +153,12 @@ export const createGroupingColDefForOneGroupingCriteria = ({
|
|
|
152
153
|
const commonProperties = {
|
|
153
154
|
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
155
|
renderCell: params => {
|
|
155
|
-
// Render
|
|
156
|
+
// Render footer
|
|
157
|
+
if (params.rowNode.position === 'footer') {
|
|
158
|
+
return /*#__PURE__*/_jsx(GridGroupingColumnFooterCell, _extends({}, params));
|
|
159
|
+
} // Render leaves
|
|
160
|
+
|
|
161
|
+
|
|
156
162
|
if (params.rowNode.groupingField == null) {
|
|
157
163
|
if (leafColDef) {
|
|
158
164
|
const leafParams = _extends({}, params.api.getCellParams(params.id, leafField), {
|
|
@@ -253,7 +259,12 @@ export const createGroupingColDefForAllGroupingCriteria = ({
|
|
|
253
259
|
return ((_columnsLookup$field$ = columnsLookup[field].width) != null ? _columnsLookup$field$ : GRID_STRING_COL_DEF.width) + 40;
|
|
254
260
|
}), (_leafColDef$width2 = leafColDef == null ? void 0 : leafColDef.width) != null ? _leafColDef$width2 : 0),
|
|
255
261
|
renderCell: params => {
|
|
256
|
-
// Render
|
|
262
|
+
// Render footer
|
|
263
|
+
if (params.rowNode.position === 'footer') {
|
|
264
|
+
return /*#__PURE__*/_jsx(GridGroupingColumnFooterCell, _extends({}, params));
|
|
265
|
+
} // Render the leaves
|
|
266
|
+
|
|
267
|
+
|
|
257
268
|
if (params.rowNode.groupingField == null) {
|
|
258
269
|
if (leafColDef) {
|
|
259
270
|
const leafParams = _extends({}, params.api.getCellParams(params.id, leafField), {
|
|
@@ -79,13 +79,17 @@ export const filterRowTreeFromGroupingColumns = params => {
|
|
|
79
79
|
visibleRowsLookup[node.id] = shouldPassFilters && areAncestorsExpanded;
|
|
80
80
|
filteredRowsLookup[node.id] = shouldPassFilters;
|
|
81
81
|
|
|
82
|
+
if (node.footerId != null) {
|
|
83
|
+
visibleRowsLookup[node.footerId] = shouldPassFilters && areAncestorsExpanded && !!node.childrenExpanded;
|
|
84
|
+
}
|
|
85
|
+
|
|
82
86
|
if (!shouldPassFilters) {
|
|
83
87
|
return 0;
|
|
84
88
|
}
|
|
85
89
|
|
|
86
90
|
filteredDescendantCountLookup[node.id] = filteredDescendantCount;
|
|
87
91
|
|
|
88
|
-
if (!node.children) {
|
|
92
|
+
if (!node.children && !node.isAutoGenerated) {
|
|
89
93
|
return filteredDescendantCount + 1;
|
|
90
94
|
}
|
|
91
95
|
|
|
@@ -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<GridApiPremium>, props: Pick<DataGridPremiumProcessedProps, 'rowGroupingModel' | 'onRowGroupingModelChange' | 'defaultGroupingExpansionDepth' | 'isGroupExpandedByDefault' | 'groupingColDef' | 'rowGroupingColumnMode' | 'disableRowGrouping'>) => void;
|
|
11
|
+
export declare const useGridRowGrouping: (apiRef: React.MutableRefObject<GridApiPremium>, props: Pick<DataGridPremiumProcessedProps, 'initialState' | 'rowGroupingModel' | 'onRowGroupingModelChange' | 'defaultGroupingExpansionDepth' | 'isGroupExpandedByDefault' | 'groupingColDef' | 'rowGroupingColumnMode' | 'disableRowGrouping'>) => void;
|