@mui/x-data-grid 7.24.1 → 7.26.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 (188) hide show
  1. package/CHANGELOG.md +148 -0
  2. package/DataGrid/DataGrid.js +1 -7
  3. package/DataGrid/useDataGridComponent.js +2 -2
  4. package/components/GridRow.d.ts +0 -1
  5. package/components/GridRow.js +32 -20
  6. package/components/GridScrollArea.d.ts +5 -2
  7. package/components/GridScrollArea.js +32 -25
  8. package/components/GridSkeletonLoadingOverlay.js +2 -1
  9. package/components/cell/GridCell.d.ts +9 -6
  10. package/components/cell/GridCell.js +29 -52
  11. package/components/containers/GridRoot.js +11 -9
  12. package/components/containers/GridRootStyles.js +138 -40
  13. package/components/toolbar/GridToolbarColumnsButton.js +5 -4
  14. package/components/toolbar/GridToolbarDensitySelector.js +2 -2
  15. package/components/toolbar/GridToolbarExportContainer.js +2 -2
  16. package/components/toolbar/GridToolbarFilterButton.js +4 -3
  17. package/components/virtualization/GridMainContainer.d.ts +10 -0
  18. package/components/virtualization/GridMainContainer.js +10 -2
  19. package/components/virtualization/GridVirtualScrollbar.d.ts +4 -0
  20. package/components/virtualization/GridVirtualScrollbar.js +5 -5
  21. package/components/virtualization/GridVirtualScroller.js +36 -16
  22. package/components/virtualization/GridVirtualScrollerContent.js +11 -2
  23. package/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.d.ts +1 -1
  24. package/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.js +6 -4
  25. package/hooks/core/useGridStateInitialization.js +3 -2
  26. package/hooks/features/columnHeaders/useGridColumnHeaders.js +10 -14
  27. package/hooks/features/columnResize/useGridColumnResize.js +2 -1
  28. package/hooks/features/columns/gridColumnsSelector.d.ts +0 -5
  29. package/hooks/features/columns/gridColumnsSelector.js +0 -12
  30. package/hooks/features/columns/useGridColumns.js +7 -3
  31. package/hooks/features/dimensions/gridDimensionsSelectors.d.ts +16 -0
  32. package/hooks/features/dimensions/gridDimensionsSelectors.js +26 -1
  33. package/hooks/features/dimensions/index.d.ts +1 -1
  34. package/hooks/features/dimensions/index.js +1 -2
  35. package/hooks/features/dimensions/useGridDimensions.js +102 -77
  36. package/hooks/features/editing/gridEditingSelectors.d.ts +10 -0
  37. package/hooks/features/editing/gridEditingSelectors.js +12 -1
  38. package/hooks/features/editing/index.d.ts +1 -1
  39. package/hooks/features/editing/index.js +1 -1
  40. package/hooks/features/editing/useGridCellEditing.js +3 -3
  41. package/hooks/features/editing/useGridRowEditing.js +8 -9
  42. package/hooks/features/filter/gridFilterState.d.ts +5 -0
  43. package/hooks/features/filter/gridFilterState.js +5 -0
  44. package/hooks/features/filter/useGridFilter.js +6 -13
  45. package/hooks/features/focus/useGridFocus.js +3 -2
  46. package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +24 -16
  47. package/hooks/features/keyboardNavigation/utils.d.ts +1 -2
  48. package/hooks/features/keyboardNavigation/utils.js +0 -5
  49. package/hooks/features/listView/useGridListView.js +2 -1
  50. package/hooks/features/pagination/useGridPagination.js +1 -1
  51. package/hooks/features/rowSelection/useGridRowSelection.js +4 -4
  52. package/hooks/features/rowSelection/utils.js +1 -1
  53. package/hooks/features/rows/gridRowsMetaState.d.ts +8 -0
  54. package/hooks/features/rows/gridRowsUtils.d.ts +0 -4
  55. package/hooks/features/rows/gridRowsUtils.js +0 -16
  56. package/hooks/features/rows/useGridParamsApi.d.ts +1 -1
  57. package/hooks/features/rows/useGridParamsApi.js +33 -14
  58. package/hooks/features/rows/useGridRowSpanning.js +94 -91
  59. package/hooks/features/rows/useGridRows.js +7 -8
  60. package/hooks/features/rows/useGridRowsMeta.js +36 -19
  61. package/hooks/features/sorting/gridSortingSelector.js +10 -9
  62. package/hooks/features/virtualization/gridFocusedVirtualCellSelector.js +2 -2
  63. package/hooks/features/virtualization/useGridVirtualScroller.d.ts +15 -1
  64. package/hooks/features/virtualization/useGridVirtualScroller.js +74 -72
  65. package/hooks/utils/useGridSelector.d.ts +8 -1
  66. package/hooks/utils/useGridSelector.js +42 -8
  67. package/hooks/utils/useIsSSR.d.ts +1 -0
  68. package/hooks/utils/useIsSSR.js +5 -0
  69. package/index.js +1 -1
  70. package/internals/index.d.ts +2 -1
  71. package/internals/index.js +2 -1
  72. package/models/api/gridApiCommon.d.ts +2 -2
  73. package/models/api/gridParamsApi.d.ts +29 -2
  74. package/models/api/gridStateApi.d.ts +1 -0
  75. package/models/api/index.d.ts +1 -1
  76. package/models/api/index.js +0 -1
  77. package/models/events/gridEventLookup.d.ts +6 -0
  78. package/modern/DataGrid/DataGrid.js +1 -7
  79. package/modern/DataGrid/useDataGridComponent.js +2 -2
  80. package/modern/components/GridRow.js +32 -20
  81. package/modern/components/GridScrollArea.js +32 -25
  82. package/modern/components/GridSkeletonLoadingOverlay.js +2 -1
  83. package/modern/components/cell/GridCell.js +29 -52
  84. package/modern/components/containers/GridRoot.js +11 -9
  85. package/modern/components/containers/GridRootStyles.js +138 -40
  86. package/modern/components/toolbar/GridToolbarColumnsButton.js +5 -4
  87. package/modern/components/toolbar/GridToolbarDensitySelector.js +2 -2
  88. package/modern/components/toolbar/GridToolbarExportContainer.js +2 -2
  89. package/modern/components/toolbar/GridToolbarFilterButton.js +4 -3
  90. package/modern/components/virtualization/GridMainContainer.js +10 -2
  91. package/modern/components/virtualization/GridVirtualScrollbar.js +5 -5
  92. package/modern/components/virtualization/GridVirtualScroller.js +36 -16
  93. package/modern/components/virtualization/GridVirtualScrollerContent.js +11 -2
  94. package/modern/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.js +6 -4
  95. package/modern/hooks/core/useGridStateInitialization.js +3 -2
  96. package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +10 -14
  97. package/modern/hooks/features/columnResize/useGridColumnResize.js +2 -1
  98. package/modern/hooks/features/columns/gridColumnsSelector.js +0 -12
  99. package/modern/hooks/features/columns/useGridColumns.js +7 -3
  100. package/modern/hooks/features/dimensions/gridDimensionsSelectors.js +26 -1
  101. package/modern/hooks/features/dimensions/index.js +1 -2
  102. package/modern/hooks/features/dimensions/useGridDimensions.js +102 -77
  103. package/modern/hooks/features/editing/gridEditingSelectors.js +12 -1
  104. package/modern/hooks/features/editing/index.js +1 -1
  105. package/modern/hooks/features/editing/useGridCellEditing.js +3 -3
  106. package/modern/hooks/features/editing/useGridRowEditing.js +8 -9
  107. package/modern/hooks/features/filter/gridFilterState.js +5 -0
  108. package/modern/hooks/features/filter/useGridFilter.js +6 -13
  109. package/modern/hooks/features/focus/useGridFocus.js +3 -2
  110. package/modern/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +24 -16
  111. package/modern/hooks/features/keyboardNavigation/utils.js +0 -5
  112. package/modern/hooks/features/listView/useGridListView.js +2 -1
  113. package/modern/hooks/features/pagination/useGridPagination.js +1 -1
  114. package/modern/hooks/features/rowSelection/useGridRowSelection.js +4 -4
  115. package/modern/hooks/features/rowSelection/utils.js +1 -1
  116. package/modern/hooks/features/rows/gridRowsUtils.js +0 -16
  117. package/modern/hooks/features/rows/useGridParamsApi.js +33 -14
  118. package/modern/hooks/features/rows/useGridRowSpanning.js +94 -91
  119. package/modern/hooks/features/rows/useGridRows.js +7 -8
  120. package/modern/hooks/features/rows/useGridRowsMeta.js +36 -19
  121. package/modern/hooks/features/sorting/gridSortingSelector.js +10 -9
  122. package/modern/hooks/features/virtualization/gridFocusedVirtualCellSelector.js +2 -2
  123. package/modern/hooks/features/virtualization/useGridVirtualScroller.js +74 -72
  124. package/modern/hooks/utils/useGridSelector.js +42 -8
  125. package/modern/hooks/utils/useIsSSR.js +5 -0
  126. package/modern/index.js +1 -1
  127. package/modern/internals/index.js +2 -1
  128. package/modern/models/api/index.js +0 -1
  129. package/modern/utils/roundToDecimalPlaces.js +3 -0
  130. package/modern/utils/utils.js +6 -1
  131. package/node/DataGrid/DataGrid.js +1 -7
  132. package/node/DataGrid/useDataGridComponent.js +2 -2
  133. package/node/components/GridRow.js +28 -17
  134. package/node/components/GridScrollArea.js +31 -24
  135. package/node/components/GridSkeletonLoadingOverlay.js +2 -1
  136. package/node/components/cell/GridCell.js +27 -50
  137. package/node/components/containers/GridRoot.js +10 -8
  138. package/node/components/containers/GridRootStyles.js +138 -40
  139. package/node/components/toolbar/GridToolbarColumnsButton.js +5 -4
  140. package/node/components/toolbar/GridToolbarDensitySelector.js +2 -2
  141. package/node/components/toolbar/GridToolbarExportContainer.js +2 -2
  142. package/node/components/toolbar/GridToolbarFilterButton.js +4 -3
  143. package/node/components/virtualization/GridMainContainer.js +10 -2
  144. package/node/components/virtualization/GridVirtualScrollbar.js +5 -5
  145. package/node/components/virtualization/GridVirtualScroller.js +36 -16
  146. package/node/components/virtualization/GridVirtualScrollerContent.js +11 -2
  147. package/node/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.js +6 -4
  148. package/node/hooks/core/useGridStateInitialization.js +3 -2
  149. package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +10 -14
  150. package/node/hooks/features/columnResize/useGridColumnResize.js +2 -1
  151. package/node/hooks/features/columns/gridColumnsSelector.js +1 -13
  152. package/node/hooks/features/columns/useGridColumns.js +7 -3
  153. package/node/hooks/features/dimensions/gridDimensionsSelectors.js +38 -2
  154. package/node/hooks/features/dimensions/index.js +13 -11
  155. package/node/hooks/features/dimensions/useGridDimensions.js +99 -74
  156. package/node/hooks/features/editing/gridEditingSelectors.js +12 -2
  157. package/node/hooks/features/editing/index.js +7 -11
  158. package/node/hooks/features/editing/useGridCellEditing.js +2 -2
  159. package/node/hooks/features/editing/useGridRowEditing.js +6 -7
  160. package/node/hooks/features/filter/gridFilterState.js +6 -1
  161. package/node/hooks/features/filter/useGridFilter.js +5 -12
  162. package/node/hooks/features/focus/useGridFocus.js +3 -2
  163. package/node/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +24 -15
  164. package/node/hooks/features/keyboardNavigation/utils.js +0 -6
  165. package/node/hooks/features/listView/useGridListView.js +2 -1
  166. package/node/hooks/features/pagination/useGridPagination.js +1 -1
  167. package/node/hooks/features/rowSelection/useGridRowSelection.js +3 -3
  168. package/node/hooks/features/rowSelection/utils.js +1 -1
  169. package/node/hooks/features/rows/gridRowsUtils.js +0 -17
  170. package/node/hooks/features/rows/useGridParamsApi.js +33 -14
  171. package/node/hooks/features/rows/useGridRowSpanning.js +92 -89
  172. package/node/hooks/features/rows/useGridRows.js +7 -8
  173. package/node/hooks/features/rows/useGridRowsMeta.js +36 -19
  174. package/node/hooks/features/sorting/gridSortingSelector.js +10 -9
  175. package/node/hooks/features/virtualization/gridFocusedVirtualCellSelector.js +2 -2
  176. package/node/hooks/features/virtualization/useGridVirtualScroller.js +73 -71
  177. package/node/hooks/utils/useGridSelector.js +42 -8
  178. package/node/hooks/utils/useIsSSR.js +12 -0
  179. package/node/index.js +1 -1
  180. package/node/internals/index.js +20 -7
  181. package/node/models/api/index.js +0 -11
  182. package/node/utils/roundToDecimalPlaces.js +9 -0
  183. package/node/utils/utils.js +8 -1
  184. package/package.json +3 -2
  185. package/utils/roundToDecimalPlaces.d.ts +1 -0
  186. package/utils/roundToDecimalPlaces.js +3 -0
  187. package/utils/utils.d.ts +1 -0
  188. package/utils/utils.js +6 -1
