@mui/x-data-grid-premium 7.21.0 → 7.22.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.
Files changed (34) hide show
  1. package/CHANGELOG.md +80 -0
  2. package/DataGridPremium/useDataGridPremiumComponent.js +2 -0
  3. package/components/GridDataSourceGroupingCriteriaCell.d.ts +7 -0
  4. package/components/GridDataSourceGroupingCriteriaCell.js +134 -0
  5. package/esm/DataGridPremium/useDataGridPremiumComponent.js +2 -0
  6. package/esm/components/GridDataSourceGroupingCriteriaCell.js +126 -0
  7. package/esm/hooks/features/rowGrouping/createGroupingColDef.js +18 -8
  8. package/esm/hooks/features/rowGrouping/gridRowGroupingUtils.js +10 -5
  9. package/esm/hooks/features/rowGrouping/useGridDataSourceRowGroupingPreProcessors.js +73 -0
  10. package/esm/hooks/features/rowGrouping/useGridRowGrouping.js +16 -6
  11. package/esm/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +17 -22
  12. package/esm/utils/releaseInfo.js +1 -1
  13. package/hooks/features/rowGrouping/createGroupingColDef.d.ts +5 -2
  14. package/hooks/features/rowGrouping/createGroupingColDef.js +17 -7
  15. package/hooks/features/rowGrouping/gridRowGroupingUtils.d.ts +7 -4
  16. package/hooks/features/rowGrouping/gridRowGroupingUtils.js +11 -6
  17. package/hooks/features/rowGrouping/useGridDataSourceRowGroupingPreProcessors.d.ts +4 -0
  18. package/hooks/features/rowGrouping/useGridDataSourceRowGroupingPreProcessors.js +81 -0
  19. package/hooks/features/rowGrouping/useGridRowGrouping.d.ts +1 -1
  20. package/hooks/features/rowGrouping/useGridRowGrouping.js +15 -5
  21. package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.d.ts +1 -1
  22. package/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +16 -21
  23. package/index.js +1 -1
  24. package/modern/DataGridPremium/useDataGridPremiumComponent.js +2 -0
  25. package/modern/components/GridDataSourceGroupingCriteriaCell.js +126 -0
  26. package/modern/hooks/features/rowGrouping/createGroupingColDef.js +18 -8
  27. package/modern/hooks/features/rowGrouping/gridRowGroupingUtils.js +10 -5
  28. package/modern/hooks/features/rowGrouping/useGridDataSourceRowGroupingPreProcessors.js +73 -0
  29. package/modern/hooks/features/rowGrouping/useGridRowGrouping.js +16 -6
  30. package/modern/hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js +17 -22
  31. package/modern/index.js +1 -1
  32. package/modern/utils/releaseInfo.js +1 -1
  33. package/package.json +4 -4
  34. package/utils/releaseInfo.js +1 -1
