Skip to content

Commit 2d0cd41

Browse files
MBilalShafiJCQuintas
authored andcommitted
[DataGridPremium] Fallback to the regular reorder method for plain data (mui#19467)
1 parent 8b12ebd commit 2d0cd41

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/x-data-grid-premium/src/hooks/features/rows/useGridRowsOverridableMethods.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ import {
44
gridRowTreeSelector,
55
gridExpandedSortedRowIdsSelector,
66
gridRowNodeSelector,
7+
gridRowMaximumTreeDepthSelector,
78
} from '@mui/x-data-grid-pro';
8-
import { gridExpandedSortedRowIndexLookupSelector } from '@mui/x-data-grid-pro/internals';
9+
import {
10+
gridExpandedSortedRowIndexLookupSelector,
11+
useGridRowsOverridableMethods as useGridRowsOverridableMethodsCommunity,
12+
useGridSelector,
13+
} from '@mui/x-data-grid-pro/internals';
914
import type { RefObject } from '@mui/x-internals/types';
1015
import { rowGroupingReorderExecutor } from '../rowReorder/reorderExecutor';
1116
import type { GridPrivateApiPremium } from '../../../models/gridApiPremium';
@@ -17,6 +22,9 @@ export const useGridRowsOverridableMethods = (
1722
props: Pick<DataGridPremiumProcessedProps, 'processRowUpdate' | 'onProcessRowUpdateError'>,
1823
) => {
1924
const { processRowUpdate, onProcessRowUpdateError } = props;
25+
const { setRowIndex: setRowIndexPlain } = useGridRowsOverridableMethodsCommunity(apiRef);
26+
27+
const flatTree = useGridSelector(apiRef, gridRowMaximumTreeDepthSelector) === 1;
2028

2129
const setRowIndex = React.useCallback(
2230
async (sourceRowId: GridRowId, targetOriginalIndex: number) => {
@@ -66,6 +74,6 @@ export const useGridRowsOverridableMethods = (
6674
);
6775

6876
return {
69-
setRowIndex,
77+
setRowIndex: flatTree ? setRowIndexPlain : setRowIndex,
7078
};
7179
};

0 commit comments

Comments
 (0)