@mui/x-data-grid-pro 5.6.1 → 5.9.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 +275 -53
- package/DataGridPro/DataGridPro.d.ts +7 -1
- package/DataGridPro/DataGridPro.js +47 -18
- package/DataGridPro/useDataGridProComponent.js +15 -13
- package/DataGridPro/useDataGridProProps.d.ts +2 -1
- package/LICENSE +12 -0
- package/README.md +1 -1
- package/components/DataGridProColumnHeaders.js +10 -16
- package/components/DataGridProVirtualScroller.js +6 -9
- package/components/GridDetailPanelToggleCell.js +15 -4
- package/components/GridGroupingCriteriaCell.d.ts +2 -5
- package/components/GridGroupingCriteriaCell.js +2 -74
- package/components/GridTreeDataGroupingCell.js +15 -4
- package/hooks/features/columnPinning/useGridColumnPinning.js +6 -6
- package/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +2 -2
- package/hooks/features/columnReorder/useGridColumnReorder.js +1 -1
- package/hooks/features/columnResize/useGridColumnResize.js +18 -6
- package/hooks/features/detailPanel/useGridDetailPanel.js +12 -4
- package/hooks/features/detailPanel/useGridDetailPanelCache.js +1 -1
- package/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +2 -2
- package/hooks/features/rowGrouping/gridRowGroupingInterfaces.d.ts +6 -0
- package/hooks/features/rowGrouping/gridRowGroupingUtils.d.ts +5 -2
- package/hooks/features/rowGrouping/gridRowGroupingUtils.js +18 -3
- package/hooks/features/rowGrouping/useGridRowGrouping.js +45 -168
- package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.d.ts +1 -1
- package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +131 -4
- package/hooks/features/treeData/gridTreeDataUtils.d.ts +1 -0
- package/hooks/features/treeData/gridTreeDataUtils.js +2 -0
- package/hooks/features/treeData/useGridTreeData.d.ts +1 -5
- package/hooks/features/treeData/useGridTreeData.js +3 -84
- package/hooks/features/treeData/useGridTreeDataPreProcessors.d.ts +1 -1
- package/hooks/features/treeData/useGridTreeDataPreProcessors.js +73 -4
- package/index.d.ts +1 -1
- package/index.js +2 -2
- package/legacy/DataGridPro/DataGridPro.js +47 -18
- package/legacy/DataGridPro/useDataGridProComponent.js +15 -13
- package/legacy/components/DataGridProColumnHeaders.js +10 -16
- package/legacy/components/DataGridProVirtualScroller.js +6 -9
- package/legacy/components/GridDetailPanelToggleCell.js +15 -4
- package/legacy/components/GridGroupingCriteriaCell.js +2 -74
- package/legacy/components/GridTreeDataGroupingCell.js +15 -4
- package/legacy/hooks/features/columnPinning/useGridColumnPinning.js +6 -6
- package/legacy/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +2 -2
- package/legacy/hooks/features/columnReorder/useGridColumnReorder.js +1 -1
- package/legacy/hooks/features/columnResize/useGridColumnResize.js +18 -6
- package/legacy/hooks/features/detailPanel/useGridDetailPanel.js +12 -4
- package/legacy/hooks/features/detailPanel/useGridDetailPanelCache.js +1 -1
- package/legacy/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +2 -2
- package/legacy/hooks/features/rowGrouping/gridRowGroupingUtils.js +19 -2
- package/legacy/hooks/features/rowGrouping/useGridRowGrouping.js +47 -173
- package/legacy/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +138 -4
- package/legacy/hooks/features/treeData/gridTreeDataUtils.js +2 -0
- package/legacy/hooks/features/treeData/useGridTreeData.js +3 -92
- package/legacy/hooks/features/treeData/useGridTreeDataPreProcessors.js +85 -4
- package/legacy/index.js +2 -2
- package/legacy/utils/domUtils.js +30 -3
- package/legacy/utils/releaseInfo.js +15 -0
- package/models/dataGridProProps.d.ts +9 -8
- package/models/gridGroupingColDefOverride.d.ts +2 -2
- package/models/gridGroupingValueGetterParams.d.ts +1 -1
- package/modern/DataGridPro/DataGridPro.js +47 -18
- package/modern/DataGridPro/useDataGridProComponent.js +13 -13
- package/modern/components/DataGridProColumnHeaders.js +10 -16
- package/modern/components/DataGridProVirtualScroller.js +6 -9
- package/modern/components/GridDetailPanelToggleCell.js +15 -4
- package/modern/components/GridGroupingCriteriaCell.js +2 -74
- package/modern/components/GridTreeDataGroupingCell.js +15 -4
- package/modern/hooks/features/columnPinning/useGridColumnPinning.js +6 -6
- package/modern/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +2 -2
- package/modern/hooks/features/columnReorder/useGridColumnReorder.js +1 -1
- package/modern/hooks/features/columnResize/useGridColumnResize.js +18 -6
- package/modern/hooks/features/detailPanel/useGridDetailPanel.js +12 -4
- package/modern/hooks/features/detailPanel/useGridDetailPanelCache.js +1 -1
- package/modern/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +2 -2
- package/modern/hooks/features/rowGrouping/gridRowGroupingUtils.js +18 -3
- package/modern/hooks/features/rowGrouping/useGridRowGrouping.js +45 -168
- package/modern/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +131 -4
- package/modern/hooks/features/treeData/gridTreeDataUtils.js +2 -0
- package/modern/hooks/features/treeData/useGridTreeData.js +3 -84
- package/modern/hooks/features/treeData/useGridTreeDataPreProcessors.js +73 -4
- package/modern/index.js +2 -2
- package/modern/utils/domUtils.js +30 -3
- package/modern/utils/releaseInfo.js +15 -0
- package/node/DataGridPro/DataGridPro.js +45 -17
- package/node/DataGridPro/useDataGridProComponent.js +15 -13
- package/node/components/DataGridProColumnHeaders.js +10 -16
- package/node/components/DataGridProVirtualScroller.js +6 -9
- package/node/components/GridDetailPanelToggleCell.js +15 -4
- package/node/components/GridGroupingCriteriaCell.js +1 -72
- package/node/components/GridTreeDataGroupingCell.js +15 -4
- package/node/hooks/features/columnPinning/useGridColumnPinning.js +5 -5
- package/node/hooks/features/columnPinning/useGridColumnPinningPreProcessors.js +1 -1
- package/node/hooks/features/columnReorder/useGridColumnReorder.js +1 -1
- package/node/hooks/features/columnResize/useGridColumnResize.js +18 -6
- package/node/hooks/features/detailPanel/useGridDetailPanel.js +11 -3
- package/node/hooks/features/detailPanel/useGridDetailPanelCache.js +1 -1
- package/node/hooks/features/detailPanel/useGridDetailPanelPreProcessors.js +1 -1
- package/node/hooks/features/rowGrouping/gridRowGroupingUtils.js +24 -5
- package/node/hooks/features/rowGrouping/useGridRowGrouping.js +41 -166
- package/node/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +134 -1
- package/node/hooks/features/treeData/gridTreeDataUtils.js +5 -2
- package/node/hooks/features/treeData/useGridTreeData.js +2 -93
- package/node/hooks/features/treeData/useGridTreeDataPreProcessors.js +75 -3
- package/node/index.js +9 -9
- package/node/utils/domUtils.js +30 -3
- package/node/utils/releaseInfo.js +25 -0
- package/package.json +7 -7
- package/typeOverloads/modules.d.ts +6 -6
- package/typeOverloads/reexports.d.ts +1 -1
- package/utils/domUtils.d.ts +2 -1
- package/utils/domUtils.js +30 -3
- package/utils/releaseInfo.d.ts +1 -0
- package/utils/releaseInfo.js +15 -0
- package/utils/tree/buildRowTree.d.ts +3 -3
- package/components/Watermark.d.ts +0 -2
- package/components/Watermark.js +0 -43
- package/legacy/components/Watermark.js +0 -43
- package/modern/components/Watermark.js +0 -43
- package/node/components/Watermark.js +0 -56
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { GridEvents, useGridSelector, useGridApiEventHandler, useGridApiMethod } from '@mui/x-data-grid';
|
|
4
|
-
import {
|
|
4
|
+
import { useGridRegisterPipeProcessor } from '@mui/x-data-grid/internals';
|
|
5
5
|
import { GRID_DETAIL_PANEL_TOGGLE_FIELD } from './gridDetailPanelToggleColDef';
|
|
6
6
|
import { gridDetailPanelExpandedRowIdsSelector, gridDetailPanelExpandedRowsContentCacheSelector, gridDetailPanelExpandedRowsHeightCacheSelector } from './gridDetailPanelSelector';
|
|
7
7
|
export const detailPanelStateInitializer = (state, props) => {
|
|
@@ -35,11 +35,19 @@ export const useGridDetailPanel = (apiRef, props) => {
|
|
|
35
35
|
apiRef.current.toggleDetailPanel(params.id);
|
|
36
36
|
}, [apiRef, contentCache, props.getDetailPanelContent]);
|
|
37
37
|
const handleCellKeyDown = React.useCallback((params, event) => {
|
|
38
|
-
if (
|
|
38
|
+
if (props.getDetailPanelContent == null) {
|
|
39
39
|
return;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
if ((event.ctrlKey || event.metaKey) && event.key === 'Enter') {
|
|
43
|
+
// TODO v6: only support Space on the detail toggle
|
|
44
|
+
apiRef.current.toggleDetailPanel(params.id);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (params.field === GRID_DETAIL_PANEL_TOGGLE_FIELD && event.key === ' ') {
|
|
49
|
+
apiRef.current.toggleDetailPanel(params.id);
|
|
50
|
+
}
|
|
43
51
|
}, [apiRef, props.getDetailPanelContent]);
|
|
44
52
|
useGridApiEventHandler(apiRef, GridEvents.cellClick, handleCellClick);
|
|
45
53
|
useGridApiEventHandler(apiRef, GridEvents.cellKeyDown, handleCellKeyDown);
|
|
@@ -58,7 +66,7 @@ export const useGridDetailPanel = (apiRef, props) => {
|
|
|
58
66
|
|
|
59
67
|
});
|
|
60
68
|
}, [apiRef, expandedRowIds]);
|
|
61
|
-
|
|
69
|
+
useGridRegisterPipeProcessor(apiRef, 'rowHeight', addDetailHeight);
|
|
62
70
|
apiRef.current.unstable_updateControlState({
|
|
63
71
|
stateId: 'detailPanels',
|
|
64
72
|
propModel: props.detailPanelExpandedRowIds,
|
|
@@ -39,7 +39,7 @@ export const useGridDetailPanelCache = (apiRef, props) => {
|
|
|
39
39
|
});
|
|
40
40
|
apiRef.current.forceUpdate();
|
|
41
41
|
}, [apiRef, props.getDetailPanelContent, props.getDetailPanelHeight]);
|
|
42
|
-
useGridApiEventHandler(apiRef, GridEvents.
|
|
42
|
+
useGridApiEventHandler(apiRef, GridEvents.sortedRowsSet, updateCaches);
|
|
43
43
|
const isFirstRender = React.useRef(true);
|
|
44
44
|
|
|
45
45
|
if (isFirstRender.current) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useGridRegisterPipeProcessor } from '@mui/x-data-grid/internals';
|
|
3
3
|
import { GRID_DETAIL_PANEL_TOGGLE_FIELD, GRID_DETAIL_PANEL_TOGGLE_COL_DEF } from './gridDetailPanelToggleColDef';
|
|
4
4
|
export const useGridDetailPanelPreProcessors = (apiRef, props) => {
|
|
5
5
|
const addToggleColumn = React.useCallback(columnsState => {
|
|
@@ -24,5 +24,5 @@ export const useGridDetailPanelPreProcessors = (apiRef, props) => {
|
|
|
24
24
|
columnsState.lookup[GRID_DETAIL_PANEL_TOGGLE_FIELD] = GRID_DETAIL_PANEL_TOGGLE_COL_DEF;
|
|
25
25
|
return columnsState;
|
|
26
26
|
}, [props.getDetailPanelContent]);
|
|
27
|
-
|
|
27
|
+
useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', addToggleColumn);
|
|
28
28
|
};
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
export declare type GridRowGroupingModel = string[];
|
|
2
2
|
export interface GridRowGroupingState {
|
|
3
3
|
model: GridRowGroupingModel;
|
|
4
|
+
/**
|
|
5
|
+
* Tracks the model on the last pre-processing
|
|
6
|
+
* Allows to check if we need to re-build the grouping columns when the grid upserts a column.
|
|
7
|
+
* TODO: Move outside of the state
|
|
8
|
+
*/
|
|
9
|
+
unstable_sanitizedModelOnLastRowTreeCreation: GridRowGroupingModel;
|
|
4
10
|
}
|
|
5
11
|
export interface GridRowGroupingInitialState {
|
|
6
12
|
model?: GridRowGroupingModel;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
1
2
|
import { GridRowTreeConfig, GridFilterState } from '@mui/x-data-grid';
|
|
2
3
|
import { GridAggregatedFilterItemApplier } from '@mui/x-data-grid/internals';
|
|
3
4
|
import { DataGridProProcessedProps } from '../../../models/dataGridProProps';
|
|
4
5
|
import { GridRowGroupingModel } from './gridRowGroupingInterfaces';
|
|
5
6
|
import { GridStatePro } from '../../../models/gridStatePro';
|
|
7
|
+
import { GridApiPro } from '../../../models/gridApiPro';
|
|
6
8
|
export declare const GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD = "__row_group_by_columns_group__";
|
|
7
|
-
export declare const
|
|
9
|
+
export declare const ROW_GROUPING_STRATEGY = "grouping-columns";
|
|
8
10
|
export declare const getRowGroupingFieldFromGroupingCriteria: (groupingCriteria: string | null) => string;
|
|
9
11
|
export declare const getRowGroupingCriteriaFromGroupingField: (groupingColDefField: string) => string | null;
|
|
10
12
|
export declare const isGroupingColumn: (field: string) => boolean;
|
|
@@ -19,6 +21,7 @@ interface FilterRowTreeFromTreeDataParams {
|
|
|
19
21
|
* - It is passing the filter
|
|
20
22
|
*/
|
|
21
23
|
export declare const filterRowTreeFromGroupingColumns: (params: FilterRowTreeFromTreeDataParams) => Omit<GridFilterState, 'filterModel'>;
|
|
22
|
-
export declare const getColDefOverrides: (groupingColDefProp: DataGridProProcessedProps['groupingColDef'], fields: string[]) => import("../../..").GridGroupingColDefOverride | null | undefined;
|
|
24
|
+
export declare const getColDefOverrides: (groupingColDefProp: DataGridProProcessedProps['groupingColDef'], fields: string[]) => import("../../..").GridGroupingColDefOverride<any> | null | undefined;
|
|
23
25
|
export declare const mergeStateWithRowGroupingModel: (rowGroupingModel: GridRowGroupingModel) => (state: GridStatePro) => GridStatePro;
|
|
26
|
+
export declare const setStrategyAvailability: (apiRef: React.MutableRefObject<GridApiPro>, disableRowGrouping: boolean) => void;
|
|
24
27
|
export {};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { gridRowGroupingSanitizedModelSelector } from './gridRowGroupingSelector';
|
|
2
3
|
export const GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD = '__row_group_by_columns_group__';
|
|
3
|
-
export const
|
|
4
|
+
export const ROW_GROUPING_STRATEGY = 'grouping-columns';
|
|
4
5
|
export const getRowGroupingFieldFromGroupingCriteria = groupingCriteria => {
|
|
5
6
|
if (groupingCriteria === null) {
|
|
6
7
|
return GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD;
|
|
@@ -110,7 +111,7 @@ export const filterRowTreeFromGroupingColumns = params => {
|
|
|
110
111
|
export const getColDefOverrides = (groupingColDefProp, fields) => {
|
|
111
112
|
if (typeof groupingColDefProp === 'function') {
|
|
112
113
|
return groupingColDefProp({
|
|
113
|
-
groupingName:
|
|
114
|
+
groupingName: ROW_GROUPING_STRATEGY,
|
|
114
115
|
fields
|
|
115
116
|
});
|
|
116
117
|
}
|
|
@@ -121,4 +122,18 @@ export const mergeStateWithRowGroupingModel = rowGroupingModel => state => _exte
|
|
|
121
122
|
rowGrouping: _extends({}, state.rowGrouping, {
|
|
122
123
|
model: rowGroupingModel
|
|
123
124
|
})
|
|
124
|
-
});
|
|
125
|
+
});
|
|
126
|
+
export const setStrategyAvailability = (apiRef, disableRowGrouping) => {
|
|
127
|
+
let isAvailable;
|
|
128
|
+
|
|
129
|
+
if (disableRowGrouping) {
|
|
130
|
+
isAvailable = () => false;
|
|
131
|
+
} else {
|
|
132
|
+
isAvailable = () => {
|
|
133
|
+
const rowGroupingSanitizedModel = gridRowGroupingSanitizedModelSelector(apiRef);
|
|
134
|
+
return rowGroupingSanitizedModel.length > 0;
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
apiRef.current.unstable_setStrategyAvailability('rowTree', ROW_GROUPING_STRATEGY, isAvailable);
|
|
139
|
+
};
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import Divider from '@mui/material/Divider';
|
|
4
|
-
import { GridEvents,
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { filterRowTreeFromGroupingColumns, getRowGroupingFieldFromGroupingCriteria, GROUPING_COLUMNS_FEATURE_NAME, isGroupingColumn, mergeStateWithRowGroupingModel } from './gridRowGroupingUtils';
|
|
9
|
-
import { sortRowTree } from '../../../utils/tree/sortRowTree';
|
|
4
|
+
import { GridEvents, useGridApiEventHandler, useGridApiMethod, gridFilteredDescendantCountLookupSelector } from '@mui/x-data-grid';
|
|
5
|
+
import { useGridRegisterPipeProcessor, isDeepEqual } from '@mui/x-data-grid/internals';
|
|
6
|
+
import { gridRowGroupingModelSelector, gridRowGroupingSanitizedModelSelector, gridRowGroupingStateSelector } from './gridRowGroupingSelector';
|
|
7
|
+
import { getRowGroupingFieldFromGroupingCriteria, ROW_GROUPING_STRATEGY, isGroupingColumn, mergeStateWithRowGroupingModel, setStrategyAvailability } from './gridRowGroupingUtils';
|
|
10
8
|
import { GridRowGroupableColumnMenuItems } from '../../../components/GridRowGroupableColumnMenuItems';
|
|
11
9
|
import { GridRowGroupingColumnMenuItems } from '../../../components/GridRowGroupingColumnMenuItems';
|
|
12
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -15,7 +13,8 @@ export const rowGroupingStateInitializer = (state, props) => {
|
|
|
15
13
|
|
|
16
14
|
return _extends({}, state, {
|
|
17
15
|
rowGrouping: {
|
|
18
|
-
model: (_ref = (_props$rowGroupingMod = props.rowGroupingModel) != null ? _props$rowGroupingMod : (_props$initialState = props.initialState) == null ? void 0 : (_props$initialState$r = _props$initialState.rowGrouping) == null ? void 0 : _props$initialState$r.model) != null ? _ref : []
|
|
16
|
+
model: (_ref = (_props$rowGroupingMod = props.rowGroupingModel) != null ? _props$rowGroupingMod : (_props$initialState = props.initialState) == null ? void 0 : (_props$initialState$r = _props$initialState.rowGrouping) == null ? void 0 : _props$initialState$r.model) != null ? _ref : [],
|
|
17
|
+
unstable_sanitizedModelOnLastRowTreeCreation: []
|
|
19
18
|
}
|
|
20
19
|
});
|
|
21
20
|
};
|
|
@@ -35,158 +34,6 @@ export const useGridRowGrouping = (apiRef, props) => {
|
|
|
35
34
|
stateSelector: gridRowGroupingModelSelector,
|
|
36
35
|
changeEvent: GridEvents.rowGroupingModelChange
|
|
37
36
|
});
|
|
38
|
-
/**
|
|
39
|
-
* ROW GROUPING
|
|
40
|
-
*/
|
|
41
|
-
// Tracks the model on the last pre-processing to check if we need to re-build the grouping columns when the grid upserts a column.
|
|
42
|
-
|
|
43
|
-
const sanitizedModelOnLastRowPreProcessing = React.useRef([]);
|
|
44
|
-
const updateRowGrouping = React.useCallback(() => {
|
|
45
|
-
const groupRows = params => {
|
|
46
|
-
const rowGroupingModel = gridRowGroupingSanitizedModelSelector(apiRef);
|
|
47
|
-
const columnsLookup = gridColumnLookupSelector(apiRef);
|
|
48
|
-
sanitizedModelOnLastRowPreProcessing.current = rowGroupingModel;
|
|
49
|
-
|
|
50
|
-
if (props.disableRowGrouping || rowGroupingModel.length === 0) {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const distinctValues = Object.fromEntries(rowGroupingModel.map(groupingField => [groupingField, {
|
|
55
|
-
lookup: {},
|
|
56
|
-
list: []
|
|
57
|
-
}]));
|
|
58
|
-
|
|
59
|
-
const getCellGroupingCriteria = ({
|
|
60
|
-
row,
|
|
61
|
-
id,
|
|
62
|
-
colDef
|
|
63
|
-
}) => {
|
|
64
|
-
let key;
|
|
65
|
-
|
|
66
|
-
if (colDef.groupingValueGetter) {
|
|
67
|
-
const groupingValueGetterParams = {
|
|
68
|
-
colDef,
|
|
69
|
-
field: colDef.field,
|
|
70
|
-
value: row[colDef.field],
|
|
71
|
-
id,
|
|
72
|
-
row,
|
|
73
|
-
rowNode: {
|
|
74
|
-
isAutoGenerated: false,
|
|
75
|
-
id
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
key = colDef.groupingValueGetter(groupingValueGetterParams);
|
|
79
|
-
} else {
|
|
80
|
-
key = row[colDef.field];
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
key,
|
|
85
|
-
field: colDef.field
|
|
86
|
-
};
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
params.ids.forEach(rowId => {
|
|
90
|
-
const row = params.idRowsLookup[rowId];
|
|
91
|
-
rowGroupingModel.forEach(groupingCriteria => {
|
|
92
|
-
const {
|
|
93
|
-
key
|
|
94
|
-
} = getCellGroupingCriteria({
|
|
95
|
-
row,
|
|
96
|
-
id: rowId,
|
|
97
|
-
colDef: columnsLookup[groupingCriteria]
|
|
98
|
-
});
|
|
99
|
-
const groupingFieldsDistinctKeys = distinctValues[groupingCriteria];
|
|
100
|
-
|
|
101
|
-
if (key != null && !groupingFieldsDistinctKeys.lookup[key.toString()]) {
|
|
102
|
-
groupingFieldsDistinctKeys.lookup[key.toString()] = true;
|
|
103
|
-
groupingFieldsDistinctKeys.list.push(key);
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
});
|
|
107
|
-
const rows = params.ids.map(rowId => {
|
|
108
|
-
const row = params.idRowsLookup[rowId];
|
|
109
|
-
const parentPath = rowGroupingModel.map(groupingField => getCellGroupingCriteria({
|
|
110
|
-
row,
|
|
111
|
-
id: rowId,
|
|
112
|
-
colDef: columnsLookup[groupingField]
|
|
113
|
-
})).filter(cell => cell.key != null);
|
|
114
|
-
const leafGroupingCriteria = {
|
|
115
|
-
key: rowId.toString(),
|
|
116
|
-
field: null
|
|
117
|
-
};
|
|
118
|
-
return {
|
|
119
|
-
path: [...parentPath, leafGroupingCriteria],
|
|
120
|
-
id: rowId
|
|
121
|
-
};
|
|
122
|
-
});
|
|
123
|
-
return buildRowTree(_extends({}, params, {
|
|
124
|
-
rows,
|
|
125
|
-
defaultGroupingExpansionDepth: props.defaultGroupingExpansionDepth,
|
|
126
|
-
isGroupExpandedByDefault: props.isGroupExpandedByDefault,
|
|
127
|
-
groupingName: GROUPING_COLUMNS_FEATURE_NAME
|
|
128
|
-
}));
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
return apiRef.current.unstable_registerRowGroupsBuilder('rowGrouping', groupRows);
|
|
132
|
-
}, [apiRef, props.defaultGroupingExpansionDepth, props.isGroupExpandedByDefault, props.disableRowGrouping]);
|
|
133
|
-
useFirstRender(() => {
|
|
134
|
-
updateRowGrouping();
|
|
135
|
-
});
|
|
136
|
-
const isFirstRender = React.useRef(true);
|
|
137
|
-
React.useEffect(() => {
|
|
138
|
-
if (isFirstRender.current) {
|
|
139
|
-
isFirstRender.current = false;
|
|
140
|
-
return () => {};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
return updateRowGrouping();
|
|
144
|
-
}, [updateRowGrouping]);
|
|
145
|
-
/**
|
|
146
|
-
* PRE-PROCESSING
|
|
147
|
-
*/
|
|
148
|
-
|
|
149
|
-
const addColumnMenuButtons = React.useCallback((initialValue, columns) => {
|
|
150
|
-
if (props.disableRowGrouping) {
|
|
151
|
-
return initialValue;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
let menuItems;
|
|
155
|
-
|
|
156
|
-
if (isGroupingColumn(columns.field)) {
|
|
157
|
-
menuItems = /*#__PURE__*/_jsx(GridRowGroupingColumnMenuItems, {});
|
|
158
|
-
} else if (columns.groupable) {
|
|
159
|
-
menuItems = /*#__PURE__*/_jsx(GridRowGroupableColumnMenuItems, {});
|
|
160
|
-
} else {
|
|
161
|
-
menuItems = null;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (menuItems == null) {
|
|
165
|
-
return initialValue;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
return [...initialValue, /*#__PURE__*/_jsx(Divider, {}), menuItems];
|
|
169
|
-
}, [props.disableRowGrouping]);
|
|
170
|
-
const filteringMethod = React.useCallback(params => {
|
|
171
|
-
const rowTree = gridRowTreeSelector(apiRef);
|
|
172
|
-
return filterRowTreeFromGroupingColumns({
|
|
173
|
-
rowTree,
|
|
174
|
-
isRowMatchingFilters: params.isRowMatchingFilters
|
|
175
|
-
});
|
|
176
|
-
}, [apiRef]);
|
|
177
|
-
const sortingMethod = React.useCallback(params => {
|
|
178
|
-
const rowTree = gridRowTreeSelector(apiRef);
|
|
179
|
-
const rowIds = gridRowIdsSelector(apiRef);
|
|
180
|
-
return sortRowTree({
|
|
181
|
-
rowTree,
|
|
182
|
-
rowIds,
|
|
183
|
-
sortRowList: params.sortRowList,
|
|
184
|
-
disableChildrenSorting: false
|
|
185
|
-
});
|
|
186
|
-
}, [apiRef]);
|
|
187
|
-
useGridRegisterPreProcessor(apiRef, 'columnMenu', addColumnMenuButtons);
|
|
188
|
-
useGridRegisterFilteringMethod(apiRef, GROUPING_COLUMNS_FEATURE_NAME, filteringMethod);
|
|
189
|
-
useGridRegisterSortingMethod(apiRef, GROUPING_COLUMNS_FEATURE_NAME, sortingMethod);
|
|
190
37
|
/**
|
|
191
38
|
* API METHODS
|
|
192
39
|
*/
|
|
@@ -196,10 +43,10 @@ export const useGridRowGrouping = (apiRef, props) => {
|
|
|
196
43
|
|
|
197
44
|
if (currentModel !== model) {
|
|
198
45
|
apiRef.current.setState(mergeStateWithRowGroupingModel(model));
|
|
199
|
-
|
|
46
|
+
setStrategyAvailability(apiRef, props.disableRowGrouping);
|
|
200
47
|
apiRef.current.forceUpdate();
|
|
201
48
|
}
|
|
202
|
-
}, [apiRef,
|
|
49
|
+
}, [apiRef, props.disableRowGrouping]);
|
|
203
50
|
const addRowGroupingCriteria = React.useCallback((field, groupingIndex) => {
|
|
204
51
|
const currentModel = gridRowGroupingModelSelector(apiRef);
|
|
205
52
|
|
|
@@ -243,6 +90,27 @@ export const useGridRowGrouping = (apiRef, props) => {
|
|
|
243
90
|
* PRE-PROCESSING
|
|
244
91
|
*/
|
|
245
92
|
|
|
93
|
+
const addColumnMenuButtons = React.useCallback((initialValue, columns) => {
|
|
94
|
+
if (props.disableRowGrouping) {
|
|
95
|
+
return initialValue;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
let menuItems;
|
|
99
|
+
|
|
100
|
+
if (isGroupingColumn(columns.field)) {
|
|
101
|
+
menuItems = /*#__PURE__*/_jsx(GridRowGroupingColumnMenuItems, {});
|
|
102
|
+
} else if (columns.groupable) {
|
|
103
|
+
menuItems = /*#__PURE__*/_jsx(GridRowGroupableColumnMenuItems, {});
|
|
104
|
+
} else {
|
|
105
|
+
menuItems = null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (menuItems == null) {
|
|
109
|
+
return initialValue;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return [...initialValue, /*#__PURE__*/_jsx(Divider, {}), menuItems];
|
|
113
|
+
}, [props.disableRowGrouping]);
|
|
246
114
|
const stateExportPreProcessing = React.useCallback(prevState => {
|
|
247
115
|
if (props.disableRowGrouping) {
|
|
248
116
|
return prevState;
|
|
@@ -275,8 +143,9 @@ export const useGridRowGrouping = (apiRef, props) => {
|
|
|
275
143
|
|
|
276
144
|
return params;
|
|
277
145
|
}, [apiRef, props.disableRowGrouping]);
|
|
278
|
-
|
|
279
|
-
|
|
146
|
+
useGridRegisterPipeProcessor(apiRef, 'columnMenu', addColumnMenuButtons);
|
|
147
|
+
useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
|
|
148
|
+
useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
|
|
280
149
|
/**
|
|
281
150
|
* EVENTS
|
|
282
151
|
*/
|
|
@@ -301,15 +170,23 @@ export const useGridRowGrouping = (apiRef, props) => {
|
|
|
301
170
|
}, [apiRef, props.rowGroupingColumnMode]);
|
|
302
171
|
const checkGroupingColumnsModelDiff = React.useCallback(() => {
|
|
303
172
|
const rowGroupingModel = gridRowGroupingSanitizedModelSelector(apiRef);
|
|
304
|
-
const lastGroupingColumnsModelApplied =
|
|
173
|
+
const lastGroupingColumnsModelApplied = gridRowGroupingStateSelector(apiRef.current.state).unstable_sanitizedModelOnLastRowTreeCreation;
|
|
305
174
|
|
|
306
175
|
if (!isDeepEqual(lastGroupingColumnsModelApplied, rowGroupingModel)) {
|
|
307
|
-
|
|
176
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
177
|
+
rowGrouping: _extends({}, state.rowGrouping, {
|
|
178
|
+
unstable_sanitizedModelOnLastRowTreeCreation: rowGroupingModel
|
|
179
|
+
})
|
|
180
|
+
}));
|
|
181
|
+
apiRef.current.unstable_requestPipeProcessorsApplication('hydrateColumns');
|
|
182
|
+
setStrategyAvailability(apiRef, props.disableRowGrouping); // Refresh the row tree creation strategy processing
|
|
183
|
+
// TODO: Add a clean way to re-run a strategy processing without publishing a private event
|
|
308
184
|
|
|
309
|
-
apiRef.current.
|
|
310
|
-
|
|
185
|
+
if (apiRef.current.unstable_getActiveStrategy('rowTree') === ROW_GROUPING_STRATEGY) {
|
|
186
|
+
apiRef.current.publishEvent(GridEvents.activeStrategyProcessorChange, 'rowTreeCreation');
|
|
187
|
+
}
|
|
311
188
|
}
|
|
312
|
-
}, [apiRef,
|
|
189
|
+
}, [apiRef, props.disableRowGrouping]);
|
|
313
190
|
useGridApiEventHandler(apiRef, GridEvents.cellKeyDown, handleCellKeyDown);
|
|
314
191
|
useGridApiEventHandler(apiRef, GridEvents.columnsChange, checkGroupingColumnsModelDiff);
|
|
315
192
|
useGridApiEventHandler(apiRef, GridEvents.rowGroupingModelChange, checkGroupingColumnsModelDiff);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { DataGridProProcessedProps } from '../../../models/dataGridProProps';
|
|
3
3
|
import { GridApiPro } from '../../../models/gridApiPro';
|
|
4
|
-
export declare const useGridRowGroupingPreProcessors: (apiRef: React.MutableRefObject<GridApiPro>, props: Pick<DataGridProProcessedProps, 'disableRowGrouping' | 'groupingColDef' | 'rowGroupingColumnMode'>) => void;
|
|
4
|
+
export declare const useGridRowGroupingPreProcessors: (apiRef: React.MutableRefObject<GridApiPro>, props: Pick<DataGridProProcessedProps, 'disableRowGrouping' | 'groupingColDef' | 'rowGroupingColumnMode' | 'defaultGroupingExpansionDepth' | 'isGroupExpandedByDefault'>) => void;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
1
2
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
3
|
+
import { gridColumnLookupSelector, gridRowIdsSelector, gridRowTreeSelector, useFirstRender } from '@mui/x-data-grid';
|
|
4
|
+
import { useGridRegisterPipeProcessor, useGridRegisterStrategyProcessor } from '@mui/x-data-grid/internals';
|
|
5
|
+
import { gridRowGroupingModelSelector, gridRowGroupingSanitizedModelSelector } from './gridRowGroupingSelector';
|
|
4
6
|
import { createGroupingColDefForAllGroupingCriteria, createGroupingColDefForOneGroupingCriteria } from './createGroupingColDef';
|
|
5
|
-
import { getColDefOverrides, isGroupingColumn } from './gridRowGroupingUtils';
|
|
7
|
+
import { filterRowTreeFromGroupingColumns, getColDefOverrides, ROW_GROUPING_STRATEGY, isGroupingColumn, setStrategyAvailability } from './gridRowGroupingUtils';
|
|
8
|
+
import { buildRowTree } from '../../../utils/tree/buildRowTree';
|
|
9
|
+
import { sortRowTree } from '../../../utils/tree/sortRowTree';
|
|
6
10
|
export const useGridRowGroupingPreProcessors = (apiRef, props) => {
|
|
7
11
|
const getGroupingColDefs = React.useCallback(columnsState => {
|
|
8
12
|
if (props.disableRowGrouping) {
|
|
@@ -72,5 +76,128 @@ export const useGridRowGroupingPreProcessors = (apiRef, props) => {
|
|
|
72
76
|
columnsState.lookup = newColumnsLookup;
|
|
73
77
|
return columnsState;
|
|
74
78
|
}, [getGroupingColDefs]);
|
|
75
|
-
|
|
79
|
+
const createRowTree = React.useCallback(params => {
|
|
80
|
+
const rowGroupingModel = gridRowGroupingSanitizedModelSelector(apiRef);
|
|
81
|
+
const columnsLookup = gridColumnLookupSelector(apiRef);
|
|
82
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
83
|
+
rowGrouping: _extends({}, state.rowGrouping, {
|
|
84
|
+
unstable_sanitizedModelOnLastRowTreeCreation: rowGroupingModel
|
|
85
|
+
})
|
|
86
|
+
}));
|
|
87
|
+
const distinctValues = Object.fromEntries(rowGroupingModel.map(groupingField => [groupingField, {
|
|
88
|
+
lookup: {},
|
|
89
|
+
list: []
|
|
90
|
+
}]));
|
|
91
|
+
|
|
92
|
+
const getCellGroupingCriteria = ({
|
|
93
|
+
row,
|
|
94
|
+
id,
|
|
95
|
+
colDef
|
|
96
|
+
}) => {
|
|
97
|
+
let key;
|
|
98
|
+
|
|
99
|
+
if (colDef.groupingValueGetter) {
|
|
100
|
+
const groupingValueGetterParams = {
|
|
101
|
+
colDef,
|
|
102
|
+
field: colDef.field,
|
|
103
|
+
value: row[colDef.field],
|
|
104
|
+
id,
|
|
105
|
+
row,
|
|
106
|
+
rowNode: {
|
|
107
|
+
isAutoGenerated: false,
|
|
108
|
+
id
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
key = colDef.groupingValueGetter(groupingValueGetterParams);
|
|
112
|
+
} else {
|
|
113
|
+
key = row[colDef.field];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
key,
|
|
118
|
+
field: colDef.field
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
params.ids.forEach(rowId => {
|
|
123
|
+
const row = params.idRowsLookup[rowId];
|
|
124
|
+
rowGroupingModel.forEach(groupingCriteria => {
|
|
125
|
+
const {
|
|
126
|
+
key
|
|
127
|
+
} = getCellGroupingCriteria({
|
|
128
|
+
row,
|
|
129
|
+
id: rowId,
|
|
130
|
+
colDef: columnsLookup[groupingCriteria]
|
|
131
|
+
});
|
|
132
|
+
const groupingFieldsDistinctKeys = distinctValues[groupingCriteria];
|
|
133
|
+
|
|
134
|
+
if (key != null && !groupingFieldsDistinctKeys.lookup[key.toString()]) {
|
|
135
|
+
groupingFieldsDistinctKeys.lookup[key.toString()] = true;
|
|
136
|
+
groupingFieldsDistinctKeys.list.push(key);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
const rows = params.ids.map(rowId => {
|
|
141
|
+
const row = params.idRowsLookup[rowId];
|
|
142
|
+
const parentPath = rowGroupingModel.map(groupingField => getCellGroupingCriteria({
|
|
143
|
+
row,
|
|
144
|
+
id: rowId,
|
|
145
|
+
colDef: columnsLookup[groupingField]
|
|
146
|
+
})).filter(cell => cell.key != null);
|
|
147
|
+
const leafGroupingCriteria = {
|
|
148
|
+
key: rowId.toString(),
|
|
149
|
+
field: null
|
|
150
|
+
};
|
|
151
|
+
return {
|
|
152
|
+
path: [...parentPath, leafGroupingCriteria],
|
|
153
|
+
id: rowId
|
|
154
|
+
};
|
|
155
|
+
});
|
|
156
|
+
return buildRowTree(_extends({}, params, {
|
|
157
|
+
rows,
|
|
158
|
+
defaultGroupingExpansionDepth: props.defaultGroupingExpansionDepth,
|
|
159
|
+
isGroupExpandedByDefault: props.isGroupExpandedByDefault,
|
|
160
|
+
groupingName: ROW_GROUPING_STRATEGY
|
|
161
|
+
}));
|
|
162
|
+
}, [apiRef, props.defaultGroupingExpansionDepth, props.isGroupExpandedByDefault]);
|
|
163
|
+
const filterRows = React.useCallback(params => {
|
|
164
|
+
const rowTree = gridRowTreeSelector(apiRef);
|
|
165
|
+
return filterRowTreeFromGroupingColumns({
|
|
166
|
+
rowTree,
|
|
167
|
+
isRowMatchingFilters: params.isRowMatchingFilters
|
|
168
|
+
});
|
|
169
|
+
}, [apiRef]);
|
|
170
|
+
const sortRows = React.useCallback(params => {
|
|
171
|
+
const rowTree = gridRowTreeSelector(apiRef);
|
|
172
|
+
const rowIds = gridRowIdsSelector(apiRef);
|
|
173
|
+
return sortRowTree({
|
|
174
|
+
rowTree,
|
|
175
|
+
rowIds,
|
|
176
|
+
sortRowList: params.sortRowList,
|
|
177
|
+
disableChildrenSorting: false
|
|
178
|
+
});
|
|
179
|
+
}, [apiRef]);
|
|
180
|
+
useGridRegisterPipeProcessor(apiRef, 'hydrateColumns', updateGroupingColumn);
|
|
181
|
+
useGridRegisterStrategyProcessor(apiRef, ROW_GROUPING_STRATEGY, 'rowTreeCreation', createRowTree);
|
|
182
|
+
useGridRegisterStrategyProcessor(apiRef, ROW_GROUPING_STRATEGY, 'filtering', filterRows);
|
|
183
|
+
useGridRegisterStrategyProcessor(apiRef, ROW_GROUPING_STRATEGY, 'sorting', sortRows);
|
|
184
|
+
/**
|
|
185
|
+
* 1ST RENDER
|
|
186
|
+
*/
|
|
187
|
+
|
|
188
|
+
useFirstRender(() => {
|
|
189
|
+
setStrategyAvailability(apiRef, props.disableRowGrouping);
|
|
190
|
+
});
|
|
191
|
+
/**
|
|
192
|
+
* EFFECTS
|
|
193
|
+
*/
|
|
194
|
+
|
|
195
|
+
const isFirstRender = React.useRef(true);
|
|
196
|
+
React.useEffect(() => {
|
|
197
|
+
if (!isFirstRender.current) {
|
|
198
|
+
setStrategyAvailability(apiRef, props.disableRowGrouping);
|
|
199
|
+
} else {
|
|
200
|
+
isFirstRender.current = false;
|
|
201
|
+
}
|
|
202
|
+
}, [apiRef, props.disableRowGrouping]);
|
|
76
203
|
};
|
|
@@ -5,6 +5,7 @@ interface FilterRowTreeFromTreeDataParams {
|
|
|
5
5
|
disableChildrenFiltering: boolean;
|
|
6
6
|
isRowMatchingFilters: GridAggregatedFilterItemApplier | null;
|
|
7
7
|
}
|
|
8
|
+
export declare const TREE_DATA_STRATEGY = "tree-data";
|
|
8
9
|
/**
|
|
9
10
|
* A node is visible if one of the following criteria is met:
|
|
10
11
|
* - One of its children is passing the filter
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
export const TREE_DATA_STRATEGY = 'tree-data';
|
|
1
2
|
/**
|
|
2
3
|
* A node is visible if one of the following criteria is met:
|
|
3
4
|
* - One of its children is passing the filter
|
|
4
5
|
* - It is passing the filter
|
|
5
6
|
*/
|
|
7
|
+
|
|
6
8
|
export const filterRowTreeFromTreeData = params => {
|
|
7
9
|
const {
|
|
8
10
|
rowTree,
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { GridApiPro } from '../../../models/gridApiPro';
|
|
3
|
-
import { DataGridProProcessedProps } from '../../../models/dataGridProProps';
|
|
4
|
-
export declare const TREE_DATA_GROUPING_NAME = "tree-data";
|
|
5
3
|
/**
|
|
6
4
|
* Only available in DataGridPro
|
|
7
|
-
* @requires useGridPreProcessing (method)
|
|
8
|
-
* @requires useGridRowGroupsPreProcessing (method)
|
|
9
5
|
*/
|
|
10
|
-
export declare const useGridTreeData: (apiRef: React.MutableRefObject<GridApiPro
|
|
6
|
+
export declare const useGridTreeData: (apiRef: React.MutableRefObject<GridApiPro>) => void;
|