@@ -6,7 +6,6 @@ import { gridVisibleColumnDefinitionsSelector, gridVisibleColumnFieldsSelector }
6
6
  import { useGridLogger } from "../../utils/useGridLogger.js";
7
7
  import { useGridApiEventHandler } from "../../utils/useGridApiEventHandler.js";
8
8
  import { gridExpandedSortedRowEntriesSelector } from "../filter/gridFilterSelector.js";
9
- import { useGridVisibleRows } from "../../utils/useGridVisibleRows.js";
10
9
  import { GRID_CHECKBOX_SELECTION_COL_DEF } from "../../../colDef/gridCheckboxSelectionColDef.js";
11
10
  import { gridClasses } from "../../../constants/gridClasses.js";
12
11
  import { GridCellModes } from "../../../models/gridEditRowModel.js";
@@ -16,8 +15,14 @@ import { gridColumnGroupsHeaderMaxDepthSelector } from "../columnGrouping/gridCo
16
15
  import { gridHeaderFilteringEditFieldSelector, gridHeaderFilteringMenuSelector } from "../headerFiltering/gridHeaderFilteringSelectors.js";
17
16
  import { useGridRegisterPipeProcessor } from "../../core/pipeProcessing/index.js";
18
17
  import { isEventTargetInPortal } from "../../../utils/domUtils.js";