package/CHANGELOG.md CHANGED
@@ -3,6 +3,86 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## 7.22.0
7
+
8
+ _Oct 25, 2024_
9
+
10
+ We'd like to offer a big thanks to the 11 contributors who made this release possible. Here are some highlights ✨:
11
+
12
+ - 🛰 Introduce [server-side support for Data Grid row grouping](https://mui.com/x/react-data-grid/server-side-data/row-grouping/)
13
+ - 🐞 Bugfixes
14
+ - 📚 Documentation improvements
15
+ - 🌍 Improve Portuguese (pt-BR) locale on the Data Grid component
16
+
17
+ Special thanks go out to the community contributors who have helped make this release possible:
18
+ @clins1994, @GITPHLAP, @k-rajat19, @kalyan90, @merotosc, @yash49.
19
+ Following are all team members who have contributed to this release:
20
+ @cherniavskii, @flaviendelangle, @LukasTy, @MBilalShafi, @romgrk.
21
+
22
+ <!--/ HIGHLIGHT_ABOVE_SEPARATOR /-->
23
+
24
+ ### Data Grid
25
+
26
+ #### `@mui/x-data-grid@7.22.0`
27
+
28
+ - [DataGrid] Fix `GridPanelAnchor` positioning (#15022) @k-rajat19
29
+ - [DataGrid] Fix ugly prop-types for the `pageStyle` prop of the `GridPrintExportMenuItem` component (#15015) @flaviendelangle
30
+ - [DataGrid] Fix value type in filter model for number and boolean column type (#14733) @k-rajat19
31
+ - [DataGrid] Focus next row when the focused row is deleted (#15067) @cherniavskii
32
+ - [DataGrid] Remove some usages of `<Box />` and `<Badge />` (#15013) @romgrk
33
+ - [DataGrid] Fix number of rows to display for page size options with negative value (#14890) @kalyan90
34
+ - [l10n] Improve Portuguese (pt-BR) locale (#15021) @k-rajat19
35
+
36
+ #### `@mui/x-data-grid-pro@7.22.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
37
+
38
+ Same changes as in `@mui/x-data-grid@7.22.0`, plus:
39
+
40
+ - [DataGridPro] Fix column pinning layout (#15073) @cherniavskii
41
+
42
+ #### `@mui/x-data-grid-premium@7.22.0` [![premium](https://mui.com/r/x-premium-svg)](https://mui.com/r/x-premium-svg-link 'Premium plan')
43
+
44
+ Same changes as in `@mui/x-data-grid-pro@7.22.0`, plus:
45
+
46
+ - [DataGridPremium] Server-side data source with row grouping (#15109) @MBilalShafi
47
+
48
+ ### Date and Time Pickers
49
+
50
+ #### `@mui/x-date-pickers@7.22.0`
51
+
52
+ - [pickers] Fix `DateCalendar` timezone management (#15119) @LukasTy
53
+ - [pickers] Fix `DigitalClock` time options on a `DST` switch day (#15092) @LukasTy
54
+
55
+ #### `@mui/x-date-pickers-pro@7.22.0` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
56
+
57
+ Same changes as in `@mui/x-date-pickers@7.22.0`.
58
+
59
+ ### Charts
60
+
61
+ #### `@mui/x-charts@7.22.0`
62
+
63
+ - [charts] Export data type in `onAxisClick(_, data)` callback (#15038) @clins1994
64
+
65
+ #### `@mui/x-charts-pro@7.0.0-beta.6` [![pro](https://mui.com/r/x-pro-svg)](https://mui.com/r/x-pro-svg-link 'Pro plan')
66
+
67
+ Same changes as in `@mui/x-charts@7.22.0`.
68
+
69
+ ### Tree View
70
+
71
+ #### `@mui/x-tree-view@7.22.0`
72
+
73
+ - [TreeView] Make the cancellable event types public (#14992) @flaviendelangle
74
+
75
+ ### Docs
76
+
77
+ - [docs] Fix typo in Tree View docs (#15047) @yash49
78
+
79
+ ### Core
80
+
81
+ - [core] Adjust cherry-pick GH actions (#15101) @LukasTy
82
+ - [core] Update prettier target branch (#15100) @MBilalShafi
83
+ - [core] Update some `default-branch-switch` instances for `v7.x` (#15085) @MBilalShafi
84
+ - [test] Revert to using `fireEvent` instead of `userEvent` (#14927) @LukasTy
85
+
6
86
  ## 7.21.0
7
87
 
8
88
  _Oct 17, 2024_
@@ -9,6 +9,7 @@ var _useGridAggregation = require("../hooks/features/aggregation/useGridAggregat
9
9
  var _useGridAggregationPreProcessors = require("../hooks/features/aggregation/useGridAggregationPreProcessors");
10
10
  var _useGridRowGrouping = require("../hooks/features/rowGrouping/useGridRowGrouping");
11
11
  var _useGridRowGroupingPreProcessors = require("../hooks/features/rowGrouping/useGridRowGroupingPreProcessors");
12
+ var _useGridDataSourceRowGroupingPreProcessors = require("../hooks/features/rowGrouping/useGridDataSourceRowGroupingPreProcessors");
12
13
  var _useGridExcelExport = require("../hooks/features/export/useGridExcelExport");
13
14
  var _useGridCellSelection = require("../hooks/features/cellSelection/useGridCellSelection");
14
15
  var _useGridClipboardImport = require("../hooks/features/clipboard/useGridClipboardImport");
@@ -23,6 +24,7 @@ const useDataGridPremiumComponent = (inputApiRef, props) => {
23
24
  (0, _internals.useGridRowSelectionPreProcessors)(apiRef, props);
24
25
  (0, _internals.useGridRowReorderPreProcessors)(apiRef, props);
25
26
  (0, _useGridRowGroupingPreProcessors.useGridRowGroupingPreProcessors)(apiRef, props);
27
+ (0, _useGridDataSourceRowGroupingPreProcessors.useGridDataSourceRowGroupingPreProcessors)(apiRef, props);
26
28
  (0, _internals.useGridTreeDataPreProcessors)(apiRef, props);
27
29
  (0, _internals.useGridDataSourceTreeDataPreProcessors)(apiRef, props);
28
30
  (0, _internals.useGridLazyLoaderPreProcessors)(apiRef, props);
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ import { GridRenderCellParams, GridGroupNode } from '@mui/x-data-grid-pro';
3
+ interface GridGroupingCriteriaCellProps extends GridRenderCellParams<any, any, any, GridGroupNode> {
4
+ hideDescendantCount?: boolean;
5
+ }
6
+ export declare function GridDataSourceGroupingCriteriaCell(props: GridGroupingCriteriaCellProps): React.JSX.Element;
7
+ export {};
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.GridDataSourceGroupingCriteriaCell = GridDataSourceGroupingCriteriaCell;
9
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
+ var React = _interopRequireWildcard(require("react"));
11
+ var _utils = require("@mui/utils");
12
+ var _Box = _interopRequireDefault(require("@mui/material/Box"));
13
+ var _CircularProgress = _interopRequireDefault(require("@mui/material/CircularProgress"));
14
+ var _internals = require("@mui/x-data-grid-pro/internals");
15
+ var _xDataGridPro = require("@mui/x-data-grid-pro");
16
+ var _useGridApiContext = require("../hooks/utils/useGridApiContext");
17
+ var _useGridRootProps = require("../hooks/utils/useGridRootProps");
18
+ var _jsxRuntime = require("react/jsx-runtime");
19
+ const useUtilityClasses = ownerState => {
20
+ const {
21
+ classes
22
+ } = ownerState;
23
+ const slots = {
24
+ root: ['groupingCriteriaCell'],
25
+ toggle: ['groupingCriteriaCellToggle'],
26
+ loadingContainer: ['groupingCriteriaCellLoadingContainer']
27
+ };
28
+ return (0, _utils.unstable_composeClasses)(slots, _xDataGridPro.getDataGridUtilityClass, classes);
29
+ };
30
+ function GridGroupingCriteriaCellIcon(props) {
31
+ const apiRef = (0, _internals.useGridPrivateApiContext)();
32
+ const rootProps = (0, _useGridRootProps.useGridRootProps)();
33
+ const classes = useUtilityClasses(rootProps);
34
+ const {
35
+ rowNode,
36
+ id,
37
+ field,
38
+ descendantCount
39
+ } = props;
40
+ const loadingSelector = state => state.dataSource.loading[id] ?? false;
41
+ const errorSelector = state => state.dataSource.errors[id];
42
+ const isDataLoading = (0, _xDataGridPro.useGridSelector)(apiRef, loadingSelector);
43
+ const error = (0, _xDataGridPro.useGridSelector)(apiRef, errorSelector);
44
+ const handleClick = event => {
45
+ if (!rowNode.childrenExpanded) {
46
+ // always fetch/get from cache the children when the node is expanded
47
+ apiRef.current.unstable_dataSource.fetchRows(id);
48
+ } else {
49
+ apiRef.current.setRowChildrenExpansion(id, !rowNode.childrenExpanded);
50
+ }
51
+ apiRef.current.setCellFocus(id, field);
52
+ event.stopPropagation();
53
+ };
54
+ const Icon = rowNode.childrenExpanded ? rootProps.slots.groupingCriteriaCollapseIcon : rootProps.slots.groupingCriteriaExpandIcon;
55
+ if (isDataLoading) {
56
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
57
+ className: classes.loadingContainer,
58
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_CircularProgress.default, {
59
+ size: "1rem",
60
+ color: "inherit"
61
+ })
62
+ });
63
+ }
64
+ return descendantCount > 0 ? /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseIconButton, (0, _extends2.default)({
65
+ size: "small",
66
+ onClick: handleClick,
67
+ tabIndex: -1,
68
+ "aria-label": rowNode.childrenExpanded ? apiRef.current.getLocaleText('treeDataCollapse') : apiRef.current.getLocaleText('treeDataExpand')
69
+ }, rootProps?.slotProps?.baseIconButton, {
70
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseTooltip, {
71
+ title: error?.message ?? null,
72
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(rootProps.slots.baseBadge, {
73
+ variant: "dot",
74
+ color: "error",
75
+ invisible: !error,
76
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Icon, {
77
+ fontSize: "inherit"
78
+ })
79
+ })
80
+ })
81
+ })) : null;
82
+ }
83
+ function GridDataSourceGroupingCriteriaCell(props) {
84
+ const {
85
+ id,
86
+ field,
87
+ rowNode,
88
+ hideDescendantCount,
89
+ formattedValue
90
+ } = props;
91
+ const rootProps = (0, _useGridRootProps.useGridRootProps)();
92
+ const apiRef = (0, _useGridApiContext.useGridApiContext)();
93
+ const rowSelector = state => state.rows.dataRowIdToModelLookup[id];
94
+ const row = (0, _xDataGridPro.useGridSelector)(apiRef, rowSelector);
95
+ const classes = useUtilityClasses(rootProps);
96
+ let descendantCount = 0;
97
+ if (row) {
98
+ descendantCount = Math.max(rootProps.unstable_dataSource?.getChildrenCount?.(row) ?? 0, 0);
99
+ }
100
+ let cellContent;
101
+ const colDef = apiRef.current.getColumn(rowNode.groupingField);
102
+ if (typeof colDef?.renderCell === 'function') {
103
+ cellContent = colDef.renderCell(props);
104
+ } else if (typeof formattedValue !== 'undefined') {
105
+ cellContent = /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
106
+ children: formattedValue
107
+ });
108
+ } else {
109
+ cellContent = /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
110
+ children: rowNode.groupingKey
111
+ });
112
+ }
113
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Box.default, {
114
+ className: classes.root,
115
+ sx: {
116
+ ml: rootProps.rowGroupingColumnMode === 'multiple' ? 0 : theme => `calc(var(--DataGrid-cellOffsetMultiplier) * ${theme.spacing(rowNode.depth)})`
117
+ },
118
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
119
+ className: classes.toggle,
120
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(GridGroupingCriteriaCellIcon, {
121
+ id: id,
122
+ field: field,
123
+ rowNode: rowNode,
124
+ row: row,
125
+ descendantCount: descendantCount
126
+ })
127
+ }), cellContent, !hideDescendantCount && descendantCount > 0 ? /*#__PURE__*/(0, _jsxRuntime.jsxs)("span", {
128
+ style: {
129
+ whiteSpace: 'pre'
130
+ },
131
+ children: [" (", descendantCount, ")"]
132
+ }) : null]
133
+ });
134
+ }
@@ -4,6 +4,7 @@ import { useGridAggregation, aggregationStateInitializer } from "../hooks/featur
4
4
  import { useGridAggregationPreProcessors } from "../hooks/features/aggregation/useGridAggregationPreProcessors.js";
5
5
  import { useGridRowGrouping, rowGroupingStateInitializer } from "../hooks/features/rowGrouping/useGridRowGrouping.js";
6
6
  import { useGridRowGroupingPreProcessors } from "../hooks/features/rowGrouping/useGridRowGroupingPreProcessors.js";
7
+ import { useGridDataSourceRowGroupingPreProcessors } from "../hooks/features/rowGrouping/useGridDataSourceRowGroupingPreProcessors.js";
7
8
  import { useGridExcelExport } from "../hooks/features/export/useGridExcelExport.js";
8
9
  import { cellSelectionStateInitializer, useGridCellSelection } from "../hooks/features/cellSelection/useGridCellSelection.js";
9
10
  import { useGridClipboardImport } from "../hooks/features/clipboard/useGridClipboardImport.js";
@@ -16,6 +17,7 @@ export const useDataGridPremiumComponent = (inputApiRef, props) => {
16
17
  useGridRowSelectionPreProcessors(apiRef, props);
17
18
  useGridRowReorderPreProcessors(apiRef, props);
18
19
  useGridRowGroupingPreProcessors(apiRef, props);
20
+ useGridDataSourceRowGroupingPreProcessors(apiRef, props);
19
21
  useGridTreeDataPreProcessors(apiRef, props);
20
22
  useGridDataSourceTreeDataPreProcessors(apiRef, props);
21
23
  useGridLazyLoaderPreProcessors(apiRef, props);
@@ -0,0 +1,126 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import * as React from 'react';
3
+ import { unstable_composeClasses as composeClasses } from '@mui/utils';
4
+ import Box from '@mui/material/Box';
5
+ import CircularProgress from '@mui/material/CircularProgress';
6
+ import { useGridPrivateApiContext } from '@mui/x-data-grid-pro/internals';
7
+ import { useGridSelector, getDataGridUtilityClass } from '@mui/x-data-grid-pro';
8
+ import { useGridApiContext } from "../hooks/utils/useGridApiContext.js";
9
+ import { useGridRootProps } from "../hooks/utils/useGridRootProps.js";
10
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
+ const useUtilityClasses = ownerState => {
12
+ const {
13
+ classes
14
+ } = ownerState;
15
+ const slots = {
16
+ root: ['groupingCriteriaCell'],
17
+ toggle: ['groupingCriteriaCellToggle'],
18
+ loadingContainer: ['groupingCriteriaCellLoadingContainer']
19
+ };
20
+ return composeClasses(slots, getDataGridUtilityClass, classes);
21
+ };
22
+ function GridGroupingCriteriaCellIcon(props) {
23
+ const apiRef = useGridPrivateApiContext();
24
+ const rootProps = useGridRootProps();
25
+ const classes = useUtilityClasses(rootProps);
26
+ const {
27
+ rowNode,
28
+ id,
29
+ field,
30
+ descendantCount
31
+ } = props;
32
+ const loadingSelector = state => state.dataSource.loading[id] ?? false;
33
+ const errorSelector = state => state.dataSource.errors[id];
34
+ const isDataLoading = useGridSelector(apiRef, loadingSelector);
35
+ const error = useGridSelector(apiRef, errorSelector);
36
+ const handleClick = event => {
37
+ if (!rowNode.childrenExpanded) {
38
+ // always fetch/get from cache the children when the node is expanded
39
+ apiRef.current.unstable_dataSource.fetchRows(id);
40
+ } else {
41
+ apiRef.current.setRowChildrenExpansion(id, !rowNode.childrenExpanded);
42
+ }
43
+ apiRef.current.setCellFocus(id, field);
44
+ event.stopPropagation();
45
+ };
46
+ const Icon = rowNode.childrenExpanded ? rootProps.slots.groupingCriteriaCollapseIcon : rootProps.slots.groupingCriteriaExpandIcon;
47
+ if (isDataLoading) {
48
+ return /*#__PURE__*/_jsx("div", {
49
+ className: classes.loadingContainer,
50
+ children: /*#__PURE__*/_jsx(CircularProgress, {
51
+ size: "1rem",
52
+ color: "inherit"
53
+ })
54
+ });
55
+ }
56
+ return descendantCount > 0 ? /*#__PURE__*/_jsx(rootProps.slots.baseIconButton, _extends({
57
+ size: "small",
58
+ onClick: handleClick,
59
+ tabIndex: -1,
60
+ "aria-label": rowNode.childrenExpanded ? apiRef.current.getLocaleText('treeDataCollapse') : apiRef.current.getLocaleText('treeDataExpand')
61
+ }, rootProps?.slotProps?.baseIconButton, {
62
+ children: /*#__PURE__*/_jsx(rootProps.slots.baseTooltip, {
63
+ title: error?.message ?? null,
64
+ children: /*#__PURE__*/_jsx(rootProps.slots.baseBadge, {
65
+ variant: "dot",
66
+ color: "error",
67
+ invisible: !error,
68
+ children: /*#__PURE__*/_jsx(Icon, {
69
+ fontSize: "inherit"
70
+ })
71
+ })
72
+ })
73
+ })) : null;
74
+ }
75
+ export function GridDataSourceGroupingCriteriaCell(props) {
76
+ const {
77
+ id,
78
+ field,
79
+ rowNode,
80
+ hideDescendantCount,
81
+ formattedValue
82
+ } = props;
83
+ const rootProps = useGridRootProps();
84
+ const apiRef = useGridApiContext();
85
+ const rowSelector = state => state.rows.dataRowIdToModelLookup[id];
86
+ const row = useGridSelector(apiRef, rowSelector);
87
+ const classes = useUtilityClasses(rootProps);
88
+ let descendantCount = 0;
89
+ if (row) {
90
+ descendantCount = Math.max(rootProps.unstable_dataSource?.getChildrenCount?.(row) ?? 0, 0);
91
+ }
92
+ let cellContent;
93
+ const colDef = apiRef.current.getColumn(rowNode.groupingField);
94
+ if (typeof colDef?.renderCell === 'function') {
95
+ cellContent = colDef.renderCell(props);
96
+ } else if (typeof formattedValue !== 'undefined') {
97
+ cellContent = /*#__PURE__*/_jsx("span", {
98
+ children: formattedValue
99
+ });
100
+ } else {
101
+ cellContent = /*#__PURE__*/_jsx("span", {
102
+ children: rowNode.groupingKey
103
+ });
104
+ }
105
+ return /*#__PURE__*/_jsxs(Box, {
106
+ className: classes.root,
107
+ sx: {
108
+ ml: rootProps.rowGroupingColumnMode === 'multiple' ? 0 : theme => `calc(var(--DataGrid-cellOffsetMultiplier) * ${theme.spacing(rowNode.depth)})`
109
+ },
110
+ children: [/*#__PURE__*/_jsx("div", {
111
+ className: classes.toggle,
112
+ children: /*#__PURE__*/_jsx(GridGroupingCriteriaCellIcon, {
113
+ id: id,
114
+ field: field,
115
+ rowNode: rowNode,
116
+ row: row,
117
+ descendantCount: descendantCount
118
+ })
119
+ }), cellContent, !hideDescendantCount && descendantCount > 0 ? /*#__PURE__*/_jsxs("span", {
120
+ style: {
121
+ whiteSpace: 'pre'
122
+ },
123
+ children: [" (", descendantCount, ")"]
124
+ }) : null]
125
+ });
126
+ }
@@ -7,18 +7,24 @@ import { GRID_STRING_COL_DEF } from '@mui/x-data-grid-pro';
7
7
  import { isSingleSelectColDef } from '@mui/x-data-grid-pro/internals';
8
8
  import { GridGroupingColumnFooterCell } from "../../../components/GridGroupingColumnFooterCell.js";
9
9
  import { GridGroupingCriteriaCell } from "../../../components/GridGroupingCriteriaCell.js";
10
+ import { GridDataSourceGroupingCriteriaCell } from "../../../components/GridDataSourceGroupingCriteriaCell.js";
10
11
  import { GridGroupingColumnLeafCell } from "../../../components/GridGroupingColumnLeafCell.js";
11
- import { getRowGroupingFieldFromGroupingCriteria, GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD } from "./gridRowGroupingUtils.js";
12
+ import { getRowGroupingFieldFromGroupingCriteria, GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD, RowGroupingStrategy } from "./gridRowGroupingUtils.js";
12
13
  import { gridRowGroupingSanitizedModelSelector } from "./gridRowGroupingSelector.js";
13
14
  import { jsx as _jsx } from "react/jsx-runtime";
14
15
  const GROUPING_COL_DEF_DEFAULT_PROPERTIES = _extends({}, GRID_STRING_COL_DEF, {
15
16
  type: 'custom',
16
17
  disableReorder: true
17
18
  });
18
- const GROUPING_COL_DEF_FORCED_PROPERTIES = {
19
+ const GROUPING_COL_DEF_FORCED_PROPERTIES_DEFAULT = {
19
20
  editable: false,
20
21
  groupable: false
21
22
  };
23
+ const GROUPING_COL_DEF_FORCED_PROPERTIES_DATA_SOURCE = _extends({}, GROUPING_COL_DEF_FORCED_PROPERTIES_DEFAULT, {
24
+ // TODO: Support these features on the grouping column(s)
25
+ filterable: false,
26
+ sortable: false
27
+ });
22
28
 
23
29
  /**
24
30
  * When sorting two cells with different grouping criteria, we consider that the cell with the grouping criteria coming first in the model should be displayed below.
@@ -84,7 +90,8 @@ export const createGroupingColDefForOneGroupingCriteria = ({
84
90
  columnsLookup,
85
91
  groupedByColDef,
86
92
  groupingCriteria,
87
- colDefOverride
93
+ colDefOverride,
94
+ strategy = RowGroupingStrategy.Default
88
95
  }) => {
89
96
  const _ref = colDefOverride ?? {},
90
97
  {
@@ -94,6 +101,7 @@ export const createGroupingColDefForOneGroupingCriteria = ({
94
101
  } = _ref,
95
102
  colDefOverrideProperties = _objectWithoutPropertiesLoose(_ref, _excluded);
96
103
  const leafColDef = leafField ? columnsLookup[leafField] : null;
104
+ const CriteriaCell = strategy === RowGroupingStrategy.Default ? GridGroupingCriteriaCell : GridDataSourceGroupingCriteriaCell;
97
105
 
98
106
  // The properties that do not depend on the presence of a `leafColDef` and that can be overridden by `colDefOverride`
99
107
  const commonProperties = {
@@ -121,7 +129,7 @@ export const createGroupingColDefForOneGroupingCriteria = ({
121
129
 
122
130
  // Render current grouping criteria groups
123
131
  if (params.rowNode.groupingField === groupingCriteria) {
124
- return /*#__PURE__*/_jsx(GridGroupingCriteriaCell, _extends({}, params, {
132
+ return /*#__PURE__*/_jsx(CriteriaCell, _extends({}, params, {
125
133
  hideDescendantCount: hideDescendantCount
126
134
  }));
127
135
  }
@@ -166,7 +174,7 @@ export const createGroupingColDefForOneGroupingCriteria = ({
166
174
  // The properties that can't be overridden with `colDefOverride`
167
175
  const forcedProperties = _extends({
168
176
  field: getRowGroupingFieldFromGroupingCriteria(groupingCriteria)
169
- }, GROUPING_COL_DEF_FORCED_PROPERTIES);
177
+ }, GROUPING_COL_DEF_FORCED_PROPERTIES_DEFAULT);
170
178
  return _extends({}, GROUPING_COL_DEF_DEFAULT_PROPERTIES, commonProperties, sourceProperties, colDefOverrideProperties, forcedProperties);
171
179
  };
172
180
  /**
@@ -176,7 +184,8 @@ export const createGroupingColDefForAllGroupingCriteria = ({
176
184
  apiRef,
177
185
  columnsLookup,
178
186
  rowGroupingModel,
179
- colDefOverride
187
+ colDefOverride,
188
+ strategy = RowGroupingStrategy.Default
180
189
  }) => {
181
190
  const _ref2 = colDefOverride ?? {},
182
191
  {
@@ -186,6 +195,7 @@ export const createGroupingColDefForAllGroupingCriteria = ({
186
195
  } = _ref2,
187
196
  colDefOverrideProperties = _objectWithoutPropertiesLoose(_ref2, _excluded2);
188
197
  const leafColDef = leafField ? columnsLookup[leafField] : null;
198
+ const CriteriaCell = strategy === RowGroupingStrategy.Default ? GridGroupingCriteriaCell : GridDataSourceGroupingCriteriaCell;
189
199
 
190
200
  // The properties that do not depend on the presence of a `leafColDef` and that can be overridden by `colDefOverride`
191
201
  const commonProperties = {
@@ -213,7 +223,7 @@ export const createGroupingColDefForAllGroupingCriteria = ({
213
223
  }
214
224
 
215
225
  // Render the groups
216
- return /*#__PURE__*/_jsx(GridGroupingCriteriaCell, _extends({}, params, {
226
+ return /*#__PURE__*/_jsx(CriteriaCell, _extends({}, params, {
217
227
  hideDescendantCount: hideDescendantCount
218
228
  }));
219
229
  },
@@ -253,6 +263,6 @@ export const createGroupingColDefForAllGroupingCriteria = ({
253
263
  // The properties that can't be overridden with `colDefOverride`
254
264
  const forcedProperties = _extends({
255
265
  field: GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD
256
- }, GROUPING_COL_DEF_FORCED_PROPERTIES);
266
+ }, strategy === RowGroupingStrategy.Default ? GROUPING_COL_DEF_FORCED_PROPERTIES_DEFAULT : GROUPING_COL_DEF_FORCED_PROPERTIES_DATA_SOURCE);
257
267
  return _extends({}, GROUPING_COL_DEF_DEFAULT_PROPERTIES, commonProperties, sourceProperties, colDefOverrideProperties, forcedProperties);
258
268
  };
@@ -2,7 +2,11 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import { passFilterLogic } from '@mui/x-data-grid-pro/internals';
3
3
  import { gridRowGroupingSanitizedModelSelector } from "./gridRowGroupingSelector.js";
4
4
  export const GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD = '__row_group_by_columns_group__';
5
- export const ROW_GROUPING_STRATEGY = 'grouping-columns';
5
+ export let RowGroupingStrategy = /*#__PURE__*/function (RowGroupingStrategy) {
6
+ RowGroupingStrategy["Default"] = "grouping-columns";
7
+ RowGroupingStrategy["DataSource"] = "grouping-columns-data-source";
8
+ return RowGroupingStrategy;
9
+ }({});
6
10
  export const getRowGroupingFieldFromGroupingCriteria = groupingCriteria => {
7
11
  if (groupingCriteria === null) {
8
12
  return GRID_ROW_GROUPING_SINGLE_GROUPING_FIELD;
@@ -103,10 +107,10 @@ export const filterRowTreeFromGroupingColumns = params => {
103
107
  filteredDescendantCountLookup
104
108
  };
105
109
  };
106
- export const getColDefOverrides = (groupingColDefProp, fields) => {
110
+ export const getColDefOverrides = (groupingColDefProp, fields, strategy) => {
107
111
  if (typeof groupingColDefProp === 'function') {
108
112
  return groupingColDefProp({
109
- groupingName: ROW_GROUPING_STRATEGY,
113
+ groupingName: strategy ?? RowGroupingStrategy.Default,
110
114
  fields
111
115
  });
112
116
  }
@@ -117,7 +121,7 @@ export const mergeStateWithRowGroupingModel = rowGroupingModel => state => _exte
117
121
  model: rowGroupingModel
118
122
  })
119
123
  });
120
- export const setStrategyAvailability = (privateApiRef, disableRowGrouping) => {
124
+ export const setStrategyAvailability = (privateApiRef, disableRowGrouping, dataSource) => {
121
125
  let isAvailable;
122
126
  if (disableRowGrouping) {
123
127
  isAvailable = () => false;
@@ -127,7 +131,8 @@ export const setStrategyAvailability = (privateApiRef, disableRowGrouping) => {
127
131
  return rowGroupingSanitizedModel.length > 0;
128
132
  };
129
133
  }
130
- privateApiRef.current.setStrategyAvailability('rowTree', ROW_GROUPING_STRATEGY, isAvailable);
134
+ const strategy = dataSource ? RowGroupingStrategy.DataSource : RowGroupingStrategy.Default;
135
+ privateApiRef.current.setStrategyAvailability('rowTree', strategy, isAvailable);
131
136
  };
132
137
  export const getCellGroupingCriteria = ({
133
138
  row,
@@ -0,0 +1,73 @@
1
+ import * as React from 'react';
2
+ import { gridRowTreeSelector, gridColumnLookupSelector } from '@mui/x-data-grid-pro';
3
+ import { useGridRegisterStrategyProcessor, createRowTree, updateRowTree, getVisibleRowsLookup, skipSorting, skipFiltering } from '@mui/x-data-grid-pro/internals';
4
+ import { getGroupingRules, RowGroupingStrategy } from "./gridRowGroupingUtils.js";
5
+ import { gridRowGroupingSanitizedModelSelector } from "./gridRowGroupingSelector.js";
6
+ export const useGridDataSourceRowGroupingPreProcessors = (apiRef, props) => {
7
+ const createRowTreeForRowGrouping = React.useCallback(params => {
8
+ const getGroupKey = props.unstable_dataSource?.getGroupKey;
9
+ if (!getGroupKey) {
10
+ throw new Error('MUI X: No `getGroupKey` method provided with the dataSource.');
11
+ }
12
+ const getChildrenCount = props.unstable_dataSource?.getChildrenCount;
13
+ if (!getChildrenCount) {
14
+ throw new Error('MUI X: No `getChildrenCount` method provided with the dataSource.');
15
+ }
16
+ const sanitizedRowGroupingModel = gridRowGroupingSanitizedModelSelector(apiRef);
17
+ const columnsLookup = gridColumnLookupSelector(apiRef);
18
+ const groupingRules = getGroupingRules({
19
+ sanitizedRowGroupingModel,
20
+ columnsLookup
21
+ });
22
+ apiRef.current.caches.rowGrouping.rulesOnLastRowTreeCreation = groupingRules;
23
+ const getRowTreeBuilderNode = rowId => {
24
+ const parentPath = params.updates.groupKeys ?? [];
25
+ const row = params.dataRowIdToModelLookup[rowId];
26
+ const groupingRule = groupingRules[parentPath.length];
27
+ const groupingValueGetter = groupingRule?.groupingValueGetter;
28
+ const leafKey = groupingValueGetter?.(row[groupingRule.field], row, columnsLookup[groupingRule.field], apiRef) ?? getGroupKey(params.dataRowIdToModelLookup[rowId]);
29
+ return {
30
+ id: rowId,
31
+ path: [...parentPath, leafKey ?? rowId.toString()].map((key, i) => ({
32
+ key,
33
+ field: groupingRules[i]?.field ?? null
34
+ })),
35
+ serverChildrenCount: getChildrenCount(params.dataRowIdToModelLookup[rowId]) ?? 0
36
+ };
37
+ };
38
+ if (params.updates.type === 'full') {
39
+ return createRowTree({
40
+ previousTree: params.previousTree,
41
+ nodes: params.updates.rows.map(getRowTreeBuilderNode),
42
+ defaultGroupingExpansionDepth: props.defaultGroupingExpansionDepth,
43
+ isGroupExpandedByDefault: props.isGroupExpandedByDefault,
44
+ groupingName: RowGroupingStrategy.DataSource
45
+ });
46
+ }
47
+ return updateRowTree({
48
+ nodes: {
49
+ inserted: params.updates.actions.insert.map(getRowTreeBuilderNode),
50
+ modified: params.updates.actions.modify.map(getRowTreeBuilderNode),
51
+ removed: params.updates.actions.remove
52
+ },
53
+ previousTree: params.previousTree,
54
+ previousGroupsToFetch: params.previousGroupsToFetch,
55
+ previousTreeDepth: params.previousTreeDepths,
56
+ defaultGroupingExpansionDepth: props.defaultGroupingExpansionDepth,
57
+ isGroupExpandedByDefault: props.isGroupExpandedByDefault,
58
+ groupingName: RowGroupingStrategy.DataSource
59
+ });
60
+ }, [apiRef, props.unstable_dataSource, props.defaultGroupingExpansionDepth, props.isGroupExpandedByDefault]);
61
+ const filterRows = React.useCallback(() => {
62
+ const rowTree = gridRowTreeSelector(apiRef);
63
+ return skipFiltering(rowTree);
64
+ }, [apiRef]);
65
+ const sortRows = React.useCallback(() => {
66
+ const rowTree = gridRowTreeSelector(apiRef);
67
+ return skipSorting(rowTree);
68
+ }, [apiRef]);
69
+ useGridRegisterStrategyProcessor(apiRef, RowGroupingStrategy.DataSource, 'rowTreeCreation', createRowTreeForRowGrouping);
70
+ useGridRegisterStrategyProcessor(apiRef, RowGroupingStrategy.DataSource, 'filtering', filterRows);
71
+ useGridRegisterStrategyProcessor(apiRef, RowGroupingStrategy.DataSource, 'sorting', sortRows);
72
+ useGridRegisterStrategyProcessor(apiRef, RowGroupingStrategy.DataSource, 'visibleRowsLookupCreation', getVisibleRowsLookup);
73
+ };