@mui/x-data-grid-premium 8.13.0 → 8.14.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 +171 -1
- package/DataGridPremium/DataGridPremium.js +7 -5
- package/DataGridPremium/useDataGridPremiumProps.js +3 -2
- package/components/GridDataSourceGroupingCriteriaCell.js +8 -2
- package/components/GridPremiumToolbar.js +1 -2
- package/components/pivotPanel/GridPivotPanelField.js +4 -4
- package/esm/DataGridPremium/DataGridPremium.js +7 -5
- package/esm/DataGridPremium/useDataGridPremiumProps.js +3 -2
- package/esm/components/GridDataSourceGroupingCriteriaCell.js +9 -3
- package/esm/components/GridPremiumToolbar.js +1 -2
- package/esm/components/pivotPanel/GridPivotPanelField.js +4 -4
- package/esm/hooks/features/aggregation/useGridAggregation.js +3 -2
- package/esm/hooks/features/dataSource/models.d.ts +52 -1
- package/esm/hooks/features/dataSource/useGridDataSourcePremium.js +30 -5
- package/esm/hooks/features/dataSource/utils.d.ts +6 -0
- package/esm/hooks/features/dataSource/utils.js +140 -0
- package/esm/hooks/features/index.d.ts +2 -1
- package/esm/hooks/features/index.js +2 -1
- package/esm/hooks/features/pivoting/gridPivotingInterfaces.d.ts +23 -13
- package/esm/hooks/features/pivoting/gridPivotingSelectors.d.ts +1 -1
- package/esm/hooks/features/pivoting/index.d.ts +1 -0
- package/esm/hooks/features/pivoting/index.js +1 -0
- package/esm/hooks/features/pivoting/useGridPivoting.d.ts +1 -1
- package/esm/hooks/features/pivoting/useGridPivoting.js +83 -32
- package/esm/hooks/features/pivoting/utils.d.ts +7 -9
- package/esm/hooks/features/pivoting/utils.js +39 -24
- package/esm/hooks/features/rowGrouping/createGroupingColDef.js +1 -1
- package/esm/hooks/features/rowGrouping/useGridDataSourceRowGroupingPreProcessors.js +7 -3
- package/esm/hooks/features/rowGrouping/useGridRowGrouping.d.ts +1 -1
- package/esm/index.js +1 -1
- package/esm/models/dataGridPremiumProps.d.ts +15 -14
- package/hooks/features/aggregation/useGridAggregation.js +2 -1
- package/hooks/features/dataSource/models.d.ts +52 -1
- package/hooks/features/dataSource/useGridDataSourcePremium.js +29 -4
- package/hooks/features/dataSource/utils.d.ts +6 -0
- package/hooks/features/dataSource/utils.js +148 -0
- package/hooks/features/index.d.ts +2 -1
- package/hooks/features/index.js +11 -0
- package/hooks/features/pivoting/gridPivotingInterfaces.d.ts +23 -13
- package/hooks/features/pivoting/gridPivotingSelectors.d.ts +1 -1
- package/hooks/features/pivoting/index.d.ts +1 -0
- package/hooks/features/pivoting/index.js +12 -0
- package/hooks/features/pivoting/useGridPivoting.d.ts +1 -1
- package/hooks/features/pivoting/useGridPivoting.js +82 -31
- package/hooks/features/pivoting/utils.d.ts +7 -9
- package/hooks/features/pivoting/utils.js +42 -27
- package/hooks/features/rowGrouping/createGroupingColDef.js +1 -1
- package/hooks/features/rowGrouping/useGridDataSourceRowGroupingPreProcessors.js +6 -2
- package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +1 -1
- package/index.js +1 -1
- package/models/dataGridPremiumProps.d.ts +15 -14
- package/package.json +6 -7
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { gridRowTreeSelector, gridColumnLookupSelector } from '@mui/x-data-grid-pro';
|
|
3
|
-
import { useGridRegisterStrategyProcessor, createRowTree, updateRowTree, getVisibleRowsLookup, skipSorting, skipFiltering, getParentPath, RowGroupingStrategy } from '@mui/x-data-grid-pro/internals';
|
|
3
|
+
import { useGridRegisterStrategyProcessor, createRowTree, updateRowTree, getVisibleRowsLookup, skipSorting, skipFiltering, getParentPath, RowGroupingStrategy, gridPivotActiveSelector } from '@mui/x-data-grid-pro/internals';
|
|
4
4
|
import { getGroupingRules } from "./gridRowGroupingUtils.js";
|
|
5
5
|
import { gridRowGroupingSanitizedModelSelector } from "./gridRowGroupingSelector.js";
|
|
6
6
|
export const useGridDataSourceRowGroupingPreProcessors = (apiRef, props) => {
|
|
@@ -13,7 +13,9 @@ export const useGridDataSourceRowGroupingPreProcessors = (apiRef, props) => {
|
|
|
13
13
|
if (!getChildrenCount) {
|
|
14
14
|
throw new Error('MUI X: No `getChildrenCount` method provided with the dataSource.');
|
|
15
15
|
}
|
|
16
|
+
const pivotingActive = gridPivotActiveSelector(apiRef);
|
|
16
17
|
const sanitizedRowGroupingModel = gridRowGroupingSanitizedModelSelector(apiRef);
|
|
18
|
+
const maxDepth = pivotingActive ? sanitizedRowGroupingModel.length - 1 : undefined;
|
|
17
19
|
const columnsLookup = gridColumnLookupSelector(apiRef);
|
|
18
20
|
const groupingRules = getGroupingRules({
|
|
19
21
|
sanitizedRowGroupingModel,
|
|
@@ -38,7 +40,8 @@ export const useGridDataSourceRowGroupingPreProcessors = (apiRef, props) => {
|
|
|
38
40
|
nodes: params.updates.rows.map(getRowTreeBuilderNode),
|
|
39
41
|
defaultGroupingExpansionDepth: props.defaultGroupingExpansionDepth,
|
|
40
42
|
isGroupExpandedByDefault: props.isGroupExpandedByDefault,
|
|
41
|
-
groupingName: RowGroupingStrategy.DataSource
|
|
43
|
+
groupingName: RowGroupingStrategy.DataSource,
|
|
44
|
+
maxDepth
|
|
42
45
|
});
|
|
43
46
|
}
|
|
44
47
|
return updateRowTree({
|
|
@@ -52,7 +55,8 @@ export const useGridDataSourceRowGroupingPreProcessors = (apiRef, props) => {
|
|
|
52
55
|
previousTreeDepth: params.previousTreeDepths,
|
|
53
56
|
defaultGroupingExpansionDepth: props.defaultGroupingExpansionDepth,
|
|
54
57
|
isGroupExpandedByDefault: props.isGroupExpandedByDefault,
|
|
55
|
-
groupingName: RowGroupingStrategy.DataSource
|
|
58
|
+
groupingName: RowGroupingStrategy.DataSource,
|
|
59
|
+
maxDepth
|
|
56
60
|
});
|
|
57
61
|
}, [apiRef, props.dataSource, props.defaultGroupingExpansionDepth, props.isGroupExpandedByDefault]);
|
|
58
62
|
const filterRows = React.useCallback(() => {
|
|
@@ -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: RefObject<GridPrivateApiPremium>, props: Pick<DataGridPremiumProcessedProps, "initialState" | "rowGroupingModel" | "onRowGroupingModelChange" | "
|
|
11
|
+
export declare const useGridRowGrouping: (apiRef: RefObject<GridPrivateApiPremium>, props: Pick<DataGridPremiumProcessedProps, "initialState" | "rowGroupingModel" | "onRowGroupingModelChange" | "isGroupExpandedByDefault" | "rowGroupingColumnMode" | "disableRowGrouping" | "slotProps" | "slots" | "dataSource" | "treeData">) => void;
|
package/esm/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import { GridPremiumSlotProps } from "./gridPremiumSlotProps.js";
|
|
|
8
8
|
import { GridInitialStatePremium } from "./gridStatePremium.js";
|
|
9
9
|
import { GridApiPremium } from "./gridApiPremium.js";
|
|
10
10
|
import { GridCellSelectionModel } from "../hooks/features/cellSelection/index.js";
|
|
11
|
-
import type { GridPivotingColDefOverrides, GridPivotModel } from "../hooks/features/pivoting/gridPivotingInterfaces.js";
|
|
11
|
+
import type { GridPivotingColDefOverrides, PivotingColDefCallback, GridPivotModel } from "../hooks/features/pivoting/gridPivotingInterfaces.js";
|
|
12
12
|
import { GridDataSourcePremium as GridDataSource, GridGetRowsParamsPremium as GridGetRowsParams } from "../hooks/features/dataSource/models.js";
|
|
13
13
|
import { Conversation, PromptResponse, PromptSuggestion } from "../hooks/features/aiAssistant/gridAiAssistantInterfaces.js";
|
|
14
14
|
export interface GridExperimentalPremiumFeatures extends GridExperimentalProFeatures {
|
|
@@ -91,15 +91,6 @@ export interface DataGridPremiumPropsWithDefaultValue<R extends GridValidRowMode
|
|
|
91
91
|
* @default false
|
|
92
92
|
*/
|
|
93
93
|
disablePivoting: boolean;
|
|
94
|
-
/**
|
|
95
|
-
* Allows to generate derived columns from actual columns that will be used for pivoting.
|
|
96
|
-
* Useful e.g. for date columns to generate year, quarter, month, etc.
|
|
97
|
-
* @param {GridColDef} column The column to generate derived columns for.
|
|
98
|
-
* @param {GridLocaleTextApi['getLocaleText']} getLocaleText The function to get the locale text.
|
|
99
|
-
* @returns {GridColDef[] | undefined} The derived columns.
|
|
100
|
-
* @default {defaultGetPivotDerivedColumns} Creates year and quarter columns for date columns.
|
|
101
|
-
*/
|
|
102
|
-
getPivotDerivedColumns: ((column: GridColDef, getLocaleText: GridLocaleTextApi['getLocaleText']) => GridColDef[] | undefined) | null;
|
|
103
94
|
/**
|
|
104
95
|
* If `true`, the AI Assistant is enabled.
|
|
105
96
|
* @default false
|
|
@@ -226,14 +217,24 @@ export interface DataGridPremiumPropsWithoutDefaultValue<R extends GridValidRowM
|
|
|
226
217
|
* @deprecated Use the `sidebarOpen` and `sidebarClose` events or corresponding event handlers `onSidebarOpen()` and `onSidebarClose()` instead.
|
|
227
218
|
*/
|
|
228
219
|
onPivotPanelOpenChange?: (pivotPanelOpen: boolean) => void;
|
|
220
|
+
/**
|
|
221
|
+
* Allows to generate derived columns from actual columns that will be used for pivoting.
|
|
222
|
+
* Useful e.g. for date columns to generate year, quarter, month, etc.
|
|
223
|
+
* @param {GridColDef} column The column to generate derived columns for.
|
|
224
|
+
* @param {GridLocaleTextApi['getLocaleText']} getLocaleText The function to get the locale text.
|
|
225
|
+
* @returns {GridColDef[] | undefined} The derived columns.
|
|
226
|
+
* @default {defaultGetPivotDerivedColumns | undefined} Creates year and quarter columns for date columns if not in server side mode.
|
|
227
|
+
*/
|
|
228
|
+
getPivotDerivedColumns?: ((column: GridColDef, getLocaleText: GridLocaleTextApi['getLocaleText']) => GridColDef[] | undefined) | null;
|
|
229
229
|
/**
|
|
230
230
|
* The column definition overrides for the columns generated by the pivoting feature.
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
* @
|
|
231
|
+
* Pass either a partial column definition to apply the same overrides to all pivot columns, or a callback to apply different overrides to each pivot column.
|
|
232
|
+
* For server-side pivoting, only the `PivotingColDefCallback` signature is supported, and the prop is required.
|
|
233
|
+
* @type {Partial<GridPivotingColDefOverrides> | PivotingColDefCallback}
|
|
234
234
|
* @default undefined
|
|
235
|
+
* @throws {Error} If `undefined` and `dataSource` is provided.
|
|
235
236
|
*/
|
|
236
|
-
pivotingColDef?: Partial<GridPivotingColDefOverrides> |
|
|
237
|
+
pivotingColDef?: Partial<GridPivotingColDefOverrides> | PivotingColDefCallback;
|
|
237
238
|
/**
|
|
238
239
|
* The conversations with the AI Assistant.
|
|
239
240
|
*/
|
|
@@ -164,6 +164,7 @@ const useGridAggregation = (apiRef, props) => {
|
|
|
164
164
|
* EVENTS
|
|
165
165
|
*/
|
|
166
166
|
const checkAggregationRulesDiff = React.useCallback(() => {
|
|
167
|
+
const pivotingActive = (0, _internals.gridPivotActiveSelector)(apiRef);
|
|
167
168
|
const {
|
|
168
169
|
rulesOnLastRowHydration,
|
|
169
170
|
rulesOnLastColumnHydration
|
|
@@ -171,7 +172,7 @@ const useGridAggregation = (apiRef, props) => {
|
|
|
171
172
|
const aggregationRules = props.disableAggregation ? {} : (0, _gridAggregationUtils.getAggregationRules)((0, _xDataGridPro.gridColumnLookupSelector)(apiRef), (0, _gridAggregationSelectors.gridAggregationModelSelector)(apiRef), props.aggregationFunctions, !!props.dataSource);
|
|
172
173
|
|
|
173
174
|
// Re-apply the row hydration to add / remove the aggregation footers
|
|
174
|
-
if (!props.dataSource && !(0, _gridAggregationUtils.areAggregationRulesEqual)(rulesOnLastRowHydration, aggregationRules)) {
|
|
175
|
+
if ((!props.dataSource || pivotingActive) && !(0, _gridAggregationUtils.areAggregationRulesEqual)(rulesOnLastRowHydration, aggregationRules)) {
|
|
175
176
|
apiRef.current.requestPipeProcessorsApplication('hydrateRows');
|
|
176
177
|
deferredApplyAggregation();
|
|
177
178
|
}
|
|
@@ -1,5 +1,22 @@
|
|
|
1
|
-
import type { GridColDef, GridRowId, GridValidRowModel, GridDataSource, GridGetRowsResponse, GridGetRowsParams, GridDataSourceApiBase, GridDataSourcePrivateApi } from '@mui/x-data-grid-pro';
|
|
1
|
+
import type { GridColDef, GridRowId, GridValidRowModel, GridDataSource, GridGetRowsResponse, GridGetRowsParams, GridDataSourceApiBase, GridDataSourcePrivateApi, GridRowModel } from '@mui/x-data-grid-pro';
|
|
2
2
|
import type { GridAggregationModel } from "../aggregation/gridAggregationInterfaces.js";
|
|
3
|
+
import type { GridPivotModel } from "../pivoting/gridPivotingInterfaces.js";
|
|
4
|
+
export interface GridGetRowsResponsePivotColumn {
|
|
5
|
+
key: string;
|
|
6
|
+
group: string | GridRowModel;
|
|
7
|
+
children?: GridGetRowsResponsePivotColumn[];
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Path to a pivot column group.
|
|
11
|
+
* @param {string} key Pivot column key.
|
|
12
|
+
* @param {string} field Pivot column field.
|
|
13
|
+
* @param {string | GridRowModel} value Path value that is either a string or a part of row model needed to get the formatted value of the original column.
|
|
14
|
+
*/
|
|
15
|
+
export interface GridDataSourcePivotColumnGroupPath {
|
|
16
|
+
key: string;
|
|
17
|
+
field: string;
|
|
18
|
+
value: string | GridRowModel;
|
|
19
|
+
}
|
|
3
20
|
export interface GridGetRowsResponsePremium extends GridGetRowsResponse {
|
|
4
21
|
/**
|
|
5
22
|
* Row to be used for aggregation footer row.
|
|
@@ -7,6 +24,32 @@ export interface GridGetRowsResponsePremium extends GridGetRowsResponse {
|
|
|
7
24
|
* `GridGetRowsParams.aggregationModel`.
|
|
8
25
|
*/
|
|
9
26
|
aggregateRow?: GridValidRowModel;
|
|
27
|
+
/**
|
|
28
|
+
* Defines the structure of pivot columns to be created from the pivoted data.
|
|
29
|
+
* Each node in the tree must have a `key` and `group` property.
|
|
30
|
+
* `key` is used to identify the column group and will be passed to the `pivotingColDef` callback as the column path parameter.
|
|
31
|
+
* `group` is either a string or a part of a row model needed to get the formatted value of the original column.
|
|
32
|
+
* optionally,`children` is a list of the next level nodes.
|
|
33
|
+
* Each node at the last level of the tree will be a column group containing each pivot value as a column.
|
|
34
|
+
*
|
|
35
|
+
* Structure:
|
|
36
|
+
* The `group` property can be a string or an object:
|
|
37
|
+
* - Strings are used directly as column group header names (e.g. `"2025"`, `"January"`)
|
|
38
|
+
* - Objects contain data that will be formatted into header names using the column's valueFormatter or valueGetter
|
|
39
|
+
* (e.g. `{date: "2025-01-01"}` could be formatted as `"Jan 2025"`)
|
|
40
|
+
*
|
|
41
|
+
* Examples:
|
|
42
|
+
* - `[{key: "Y", group: "Yes"}, {key: "N", group: "No"}]` - Creates column groups with values "Yes" and "No"
|
|
43
|
+
* - `[{key: "2025", group: "2025", children: [{key: "January", group: "January"}, {key: "February", group: "February"}]}]` - Creates a column group with value "2025"
|
|
44
|
+
* that has column groups "January" and "February"
|
|
45
|
+
* - `[
|
|
46
|
+
* {key: "2025-01", group: {date: "2025-01-01"}, children: [{key: "01", group: {date: "2025-01-01"}}]},
|
|
47
|
+
* {key: "2025-02", group: {date: "2025-02-01"}, children: [{key: "02", group: {date: "2025-02-01"}}]},
|
|
48
|
+
* ]` - Creates two levels of column groups with values returned from the value formatters of the columns used for pivoting.
|
|
49
|
+
* Even though the same values are passed, the header names can be different based on the valueFormatter or valueGetter.
|
|
50
|
+
* One pivoting column may format the date as a year and the other as a month.
|
|
51
|
+
*/
|
|
52
|
+
pivotColumns?: GridGetRowsResponsePivotColumn[];
|
|
10
53
|
}
|
|
11
54
|
export interface GridGetRowsParamsPremium extends GridGetRowsParams {
|
|
12
55
|
/**
|
|
@@ -17,6 +60,14 @@ export interface GridGetRowsParamsPremium extends GridGetRowsParams {
|
|
|
17
60
|
* List of grouped columns (only applicable with `rowGrouping`).
|
|
18
61
|
*/
|
|
19
62
|
groupFields?: GridColDef['field'][];
|
|
63
|
+
/**
|
|
64
|
+
* Visible rows, columns and values from the pivot model (only applicable with `pivoting`).
|
|
65
|
+
*/
|
|
66
|
+
pivotModel?: {
|
|
67
|
+
columns: Omit<GridPivotModel['columns'], 'hidden'>;
|
|
68
|
+
rows: Omit<GridPivotModel['rows'], 'hidden'>;
|
|
69
|
+
values: Omit<GridPivotModel['values'], 'hidden'>;
|
|
70
|
+
};
|
|
20
71
|
}
|
|
21
72
|
export interface GridDataSourcePremium extends Omit<GridDataSource, 'getRows'> {
|
|
22
73
|
/**
|
|
@@ -11,8 +11,10 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
|
|
|
11
11
|
var React = _interopRequireWildcard(require("react"));
|
|
12
12
|
var _xDataGridPro = require("@mui/x-data-grid-pro");
|
|
13
13
|
var _internals = require("@mui/x-data-grid-pro/internals");
|
|
14
|
+
var _gridPivotingSelectors = require("../pivoting/gridPivotingSelectors");
|
|
15
|
+
var _utils = require("./utils");
|
|
14
16
|
function getKeyPremium(params) {
|
|
15
|
-
return JSON.stringify([params.filterModel, params.sortModel, params.groupKeys, params.groupFields, params.start, params.end, params.aggregationModel]);
|
|
17
|
+
return JSON.stringify([params.filterModel, params.sortModel, params.groupKeys, params.groupFields, params.start, params.end, params.pivotModel ? {} : params.aggregationModel, params.pivotModel]);
|
|
16
18
|
}
|
|
17
19
|
const options = {
|
|
18
20
|
cacheOptions: {
|
|
@@ -28,6 +30,9 @@ const useGridDataSourcePremium = (apiRef, props) => {
|
|
|
28
30
|
setStrategyAvailability
|
|
29
31
|
} = (0, _internals.useGridDataSourceBasePro)(apiRef, props, options);
|
|
30
32
|
const aggregateRowRef = React.useRef({});
|
|
33
|
+
const initialColumns = (0, _internals.gridPivotInitialColumnsSelector)(apiRef);
|
|
34
|
+
const pivotActive = (0, _internals.gridPivotActiveSelector)(apiRef);
|
|
35
|
+
const pivotModel = (0, _gridPivotingSelectors.gridPivotModelSelector)(apiRef);
|
|
31
36
|
const processDataSourceRows = React.useCallback(({
|
|
32
37
|
params,
|
|
33
38
|
response
|
|
@@ -41,11 +46,29 @@ const useGridDataSourcePremium = (apiRef, props) => {
|
|
|
41
46
|
}
|
|
42
47
|
apiRef.current.applyAggregation();
|
|
43
48
|
}
|
|
49
|
+
if (response.pivotColumns) {
|
|
50
|
+
const pivotingColDef = props.pivotingColDef;
|
|
51
|
+
if (!pivotingColDef || typeof pivotingColDef !== 'function') {
|
|
52
|
+
throw new Error('MUI X: No `pivotingColDef()` prop provided with to the Data Grid, but response contains `pivotColumns`.\n\n\
|
|
53
|
+
You need a callback to return at least a field column prop for each generated pivot column.\n\n\
|
|
54
|
+
See [server-side pivoting](https://mui.com/x/react-data-grid/server-side-data/pivoting/) documentation for more details.');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Update the grid state with new columns and column grouping model
|
|
58
|
+
const partialPropsOverrides = (0, _utils.getPropsOverrides)(response.pivotColumns, pivotingColDef, pivotModel, initialColumns, apiRef);
|
|
59
|
+
apiRef.current.setState(state => {
|
|
60
|
+
return (0, _extends2.default)({}, state, {
|
|
61
|
+
pivoting: (0, _extends2.default)({}, state.pivoting, {
|
|
62
|
+
propsOverrides: (0, _extends2.default)({}, state.pivoting.propsOverrides, partialPropsOverrides)
|
|
63
|
+
})
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
44
67
|
return {
|
|
45
68
|
params,
|
|
46
69
|
response
|
|
47
70
|
};
|
|
48
|
-
}, [apiRef]);
|
|
71
|
+
}, [apiRef, props.pivotingColDef, initialColumns, pivotModel]);
|
|
49
72
|
const resolveGroupAggregation = React.useCallback((groupId, field) => {
|
|
50
73
|
if (groupId === _xDataGridPro.GRID_ROOT_GROUP_ID) {
|
|
51
74
|
return props.dataSource?.getAggregatedValue?.(aggregateRowRef.current, field);
|
|
@@ -63,8 +86,10 @@ const useGridDataSourcePremium = (apiRef, props) => {
|
|
|
63
86
|
Object.entries(events).forEach(([event, handler]) => {
|
|
64
87
|
(0, _xDataGridPro.useGridEvent)(apiRef, event, handler);
|
|
65
88
|
});
|
|
66
|
-
(0, _xDataGridPro.useGridEvent)(apiRef, 'rowGroupingModelChange', () => debouncedFetchRows());
|
|
67
|
-
(0, _xDataGridPro.useGridEvent)(apiRef, 'aggregationModelChange', () => debouncedFetchRows());
|
|
89
|
+
(0, _xDataGridPro.useGridEvent)(apiRef, 'rowGroupingModelChange', (0, _internals.runIf)(!pivotActive, () => debouncedFetchRows()));
|
|
90
|
+
(0, _xDataGridPro.useGridEvent)(apiRef, 'aggregationModelChange', (0, _internals.runIf)(!pivotActive, () => debouncedFetchRows()));
|
|
91
|
+
(0, _xDataGridPro.useGridEvent)(apiRef, 'pivotModeChange', (0, _internals.runIf)(!pivotActive, () => debouncedFetchRows()));
|
|
92
|
+
(0, _xDataGridPro.useGridEvent)(apiRef, 'pivotModelChange', (0, _internals.runIf)(pivotActive, () => debouncedFetchRows()));
|
|
68
93
|
React.useEffect(() => {
|
|
69
94
|
setStrategyAvailability();
|
|
70
95
|
}, [setStrategyAvailability]);
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RefObject } from '@mui/x-internals/types';
|
|
2
|
+
import { GridColDef } from '@mui/x-data-grid-pro';
|
|
3
|
+
import type { GridPrivateApiPremium } from "../../../models/gridApiPremium.js";
|
|
4
|
+
import type { GridPivotingDynamicPropsOverrides, PivotingColDefCallback, GridPivotModel } from "../pivoting/gridPivotingInterfaces.js";
|
|
5
|
+
import type { GridGetRowsResponsePivotColumn } from "./models.js";
|
|
6
|
+
export declare const getPropsOverrides: (pivotColumns: GridGetRowsResponsePivotColumn[], pivotingColDef: PivotingColDefCallback, pivotModel: GridPivotModel, initialColumns: Map<string, GridColDef>, apiRef: RefObject<GridPrivateApiPremium>) => GridPivotingDynamicPropsOverrides;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.getPropsOverrides = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _xDataGridPro = require("@mui/x-data-grid-pro");
|
|
10
|
+
const getPropsOverrides = (pivotColumns, pivotingColDef, pivotModel, initialColumns, apiRef) => {
|
|
11
|
+
const visiblePivotColumns = pivotModel.columns.filter(column => !column.hidden);
|
|
12
|
+
const visiblePivotValues = pivotModel.values.filter(value => !value.hidden);
|
|
13
|
+
const columns = Array.from(initialColumns.values());
|
|
14
|
+
|
|
15
|
+
// Build column grouping model from pivot column paths
|
|
16
|
+
const columnGroupingModel = [];
|
|
17
|
+
const columnGroupingModelLookup = new Map();
|
|
18
|
+
|
|
19
|
+
// Build new columns lookup and ordered fields
|
|
20
|
+
const newColumns = {};
|
|
21
|
+
|
|
22
|
+
// Build aggregation model
|
|
23
|
+
const aggregationModel = {};
|
|
24
|
+
|
|
25
|
+
// Create unique combinations of all values from pivotColumns and pivotValues
|
|
26
|
+
const uniquePaths = [];
|
|
27
|
+
const processPath = (currentPath, remainingColumns, level) => {
|
|
28
|
+
if (level === visiblePivotColumns.length) {
|
|
29
|
+
uniquePaths.push([...currentPath]);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
remainingColumns.forEach(column => {
|
|
33
|
+
processPath([...currentPath, {
|
|
34
|
+
key: column.key,
|
|
35
|
+
field: visiblePivotColumns[level].field,
|
|
36
|
+
value: column.group
|
|
37
|
+
}], column.children || [], level + 1);
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
processPath([], pivotColumns, 0);
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Column group headers are sorted by the leaf columns order in the column definition.
|
|
44
|
+
* Store the values of each column group path to be able to sort them by pivot column sort order.
|
|
45
|
+
* The values are stored by the column group level which allows easier sorting by going through the column group levels in reverse order.
|
|
46
|
+
* Store raw value to be able to determine if the value was formatted on the client using `getRowValue`.
|
|
47
|
+
* Values sent from the server as strings will not be sorted on the client.
|
|
48
|
+
*/
|
|
49
|
+
const columnGroupPathValues = [];
|
|
50
|
+
uniquePaths.forEach(columnPath => {
|
|
51
|
+
const columnPathKeys = columnPath.map(path => path.key);
|
|
52
|
+
const columnPathValues = columnPath.map(path => path.value);
|
|
53
|
+
visiblePivotValues.forEach(pivotValue => {
|
|
54
|
+
// Find the original column definition for the last field
|
|
55
|
+
const originalColumn = initialColumns.get(pivotValue.field);
|
|
56
|
+
// get the overrides defined from the data source definition
|
|
57
|
+
const overrides = pivotingColDef(pivotValue.field, columnPathKeys);
|
|
58
|
+
|
|
59
|
+
// Create new column definition based on original column
|
|
60
|
+
const newColumnDef = (0, _extends2.default)({}, originalColumn, overrides, {
|
|
61
|
+
aggregable: false,
|
|
62
|
+
groupable: false,
|
|
63
|
+
filterable: false,
|
|
64
|
+
hideable: false,
|
|
65
|
+
editable: false,
|
|
66
|
+
disableReorder: true
|
|
67
|
+
});
|
|
68
|
+
const pivotFieldName = newColumnDef.field;
|
|
69
|
+
newColumns[pivotFieldName] = newColumnDef;
|
|
70
|
+
aggregationModel[pivotFieldName] = pivotValue.aggFunc;
|
|
71
|
+
|
|
72
|
+
// Build column grouping model
|
|
73
|
+
const combinedPathValues = [...columnPathValues, pivotValue.field].map((path, index) => typeof path === 'string' ? path : apiRef.current.getRowValue(path, initialColumns.get(visiblePivotColumns[index].field)));
|
|
74
|
+
columnGroupPathValues.push({
|
|
75
|
+
field: pivotFieldName,
|
|
76
|
+
pathValues: combinedPathValues.slice(0, -1),
|
|
77
|
+
pathValuesRaw: columnPathValues
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
// Build the hierarchy for column groups
|
|
81
|
+
for (let i = 0; i < combinedPathValues.length - 1; i += 1) {
|
|
82
|
+
const currentField = visiblePivotColumns[i].field;
|
|
83
|
+
const groupPath = combinedPathValues.slice(0, i + 1);
|
|
84
|
+
const groupId = groupPath.join('-');
|
|
85
|
+
let headerName = columnPathValues[groupPath.length - 1];
|
|
86
|
+
if (typeof headerName !== 'string') {
|
|
87
|
+
headerName = apiRef.current.getRowFormattedValue(headerName, initialColumns.get(currentField));
|
|
88
|
+
}
|
|
89
|
+
if (typeof headerName === 'number') {
|
|
90
|
+
headerName = String(headerName);
|
|
91
|
+
}
|
|
92
|
+
if (typeof headerName !== 'string') {
|
|
93
|
+
throw new Error(`MUI X: Header name for a column group based on ${currentField} cannot be converted to a string.`);
|
|
94
|
+
}
|
|
95
|
+
if (!columnGroupingModelLookup.has(groupId)) {
|
|
96
|
+
const columnGroup = {
|
|
97
|
+
groupId,
|
|
98
|
+
headerName,
|
|
99
|
+
children: []
|
|
100
|
+
};
|
|
101
|
+
columnGroupingModelLookup.set(groupId, columnGroup);
|
|
102
|
+
if (i === 0) {
|
|
103
|
+
columnGroupingModel.push(columnGroup);
|
|
104
|
+
} else {
|
|
105
|
+
const parentGroupId = groupPath.slice(0, -1).join('-');
|
|
106
|
+
const parentGroup = columnGroupingModelLookup.get(parentGroupId);
|
|
107
|
+
if (parentGroup) {
|
|
108
|
+
parentGroup.children.push(columnGroup);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Add the final column to the appropriate group
|
|
115
|
+
const parentGroupId = combinedPathValues.slice(0, -1).join('-');
|
|
116
|
+
const parentGroup = columnGroupingModelLookup.get(parentGroupId);
|
|
117
|
+
if (parentGroup) {
|
|
118
|
+
parentGroup.children.push({
|
|
119
|
+
field: pivotFieldName
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
for (let i = visiblePivotColumns.length - 1; i >= 0; i -= 1) {
|
|
125
|
+
const sort = visiblePivotColumns[i].sort;
|
|
126
|
+
if (!sort) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
columnGroupPathValues.sort((a, b) => {
|
|
130
|
+
// Do not sort values that are returned as strings
|
|
131
|
+
if (typeof a.pathValuesRaw[i] === 'string' && typeof b.pathValuesRaw[i] === 'string') {
|
|
132
|
+
return 0;
|
|
133
|
+
}
|
|
134
|
+
return (sort === 'asc' ? 1 : -1) * (0, _xDataGridPro.gridStringOrNumberComparator)(a.pathValues[i], b.pathValues[i], {}, {});
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (visiblePivotColumns.length > 0) {
|
|
138
|
+
for (let i = 0; i < columnGroupPathValues.length; i += 1) {
|
|
139
|
+
columns.push(newColumns[columnGroupPathValues[i].field]);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return {
|
|
143
|
+
columns,
|
|
144
|
+
columnGroupingModel,
|
|
145
|
+
aggregationModel
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
exports.getPropsOverrides = getPropsOverrides;
|
|
@@ -3,4 +3,5 @@ export * from "./rowGrouping/index.js";
|
|
|
3
3
|
export * from "./export/index.js";
|
|
4
4
|
export * from "./cellSelection/index.js";
|
|
5
5
|
export * from "./aiAssistant/index.js";
|
|
6
|
-
export * from "./sidebar/index.js";
|
|
6
|
+
export * from "./sidebar/index.js";
|
|
7
|
+
export * from "./pivoting/index.js";
|
package/hooks/features/index.js
CHANGED
|
@@ -68,4 +68,15 @@ Object.keys(_sidebar).forEach(function (key) {
|
|
|
68
68
|
return _sidebar[key];
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
|
+
});
|
|
72
|
+
var _pivoting = require("./pivoting");
|
|
73
|
+
Object.keys(_pivoting).forEach(function (key) {
|
|
74
|
+
if (key === "default" || key === "__esModule") return;
|
|
75
|
+
if (key in exports && exports[key] === _pivoting[key]) return;
|
|
76
|
+
Object.defineProperty(exports, key, {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () {
|
|
79
|
+
return _pivoting[key];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
71
82
|
});
|
|
@@ -3,22 +3,25 @@ import type { GridPivotingPrivateApiCommunity, GridPivotingStatePartial } from '
|
|
|
3
3
|
import type { RefObject } from '@mui/x-internals/types';
|
|
4
4
|
import type { DataGridPremiumProcessedProps } from "../../../models/dataGridPremiumProps.js";
|
|
5
5
|
import type { GridInitialStatePremium } from "../../../models/gridStatePremium.js";
|
|
6
|
-
export type
|
|
7
|
-
|
|
6
|
+
export type GridPivotingStaticPropsOverrides = {
|
|
7
|
+
rowGroupingModel: DataGridPremiumProcessedProps['rowGroupingModel'];
|
|
8
|
+
getAggregationPosition: DataGridPremiumProcessedProps['getAggregationPosition'];
|
|
9
|
+
columnVisibilityModel: DataGridPremiumProcessedProps['columnVisibilityModel'];
|
|
10
|
+
groupingColDef: DataGridPremiumProcessedProps['groupingColDef'];
|
|
11
|
+
headerFilters: DataGridPremiumProcessedProps['headerFilters'];
|
|
12
|
+
disableAggregation: DataGridPremiumProcessedProps['disableAggregation'];
|
|
13
|
+
disableRowGrouping: DataGridPremiumProcessedProps['disableRowGrouping'];
|
|
14
|
+
};
|
|
15
|
+
export type GridPivotingDynamicPropsOverrides = {
|
|
16
|
+
rows?: DataGridPremiumProcessedProps['rows'];
|
|
8
17
|
columns: DataGridPremiumProcessedProps['columns'];
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
getAggregationPosition: NonNullable<DataGridPremiumProcessedProps['getAggregationPosition']>;
|
|
12
|
-
columnVisibilityModel: NonNullable<DataGridPremiumProcessedProps['columnVisibilityModel']>;
|
|
13
|
-
columnGroupingModel: NonNullable<DataGridPremiumProcessedProps['columnGroupingModel']>;
|
|
14
|
-
groupingColDef: NonNullable<DataGridPremiumProcessedProps['groupingColDef']>;
|
|
15
|
-
headerFilters: NonNullable<DataGridPremiumProcessedProps['headerFilters']>;
|
|
16
|
-
disableAggregation: NonNullable<DataGridPremiumProcessedProps['disableAggregation']>;
|
|
17
|
-
disableRowGrouping: NonNullable<DataGridPremiumProcessedProps['disableRowGrouping']>;
|
|
18
|
+
aggregationModel: DataGridPremiumProcessedProps['aggregationModel'];
|
|
19
|
+
columnGroupingModel: DataGridPremiumProcessedProps['columnGroupingModel'];
|
|
18
20
|
};
|
|
21
|
+
export type GridPivotingPropsOverrides = GridPivotingStaticPropsOverrides & GridPivotingDynamicPropsOverrides;
|
|
19
22
|
export interface GridPivotingState extends GridPivotingStatePartial {
|
|
20
23
|
model: GridPivotModel;
|
|
21
|
-
propsOverrides: GridPivotingPropsOverrides | undefined;
|
|
24
|
+
propsOverrides: GridPivotingPropsOverrides | GridPivotingStaticPropsOverrides | {} | undefined;
|
|
22
25
|
}
|
|
23
26
|
export interface GridPivotingInitialState {
|
|
24
27
|
model?: GridPivotModel;
|
|
@@ -73,7 +76,14 @@ export interface GridPivotingPrivateApi extends GridPivotingPrivateApiCommunity
|
|
|
73
76
|
targetFieldPosition?: DropPosition;
|
|
74
77
|
}) => void;
|
|
75
78
|
}
|
|
76
|
-
export type GridPivotingColDefOverrides = Pick<GridColDef, 'width' | 'flex' | 'headerName' | 'description' | 'align' | 'headerAlign' | 'cellClassName' | 'headerClassName' | 'display' | 'maxWidth' | 'minWidth' | 'resizable' | 'sortingOrder'>;
|
|
79
|
+
export type GridPivotingColDefOverrides = Pick<GridColDef, 'field' | 'width' | 'flex' | 'headerName' | 'description' | 'align' | 'headerAlign' | 'cellClassName' | 'headerClassName' | 'display' | 'maxWidth' | 'minWidth' | 'resizable' | 'sortingOrder'>;
|
|
80
|
+
/**
|
|
81
|
+
* The column definition overrides callback for the columns generated by the pivoting feature.
|
|
82
|
+
* @param {string} originalColumnField The field of the original column.
|
|
83
|
+
* @param {string[]} columnGroupPath The path of the column groups the column belongs to.
|
|
84
|
+
* @returns {Partial<GridPivotingColDefOverrides> | undefined | void} The column definition overrides.
|
|
85
|
+
*/
|
|
86
|
+
export type PivotingColDefCallback = (originalColumnField: GridColDef['field'], columnGroupPath: string[]) => Partial<GridPivotingColDefOverrides> | undefined;
|
|
77
87
|
export interface GridPivotingInternalCache {
|
|
78
88
|
nonPivotDataRef: RefObject<{
|
|
79
89
|
rows: GridRowModel[];
|
|
@@ -7,5 +7,5 @@ export declare const gridPivotModelSelector: (args_0: import("react").RefObject<
|
|
|
7
7
|
} | null>) => import("./gridPivotingInterfaces.js").GridPivotModel;
|
|
8
8
|
export declare const gridPivotPropsOverridesSelector: (args_0: import("react").RefObject<{
|
|
9
9
|
state: GridStatePremium;
|
|
10
|
-
} | null>) =>
|
|
10
|
+
} | null>) => {} | undefined;
|
|
11
11
|
export { gridPivotActiveSelector, gridPivotInitialColumnsSelector } from '@mui/x-data-grid/internals';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { gridPivotModelSelector } from "./gridPivotingSelectors.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "gridPivotModelSelector", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _gridPivotingSelectors.gridPivotModelSelector;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _gridPivotingSelectors = require("./gridPivotingSelectors");
|
|
@@ -4,5 +4,5 @@ import { GridStateInitializer } from '@mui/x-data-grid-pro/internals';
|
|
|
4
4
|
import type { DataGridPremiumProcessedProps } from "../../../models/dataGridPremiumProps.js";
|
|
5
5
|
import { GridPrivateApiPremium } from "../../../models/gridApiPremium.js";
|
|
6
6
|
export declare const pivotingStateInitializer: GridStateInitializer<Pick<DataGridPremiumProcessedProps, 'pivotActive' | 'pivotModel' | 'pivotPanelOpen' | 'initialState' | 'disablePivoting' | 'getPivotDerivedColumns' | 'columns'>, GridPrivateApiPremium>;
|
|
7
|
-
export declare const useGridPivoting: (apiRef: RefObject<GridPrivateApiPremium>, props: Pick<DataGridPremiumProcessedProps, "pivotActive" | "onPivotActiveChange" | "pivotModel" | "onPivotModelChange" | "pivotPanelOpen" | "onPivotPanelOpenChange" | "disablePivoting" | "getPivotDerivedColumns" | "pivotingColDef" | "groupingColDef" | "aggregationFunctions">, originalColumnsProp: readonly GridColDef[], originalRowsProp: readonly GridRowModel[]) => void;
|
|
7
|
+
export declare const useGridPivoting: (apiRef: RefObject<GridPrivateApiPremium>, props: Pick<DataGridPremiumProcessedProps, "pivotActive" | "onPivotActiveChange" | "pivotModel" | "onPivotModelChange" | "pivotPanelOpen" | "onPivotPanelOpenChange" | "disablePivoting" | "getPivotDerivedColumns" | "pivotingColDef" | "groupingColDef" | "aggregationFunctions" | "loading" | "dataSource">, originalColumnsProp: readonly GridColDef[], originalRowsProp: readonly GridRowModel[]) => void;
|
|
8
8
|
export declare const useGridPivotingExportState: (apiRef: RefObject<GridPrivateApiPremium>) => void;
|