19
- import { enrichPageRowsWithPinnedRows, getLeftColumnIndex, getRightColumnIndex, findNonRowSpannedCell } from "./utils.js";
18
+ import { getLeftColumnIndex, getRightColumnIndex, findNonRowSpannedCell } from "./utils.js";
20
19
  import { gridListColumnSelector } from "../listView/gridListViewSelectors.js";
20
+ import { createSelectorMemoized } from "../../../utils/createSelector.js";
21
+ import { gridVisibleRowsSelector } from "../pagination/index.js";
22
+ import { gridPinnedRowsSelector } from "../rows/gridRowsSelector.js";
23
+ const gridVisibleRowsWithPinnedRowsSelector = createSelectorMemoized(gridVisibleRowsSelector, gridPinnedRowsSelector, (visibleRows, pinnedRows) => {
24
+ return (pinnedRows.top || []).concat(visibleRows.rows, pinnedRows.bottom || []);
25
+ });
21
26
 
22
27
  /**
23
28
  * @requires useGridSorting (method) - can be after
@@ -30,10 +35,11 @@ import { gridListColumnSelector } from "../listView/gridListViewSelectors.js";
30
35
  */
31
36
  export const useGridKeyboardNavigation = (apiRef, props) => {
32
37
  const logger = useGridLogger(apiRef, 'useGridKeyboardNavigation');
33
- const initialCurrentPageRows = useGridVisibleRows(apiRef, props).rows;
34
38
  const isRtl = useRtl();
35
39
  const listView = props.unstable_listView;
36
- const currentPageRows = React.useMemo(() => enrichPageRowsWithPinnedRows(apiRef, initialCurrentPageRows), [apiRef, initialCurrentPageRows]);
40
+ const getCurrentPageRows = React.useCallback(() => {
41
+ return gridVisibleRowsWithPinnedRowsSelector(apiRef);
42
+ }, [apiRef]);
37
43
  const headerFilteringEnabled = props.signature !== 'DataGrid' && props.headerFilters;
38
44
 
39
45
  /**
@@ -92,8 +98,8 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
92
98
  apiRef.current.setColumnGroupHeaderFocus(field, depth, event);
93
99
  }, [apiRef, logger]);
94
100
  const getRowIdFromIndex = React.useCallback(rowIndex => {
95
- return currentPageRows[rowIndex]?.id;
96
- }, [currentPageRows]);
101
+ return getCurrentPageRows()[rowIndex]?.id;
102
+ }, [getCurrentPageRows]);
97
103
  const handleColumnHeaderKeyDown = React.useCallback((params, event) => {
98
104
  const headerTitleNode = event.currentTarget.querySelector(`.${gridClasses.columnHeaderTitleContainerContent}`);
99
105
  const isFromInsideContent = !!headerTitleNode && headerTitleNode.contains(event.target);
@@ -102,6 +108,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
102
108
  // There is one exception for the checkBoxHeader
103
109
  return;
104
110
  }
111
+ const currentPageRows = getCurrentPageRows();
105
112
  const viewportPageSize = apiRef.current.getViewportPageSize();
106
113
  const colIndexBefore = params.field ? apiRef.current.getColumnIndex(params.field) : 0;
107
114
  const firstRowIndexInPage = currentPageRows.length > 0 ? 0 : null;
@@ -113,12 +120,10 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
113
120
  switch (event.key) {
114
121
  case 'ArrowDown':
115
122
  {
116
- if (firstRowIndexInPage !== null) {
117
- if (headerFilteringEnabled) {
118
- goToHeaderFilter(colIndexBefore, event);
119
- } else {
120
- goToCell(colIndexBefore, getRowIdFromIndex(firstRowIndexInPage));
121
- }
123
+ if (headerFilteringEnabled) {
124
+ goToHeaderFilter(colIndexBefore, event);
125
+ } else if (firstRowIndexInPage !== null) {
126
+ goToCell(colIndexBefore, getRowIdFromIndex(firstRowIndexInPage));
122
127
  }
123
128
  break;
124
129
  }
@@ -192,13 +197,14 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
192
197
  if (shouldPreventDefault) {
193
198
  event.preventDefault();
194
199
  }
195
- }, [apiRef, currentPageRows.length, headerFilteringEnabled, goToHeaderFilter, goToCell, getRowIdFromIndex, isRtl, goToHeader, goToGroupHeader]);
200
+ }, [apiRef, getCurrentPageRows, headerFilteringEnabled, goToHeaderFilter, goToCell, getRowIdFromIndex, isRtl, goToHeader, goToGroupHeader]);
196
201
  const handleHeaderFilterKeyDown = React.useCallback((params, event) => {
197
202
  const isEditing = gridHeaderFilteringEditFieldSelector(apiRef) === params.field;
198
203
  const isHeaderMenuOpen = gridHeaderFilteringMenuSelector(apiRef) === params.field;
199
204
  if (isEditing || isHeaderMenuOpen || !isNavigationKey(event.key)) {
200
205
  return;
201
206
  }
207
+ const currentPageRows = getCurrentPageRows();
202
208
  const viewportPageSize = apiRef.current.getViewportPageSize();
203
209
  const colIndexBefore = params.field ? apiRef.current.getColumnIndex(params.field) : 0;
204
210
  const firstRowIndexInPage = 0;
@@ -278,7 +284,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
278
284
  if (shouldPreventDefault) {
279
285
  event.preventDefault();
280
286
  }
281
- }, [apiRef, currentPageRows.length, goToHeaderFilter, isRtl, goToHeader, goToCell, getRowIdFromIndex]);
287
+ }, [apiRef, getCurrentPageRows, goToHeaderFilter, isRtl, goToHeader, goToCell, getRowIdFromIndex]);
282
288
  const handleColumnGroupHeaderKeyDown = React.useCallback((params, event) => {
283
289
  const focusedColumnGroup = gridFocusColumnGroupHeaderSelector(apiRef);
284
290
  if (focusedColumnGroup === null) {
@@ -293,6 +299,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
293
299
  depth,
294
300
  maxDepth
295
301
  } = params;
302
+ const currentPageRows = getCurrentPageRows();
296
303
  const viewportPageSize = apiRef.current.getViewportPageSize();
297
304
  const currentColIndex = apiRef.current.getColumnIndex(currentField);
298
305
  const colIndexBefore = currentField ? apiRef.current.getColumnIndex(currentField) : 0;
@@ -364,7 +371,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
364
371
  if (shouldPreventDefault) {
365
372
  event.preventDefault();
366
373
  }
367
- }, [apiRef, currentPageRows.length, goToHeader, goToGroupHeader, goToCell, getRowIdFromIndex]);
374
+ }, [apiRef, getCurrentPageRows, goToHeader, goToGroupHeader, goToCell, getRowIdFromIndex]);
368
375
  const handleCellKeyDown = React.useCallback((params, event) => {
369
376
  // Ignore portal
370
377
  if (isEventTargetInPortal(event)) {
@@ -383,6 +390,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
383
390
  if (!canUpdateFocus) {
384
391
  return;
385
392
  }
393
+ const currentPageRows = getCurrentPageRows();
386
394
  if (currentPageRows.length === 0) {
387
395
  return;
388
396
  }
@@ -511,7 +519,7 @@ export const useGridKeyboardNavigation = (apiRef, props) => {
511
519
  if (shouldPreventDefault) {
512
520
  event.preventDefault();
513
521
  }
514
- }, [apiRef, currentPageRows, isRtl, goToCell, getRowIdFromIndex, headerFilteringEnabled, goToHeaderFilter, goToHeader, listView]);
522
+ }, [apiRef, getCurrentPageRows, isRtl, goToCell, getRowIdFromIndex, headerFilteringEnabled, goToHeaderFilter, goToHeader, listView]);
515
523
  const checkIfCanStartEditing = React.useCallback((initialValue, {
516
524
  event
517
525
  }) => {
@@ -1,10 +1,5 @@
1
1
  import { gridFilteredSortedRowIdsSelector } from "../filter/gridFilterSelector.js";
2
2
  import { gridRowSpanningHiddenCellsSelector } from "../rows/gridRowSpanningSelectors.js";
3
- import { gridPinnedRowsSelector } from "../rows/gridRowsSelector.js";
4
- export function enrichPageRowsWithPinnedRows(apiRef, rows) {
5
- const pinnedRows = gridPinnedRowsSelector(apiRef) || {};
6
- return [...(pinnedRows.top || []), ...rows, ...(pinnedRows.bottom || [])];
7
- }
8
3
  export const getLeftColumnIndex = ({
9
4
  currentColIndex,
10
5
  firstColIndex,
@@ -1,5 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import * as React from 'react';
3
+ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
3
4
  import { warnOnce } from '@mui/x-internals/warning';
4
5
  import { gridDimensionsSelector } from "../dimensions/index.js";
5
6
  import { useGridApiEventHandler } from "../../utils/useGridApiEventHandler.js";
@@ -37,7 +38,7 @@ export function useGridListView(apiRef, props) {
37
38
  /*
38
39
  * EFFECTS
39
40
  */
40
- React.useEffect(() => {
41
+ useEnhancedEffect(() => {
41
42
  const listColumn = props.unstable_listColumn;
42
43
  if (listColumn) {
43
44
  apiRef.current.setState(state => {
@@ -6,7 +6,7 @@ import { useGridPaginationMeta } from "./useGridPaginationMeta.js";
6
6
  export const paginationStateInitializer = (state, props) => {
7
7
  const paginationModel = _extends({}, getDefaultGridPaginationModel(props.autoPageSize), props.paginationModel ?? props.initialState?.pagination?.paginationModel);
8
8
  throwIfPageSizeExceedsTheLimit(paginationModel.pageSize, props.signature);
9
- const rowCount = props.rowCount ?? props.initialState?.pagination?.rowCount;
9
+ const rowCount = props.rowCount ?? props.initialState?.pagination?.rowCount ?? (props.paginationMode === 'client' ? state.rows?.totalRowCount : undefined);
10
10
  const meta = props.paginationMeta ?? props.initialState?.pagination?.meta ?? {};
11
11
  return _extends({}, state, {
12
12
  pagination: _extends({}, state.pagination, {
@@ -12,7 +12,7 @@ import { gridExpandedSortedRowIdsSelector, gridFilteredRowsLookupSelector } from
12
12
  import { GRID_CHECKBOX_SELECTION_COL_DEF, GRID_ACTIONS_COLUMN_TYPE } from "../../../colDef/index.js";
13
13
  import { GridCellModes } from "../../../models/gridEditRowModel.js";
14
14
  import { isKeyboardEvent, isNavigationKey } from "../../../utils/keyboardUtils.js";
15
- import { useGridVisibleRows } from "../../utils/useGridVisibleRows.js";
15
+ import { getVisibleRows } from "../../utils/useGridVisibleRows.js";
16
16
  import { GRID_DETAIL_PANEL_TOGGLE_FIELD } from "../../../internals/constants.js";
17
17
  import { gridClasses } from "../../../constants/gridClasses.js";
18
18
  import { isEventTargetInPortal } from "../../../utils/domUtils.js";
@@ -64,7 +64,6 @@ export const useGridRowSelection = (apiRef, props) => {
64
64
  isRowSelectable: propIsRowSelectable
65
65
  } = props;
66
66
  const canHaveMultipleSelection = isMultipleRowSelectionEnabled(props);
67
- const visibleRows = useGridVisibleRows(apiRef, props);
68
67
  const tree = useGridSelector(apiRef, gridRowTreeSelector);
69
68
  const isNestedData = useGridSelector(apiRef, gridRowMaximumTreeDepthSelector) > 1;
70
69
  const expandMouseRowRangeSelection = React.useCallback(id => {
@@ -259,7 +258,7 @@ export const useGridRowSelection = (apiRef, props) => {
259
258
  if (props.filterMode === 'server') {
260
259
  return !rowsLookup[id];
261
260
  }
262
- return filteredRowsLookup[id] !== true;
261
+ return !rowsLookup[id] || filteredRowsLookup[id] === false;
263
262
  };
264
263
  let hasChanged = false;
265
264
  currentSelection.forEach(id => {
@@ -412,6 +411,7 @@ export const useGridRowSelection = (apiRef, props) => {
412
411
  end = previousRowIndex;
413
412
  }
414
413
  }
414
+ const visibleRows = getVisibleRows(apiRef);
415
415
  const rowsBetweenStartAndEnd = visibleRows.rows.slice(start, end + 1).map(row => row.id);
416
416
  apiRef.current.selectRows(rowsBetweenStartAndEnd, !isNextRowSelected);
417
417
  return;
@@ -426,7 +426,7 @@ export const useGridRowSelection = (apiRef, props) => {
426
426
  event.preventDefault();
427
427
  selectRows(apiRef.current.getAllRowIds(), true);
428
428
  }
429
- }, [apiRef, handleSingleRowSelection, selectRows, visibleRows.rows, canHaveMultipleSelection]);
429
+ }, [apiRef, handleSingleRowSelection, selectRows, canHaveMultipleSelection]);
430
430
  useGridApiEventHandler(apiRef, 'sortedRowsSet', runIfRowSelectionIsEnabled(() => removeOutdatedSelection(true)));
431
431
  useGridApiEventHandler(apiRef, 'filteredRowsSet', runIfRowSelectionIsEnabled(removeOutdatedSelection));
432
432
  useGridApiEventHandler(apiRef, 'rowClick', runIfRowSelectionIsEnabled(handleRowClick));
@@ -92,7 +92,7 @@ const getFilteredRowNodeSiblings = (tree, filteredRows, id) => {
92
92
  return [];
93
93
  }
94
94
  const parentNode = tree[parent];
95
- return parentNode.children.filter(childId => childId !== id && filteredRows[childId]);
95
+ return parentNode.children.filter(childId => childId !== id && filteredRows[childId] !== false);
96
96
  };
97
97
  export const findRowsToSelect = (apiRef, tree, selectedRow, autoSelectDescendants, autoSelectParents, addRow) => {
98
98
  const filteredRows = gridFilteredRowsLookupSelector(apiRef);
@@ -1,5 +1,4 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
- import { gridPinnedRowsSelector } from "./gridRowsSelector.js";
3
2
  export const GRID_ROOT_GROUP_ID = `auto-generated-group-node-root`;
4
3
  export const GRID_ID_AUTOGENERATED = Symbol('mui.id_autogenerated');
5
4
  export const buildRootGroup = () => ({
@@ -269,21 +268,6 @@ export const updateCacheWithNewRows = ({
269
268
  rowCountPropBeforePartialUpdates: previousCache.rowCountPropBeforePartialUpdates
270
269
  };
271
270
  };
272
- export function calculatePinnedRowsHeight(apiRef) {
273
- const pinnedRows = gridPinnedRowsSelector(apiRef);
274
- const topPinnedRowsHeight = pinnedRows?.top?.reduce((acc, value) => {
275
- acc += apiRef.current.unstable_getRowHeight(value.id);
276
- return acc;
277
- }, 0) || 0;
278
- const bottomPinnedRowsHeight = pinnedRows?.bottom?.reduce((acc, value) => {
279
- acc += apiRef.current.unstable_getRowHeight(value.id);
280
- return acc;
281
- }, 0) || 0;
282
- return {
283
- top: topPinnedRowsHeight,
284
- bottom: bottomPinnedRowsHeight
285
- };
286
- }
287
271
  export const minimalContentHeight = 'var(--DataGrid-overlayHeight, calc(var(--height) * 2))';
288
272
  export function computeRowsUpdates(apiRef, updates, getRowId) {
289
273
  const nonPinnedRowsUpdates = [];
@@ -30,37 +30,52 @@ export function useGridParamsApi(apiRef, props) {
30
30
  };
31
31
  return params;
32
32
  }, [apiRef]);
33
- const getCellParams = React.useCallback((id, field) => {
34
- const colDef = props.unstable_listView ? gridListColumnSelector(apiRef.current.state) : apiRef.current.getColumn(field);
35
- const row = apiRef.current.getRow(id);
36
- const rowNode = apiRef.current.getRowNode(id);
37
- if (!row || !rowNode) {
38
- throw new MissingRowIdError(`No row with id #${id} found`);
39
- }
33
+ const getCellParamsForRow = React.useCallback((id, field, row, {
34
+ cellMode,
35
+ colDef,
36
+ hasFocus,
37
+ rowNode,
38
+ tabIndex
39
+ }) => {
40
40
  const rawValue = row[field];
41
41
  const value = colDef?.valueGetter ? colDef.valueGetter(rawValue, row, colDef, apiRef) : rawValue;
42
- const cellFocus = gridFocusCellSelector(apiRef);
43
- const cellTabIndex = gridTabIndexCellSelector(apiRef);
44
42
  const params = {
45
43
  id,
46
44
  field,
47
45
  row,
48
46
  rowNode,
49
47
  colDef,
50
- cellMode: apiRef.current.getCellMode(id, field),
51
- hasFocus: cellFocus !== null && cellFocus.field === field && cellFocus.id === id,
52
- tabIndex: cellTabIndex && cellTabIndex.field === field && cellTabIndex.id === id ? 0 : -1,
48
+ cellMode,
49
+ hasFocus,
50
+ tabIndex,
53
51
  value,
54
52
  formattedValue: value,
55
53
  isEditable: false,
56
- api: {}
54
+ api: null
57
55
  };
58
56
  if (colDef && colDef.valueFormatter) {
59
57
  params.formattedValue = colDef.valueFormatter(value, row, colDef, apiRef);
60
58
  }
61
59
  params.isEditable = colDef && apiRef.current.isCellEditable(params);
62
60
  return params;
63
- }, [apiRef, props.unstable_listView]);
61
+ }, [apiRef]);
62
+ const getCellParams = React.useCallback((id, field) => {
63
+ const row = apiRef.current.getRow(id);
64
+ const rowNode = apiRef.current.getRowNode(id);
65
+ if (!row || !rowNode) {
66
+ throw new MissingRowIdError(`No row with id #${id} found`);
67
+ }
68
+ const cellFocus = gridFocusCellSelector(apiRef);
69
+ const cellTabIndex = gridTabIndexCellSelector(apiRef);
70
+ const cellMode = apiRef.current.getCellMode(id, field);
71
+ return apiRef.current.getCellParamsForRow(id, field, row, {
72
+ colDef: props.unstable_listView && props.unstable_listColumn?.field === field ? gridListColumnSelector(apiRef.current.state) : apiRef.current.getColumn(field),
73
+ rowNode,
74
+ hasFocus: cellFocus !== null && cellFocus.field === field && cellFocus.id === id,
75
+ tabIndex: cellTabIndex && cellTabIndex.field === field && cellTabIndex.id === id ? 0 : -1,
76
+ cellMode
77
+ });
78
+ }, [apiRef, props.unstable_listView, props.unstable_listColumn?.field]);
64
79
  const getCellValue = React.useCallback((id, field) => {
65
80
  const colDef = apiRef.current.getColumn(field);
66
81
  const row = apiRef.current.getRow(id);
@@ -119,5 +134,9 @@ export function useGridParamsApi(apiRef, props) {
119
134
  getColumnHeaderParams,
120
135
  getColumnHeaderElement
121
136
  };
137
+ const paramsPrivateApi = {
138
+ getCellParamsForRow
139
+ };
122
140
  useGridApiMethod(apiRef, paramsApi, 'public');
141
+ useGridApiMethod(apiRef, paramsPrivateApi, 'private');
123
142
  }
@@ -3,12 +3,14 @@ import * as React from 'react';
3
3
  import useLazyRef from '@mui/utils/useLazyRef';
4
4
  import { GRID_DETAIL_PANEL_TOGGLE_FIELD } from "../../../internals/constants.js";
5
5
  import { gridVisibleColumnDefinitionsSelector } from "../columns/gridColumnsSelector.js";
6
- import { useGridVisibleRows } from "../../utils/useGridVisibleRows.js";
6
+ import { getVisibleRows } from "../../utils/useGridVisibleRows.js";
7
7
  import { gridRenderContextSelector } from "../virtualization/gridVirtualizationSelectors.js";
8
- import { useGridSelector } from "../../utils/useGridSelector.js";
9
- import { gridRowTreeSelector } from "./gridRowsSelector.js";
10
- import { getUnprocessedRange, isRowRangeUpdated, isRowContextInitialized, getCellValue } from "./gridRowSpanningUtils.js";
8
+ import { getUnprocessedRange, isRowContextInitialized, getCellValue } from "./gridRowSpanningUtils.js";
11
9
  import { GRID_CHECKBOX_SELECTION_FIELD } from "../../../colDef/gridCheckboxSelectionColDef.js";
10
+ import { useGridApiEventHandler } from "../../utils/useGridApiEventHandler.js";
11
+ import { runIf } from "../../../utils/utils.js";
12
+ import { gridPageSizeSelector } from "../pagination/index.js";
13
+ import { gridDataRowIdsSelector } from "./gridRowsSelector.js";
12
14
  const EMPTY_STATE = {
13
15
  spannedCells: {},
14
16
  hiddenCells: {},
@@ -53,8 +55,8 @@ const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToPro
53
55
  const backwardsHiddenCells = [];
54
56
  if (index === rangeToProcess.firstRowIndex) {
55
57
  let prevIndex = index - 1;
56
- const prevRowEntry = visibleRows[prevIndex];
57
- while (prevIndex >= range.firstRowIndex && getCellValue(prevRowEntry.model, colDef, apiRef) === cellValue) {
58
+ let prevRowEntry = visibleRows[prevIndex];
59
+ while (prevIndex >= range.firstRowIndex && prevRowEntry && getCellValue(prevRowEntry.model, colDef, apiRef) === cellValue) {
58
60
  const currentRow = visibleRows[prevIndex + 1];
59
61
  if (hiddenCells[currentRow.id]) {
60
62
  hiddenCells[currentRow.id][colDef.field] = true;
@@ -68,6 +70,7 @@ const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToPro
68
70
  spannedRowId = prevRowEntry.id;
69
71
  spannedRowIndex = prevIndex;
70
72
  prevIndex -= 1;
73
+ prevRowEntry = visibleRows[prevIndex];
71
74
  }
72
75
  }
73
76
  backwardsHiddenCells.forEach(hiddenCellIndex => {
@@ -123,6 +126,24 @@ const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToPro
123
126
  processedRange
124
127
  };
125
128
  };
129
+ const getInitialRangeToProcess = (props, apiRef) => {
130
+ const rowCount = gridDataRowIdsSelector(apiRef).length;
131
+ if (props.pagination) {
132
+ const pageSize = gridPageSizeSelector(apiRef);
133
+ let paginationLastRowIndex = DEFAULT_ROWS_TO_PROCESS;
134
+ if (pageSize > 0) {
135
+ paginationLastRowIndex = pageSize - 1;
136
+ }
137
+ return {
138
+ firstRowIndex: 0,
139
+ lastRowIndex: Math.min(paginationLastRowIndex, rowCount)
140
+ };
141
+ }
142
+ return {
143
+ firstRowIndex: 0,
144
+ lastRowIndex: Math.min(DEFAULT_ROWS_TO_PROCESS, rowCount)
145
+ };
146
+ };
126
147
 
127
148
  /**
128
149
  * @requires columnsStateInitializer (method) - should be initialized before
@@ -130,74 +151,52 @@ const computeRowSpanningState = (apiRef, colDefs, visibleRows, range, rangeToPro
130
151
  * @requires filterStateInitializer (method) - should be initialized before
131
152
  */
132
153
  export const rowSpanningStateInitializer = (state, props, apiRef) => {
133
- if (props.unstable_rowSpanning) {
134
- const rowIds = state.rows.dataRowIds || [];
135
- const orderedFields = state.columns.orderedFields || [];
136
- const dataRowIdToModelLookup = state.rows.dataRowIdToModelLookup;
137
- const columnsLookup = state.columns.lookup;
138
- const isFilteringPending = Boolean(state.filter.filterModel.items.length) || Boolean(state.filter.filterModel.quickFilterValues?.length);
139
- if (!rowIds.length || !orderedFields.length || !dataRowIdToModelLookup || !columnsLookup || isFilteringPending) {
140
- return _extends({}, state, {
141
- rowSpanning: EMPTY_STATE
142
- });
143
- }
144
- const rangeToProcess = {
145
- firstRowIndex: 0,
146
- lastRowIndex: Math.min(DEFAULT_ROWS_TO_PROCESS, Math.max(rowIds.length, 0))
147
- };
148
- const rows = rowIds.map(id => ({
149
- id,
150
- model: dataRowIdToModelLookup[id]
151
- }));
152
- const colDefs = orderedFields.map(field => columnsLookup[field]);
153
- const {
154
- spannedCells,
155
- hiddenCells,
156
- hiddenCellOriginMap
157
- } = computeRowSpanningState(apiRef, colDefs, rows, rangeToProcess, rangeToProcess, true, EMPTY_RANGE);
154
+ if (!props.unstable_rowSpanning) {
158
155
  return _extends({}, state, {
159
- rowSpanning: {
160
- spannedCells,
161
- hiddenCells,
162
- hiddenCellOriginMap
163
- }
156
+ rowSpanning: EMPTY_STATE
157
+ });
158
+ }
159
+ const rowIds = state.rows.dataRowIds || [];
160
+ const orderedFields = state.columns.orderedFields || [];
161
+ const dataRowIdToModelLookup = state.rows.dataRowIdToModelLookup;
162
+ const columnsLookup = state.columns.lookup;
163
+ const isFilteringPending = Boolean(state.filter.filterModel.items.length) || Boolean(state.filter.filterModel.quickFilterValues?.length);
164
+ if (!rowIds.length || !orderedFields.length || !dataRowIdToModelLookup || !columnsLookup || isFilteringPending) {
165
+ return _extends({}, state, {
166
+ rowSpanning: EMPTY_STATE
164
167
  });
165
168
  }
169
+ const rangeToProcess = getInitialRangeToProcess(props, apiRef);
170
+ const rows = rowIds.map(id => ({
171
+ id,
172
+ model: dataRowIdToModelLookup[id]
173
+ }));
174
+ const colDefs = orderedFields.map(field => columnsLookup[field]);
175
+ const {
176
+ spannedCells,
177
+ hiddenCells,
178
+ hiddenCellOriginMap
179
+ } = computeRowSpanningState(apiRef, colDefs, rows, rangeToProcess, rangeToProcess, true, EMPTY_RANGE);
166
180
  return _extends({}, state, {
167
- rowSpanning: EMPTY_STATE
181
+ rowSpanning: {
182
+ spannedCells,
183
+ hiddenCells,
184
+ hiddenCellOriginMap
185
+ }
168
186
  });
169
187
  };
170
188
  export const useGridRowSpanning = (apiRef, props) => {
171
- const {
172
- range,
173
- rows: visibleRows
174
- } = useGridVisibleRows(apiRef, props);
175
- const renderContext = useGridSelector(apiRef, gridRenderContextSelector);
176
- const colDefs = useGridSelector(apiRef, gridVisibleColumnDefinitionsSelector);
177
- const tree = useGridSelector(apiRef, gridRowTreeSelector);
178
189
  const processedRange = useLazyRef(() => {
179
- return Object.keys(apiRef.current.state.rowSpanning.spannedCells).length > 0 ? {
180
- firstRowIndex: 0,
181
- lastRowIndex: Math.min(DEFAULT_ROWS_TO_PROCESS, Math.max(apiRef.current.state.rows.dataRowIds.length, 0))
182
- } : EMPTY_RANGE;
190
+ return apiRef.current.state.rowSpanning !== EMPTY_STATE ? getInitialRangeToProcess(props, apiRef) : EMPTY_RANGE;
183
191
  });
184
- const lastRange = React.useRef(EMPTY_RANGE);
185
- const updateRowSpanningState = React.useCallback(
186
- // A reset needs to occur when:
187
- // - The `unstable_rowSpanning` prop is updated (feature flag)
188
- // - The filtering is applied
189
- // - The sorting is applied
190
- // - The `paginationModel` is updated
191
- // - The rows are updated
192
- (resetState = true) => {
193
- if (!props.unstable_rowSpanning) {
194
- if (apiRef.current.state.rowSpanning !== EMPTY_STATE) {
195
- apiRef.current.setState(state => _extends({}, state, {
196
- rowSpanning: EMPTY_STATE
197
- }));
198
- }
199
- return;
200
- }
192
+ const updateRowSpanningState = React.useCallback((renderContext, resetState = false) => {
193
+ const {
194
+ range,
195
+ rows: visibleRows
196
+ } = getVisibleRows(apiRef, {
197
+ pagination: props.pagination,
198
+ paginationMode: props.paginationMode
199
+ });
201
200
  if (range === null || !isRowContextInitialized(renderContext)) {
202
201
  return;
203
202
  }
@@ -211,6 +210,7 @@ export const useGridRowSpanning = (apiRef, props) => {
211
210
  if (rangeToProcess === null) {
212
211
  return;
213
212
  }
213
+ const colDefs = gridVisibleColumnDefinitionsSelector(apiRef);
214
214
  const {
215
215
  spannedCells,
216
216
  hiddenCells,
@@ -223,7 +223,8 @@ export const useGridRowSpanning = (apiRef, props) => {
223
223
  const currentSpannedCellsCount = Object.keys(apiRef.current.state.rowSpanning.spannedCells).length;
224
224
  const currentHiddenCellsCount = Object.keys(apiRef.current.state.rowSpanning.hiddenCells).length;
225
225
  const shouldUpdateState = resetState || newSpannedCellsCount !== currentSpannedCellsCount || newHiddenCellsCount !== currentHiddenCellsCount;
226
- if (!shouldUpdateState) {
226
+ const hasNoSpannedCells = newSpannedCellsCount === 0 && currentSpannedCellsCount === 0;
227
+ if (!shouldUpdateState || hasNoSpannedCells) {
227
228
  return;
228
229
  }
229
230
  apiRef.current.setState(state => {
@@ -235,33 +236,35 @@ export const useGridRowSpanning = (apiRef, props) => {
235
236
  }
236
237
  });
237
238
  });
238
- }, [apiRef, props.unstable_rowSpanning, range, renderContext, visibleRows, colDefs, processedRange]);
239
- const prevRenderContext = React.useRef(renderContext);
240
- const isFirstRender = React.useRef(true);
241
- const shouldResetState = React.useRef(false);
242
- const previousTree = React.useRef(tree);
243
- React.useEffect(() => {
244
- const firstRender = isFirstRender.current;
245
- if (isFirstRender.current) {
246
- isFirstRender.current = false;
247
- }
248
- if (tree !== previousTree.current) {
249
- previousTree.current = tree;
250
- updateRowSpanningState(true);
239
+ }, [apiRef, processedRange, props.pagination, props.paginationMode]);
240
+
241
+ // Reset events trigger a full re-computation of the row spanning state:
242
+ // - The `unstable_rowSpanning` prop is updated (feature flag)
243
+ // - The filtering is applied
244
+ // - The sorting is applied
245
+ // - The `paginationModel` is updated
246
+ // - The rows are updated
247
+ const resetRowSpanningState = React.useCallback(() => {
248
+ const renderContext = gridRenderContextSelector(apiRef);
249
+ if (!isRowContextInitialized(renderContext)) {
251
250
  return;
252
251
  }
253
- if (range && lastRange.current && isRowRangeUpdated(range, lastRange.current)) {
254
- lastRange.current = range;
255
- shouldResetState.current = true;
256
- }
257
- if (!firstRender && prevRenderContext.current !== renderContext) {
258
- if (isRowRangeUpdated(prevRenderContext.current, renderContext)) {
259
- updateRowSpanningState(shouldResetState.current);
260
- shouldResetState.current = false;
252
+ updateRowSpanningState(renderContext, true);
253
+ }, [apiRef, updateRowSpanningState]);
254
+ useGridApiEventHandler(apiRef, 'renderedRowsIntervalChange', runIf(props.unstable_rowSpanning, updateRowSpanningState));
255
+ useGridApiEventHandler(apiRef, 'sortedRowsSet', runIf(props.unstable_rowSpanning, resetRowSpanningState));
256
+ useGridApiEventHandler(apiRef, 'paginationModelChange', runIf(props.unstable_rowSpanning, resetRowSpanningState));
257
+ useGridApiEventHandler(apiRef, 'filteredRowsSet', runIf(props.unstable_rowSpanning, resetRowSpanningState));
258
+ useGridApiEventHandler(apiRef, 'columnsChange', runIf(props.unstable_rowSpanning, resetRowSpanningState));
259
+ React.useEffect(() => {
260
+ if (!props.unstable_rowSpanning) {
261
+ if (apiRef.current.state.rowSpanning !== EMPTY_STATE) {
262
+ apiRef.current.setState(state => _extends({}, state, {
263
+ rowSpanning: EMPTY_STATE
264
+ }));
261
265
  }
262
- prevRenderContext.current = renderContext;
263
- return;
266
+ } else if (apiRef.current.state.rowSpanning === EMPTY_STATE) {
267
+ resetRowSpanningState();
264
268
  }
265
- updateRowSpanningState();
266
- }, [updateRowSpanningState, renderContext, range, lastRange, tree]);
269
+ }, [apiRef, resetRowSpanningState, props.unstable_rowSpanning]);
267
270
  };
@@ -39,7 +39,6 @@ export const useGridRows = (apiRef, props) => {
39
39
  }
40
40
  }
41
41
  const logger = useGridLogger(apiRef, 'useGridRows');
42
- const currentPage = getVisibleRows(apiRef);
43
42
  const lastUpdateMs = React.useRef(Date.now());
44
43
  const lastRowCount = React.useRef(props.rowCount);
45
44
  const timeout = useTimeout();
@@ -66,12 +65,6 @@ export const useGridRows = (apiRef, props) => {
66
65
  }
67
66
  return row.id;
68
67
  }, [getRowIdProp]);
69
- const lookup = React.useMemo(() => currentPage.rows.reduce((acc, {
70
- id
71
- }, index) => {
72
- acc[id] = index;
73
- return acc;
74
- }, {}), [currentPage.rows]);
75
68
  const throttledRowsChange = React.useCallback(({
76
69
  cache,
77
70
  throttle
@@ -170,7 +163,13 @@ export const useGridRows = (apiRef, props) => {
170
163
  }, [apiRef]);
171
164
  const getRowsCount = React.useCallback(() => gridRowCountSelector(apiRef), [apiRef]);
172
165
  const getAllRowIds = React.useCallback(() => gridDataRowIdsSelector(apiRef), [apiRef]);
173
- const getRowIndexRelativeToVisibleRows = React.useCallback(id => lookup[id], [lookup]);
166
+ const getRowIndexRelativeToVisibleRows = React.useCallback(id => {
167
+ const row = apiRef.current.getRow(id);
168
+ const {
169
+ rowToIndexMap
170
+ } = getVisibleRows(apiRef);
171
+ return rowToIndexMap.get(row);
172
+ }, [apiRef]);
174
173
  const setRowChildrenExpansion = React.useCallback((id, isExpanded) => {
175
174
  const currentNode = apiRef.current.getRowNode(id);
176
175
  if (!currentNode) {