@mui/x-data-grid 8.9.1 → 8.9.2
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 +96 -2
- package/DataGrid/DataGrid.js +5 -0
- package/DataGrid/useDataGridComponent.js +2 -0
- package/colDef/gridCheckboxSelectionColDef.js +1 -0
- package/components/GridDetailPanels.d.ts +2 -2
- package/components/GridPinnedRows.d.ts +2 -2
- package/components/GridRow.js +5 -0
- package/components/cell/GridCell.js +7 -5
- package/components/cell/GridEditSingleSelectCell.js +1 -1
- package/components/columnsManagement/GridColumnsManagement.d.ts +6 -0
- package/components/columnsManagement/GridColumnsManagement.js +17 -5
- package/components/containers/GridRootStyles.d.ts +1 -1
- package/components/toolbarV8/Toolbar.d.ts +1 -1
- package/components/virtualization/GridVirtualScroller.js +5 -5
- package/constants/dataGridPropsDefaultValues.js +1 -0
- package/esm/DataGrid/DataGrid.js +5 -0
- package/esm/DataGrid/useDataGridComponent.js +2 -0
- package/esm/colDef/gridCheckboxSelectionColDef.js +1 -0
- package/esm/components/GridDetailPanels.d.ts +2 -2
- package/esm/components/GridPinnedRows.d.ts +2 -2
- package/esm/components/GridRow.js +5 -0
- package/esm/components/cell/GridCell.js +7 -5
- package/esm/components/cell/GridEditSingleSelectCell.js +1 -1
- package/esm/components/columnsManagement/GridColumnsManagement.d.ts +6 -0
- package/esm/components/columnsManagement/GridColumnsManagement.js +17 -5
- package/esm/components/containers/GridRootStyles.d.ts +1 -1
- package/esm/components/toolbarV8/Toolbar.d.ts +1 -1
- package/esm/components/virtualization/GridVirtualScroller.js +5 -5
- package/esm/constants/dataGridPropsDefaultValues.js +1 -0
- package/esm/hooks/core/useGridVirtualizer.d.ts +9 -0
- package/esm/hooks/core/useGridVirtualizer.js +223 -0
- package/esm/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +1 -1
- package/esm/hooks/features/columnHeaders/useGridColumnHeaders.js +3 -2
- package/esm/hooks/features/columns/useGridColumnSpanning.js +5 -90
- package/esm/hooks/features/dimensions/useGridDimensions.js +18 -188
- package/esm/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +1 -1
- package/esm/hooks/features/keyboardNavigation/utils.d.ts +3 -3
- package/esm/hooks/features/keyboardNavigation/utils.js +5 -5
- package/esm/hooks/features/pivoting/gridPivotingInterfaces.d.ts +0 -1
- package/esm/hooks/features/pivoting/gridPivotingSelectors.d.ts +1 -4
- package/esm/hooks/features/pivoting/gridPivotingSelectors.js +1 -2
- package/esm/hooks/features/rows/gridRowsMetaInterfaces.d.ts +2 -8
- package/esm/hooks/features/rows/gridRowsMetaState.d.ts +2 -18
- package/esm/hooks/features/rows/useGridRowAriaAttributes.js +3 -1
- package/esm/hooks/features/rows/useGridRowSpanning.d.ts +2 -12
- package/esm/hooks/features/rows/useGridRowSpanning.js +54 -85
- package/esm/hooks/features/rows/useGridRowsMeta.d.ts +1 -1
- package/esm/hooks/features/rows/useGridRowsMeta.js +17 -187
- package/esm/hooks/features/virtualization/gridVirtualizationSelectors.d.ts +1 -1
- package/esm/hooks/features/virtualization/index.d.ts +1 -0
- package/esm/hooks/features/virtualization/index.js +1 -0
- package/esm/hooks/features/virtualization/useGridVirtualization.d.ts +5 -16
- package/esm/hooks/features/virtualization/useGridVirtualization.js +41 -22
- package/esm/hooks/utils/index.d.ts +1 -1
- package/esm/hooks/utils/index.js +1 -1
- package/esm/hooks/utils/useFirstRender.d.ts +1 -1
- package/esm/hooks/utils/useFirstRender.js +1 -8
- package/esm/index.js +1 -1
- package/esm/internals/index.d.ts +1 -1
- package/esm/internals/index.js +1 -1
- package/esm/internals/utils/getPinnedCellOffset.js +5 -0
- package/esm/locales/frFR.js +18 -21
- package/esm/locales/heIL.js +12 -12
- package/esm/locales/plPL.js +22 -24
- package/esm/models/api/gridApiCommon.d.ts +4 -1
- package/esm/models/api/gridColumnSpanning.d.ts +5 -11
- package/esm/models/props/DataGridProps.d.ts +5 -0
- package/esm/utils/roundToDecimalPlaces.d.ts +1 -1
- package/esm/utils/roundToDecimalPlaces.js +1 -3
- package/hooks/core/useGridVirtualizer.d.ts +9 -0
- package/hooks/core/useGridVirtualizer.js +231 -0
- package/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +1 -1
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +4 -3
- package/hooks/features/columns/useGridColumnSpanning.js +5 -91
- package/hooks/features/dimensions/useGridDimensions.js +18 -188
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +1 -1
- package/hooks/features/keyboardNavigation/utils.d.ts +3 -3
- package/hooks/features/keyboardNavigation/utils.js +5 -5
- package/hooks/features/pivoting/gridPivotingInterfaces.d.ts +0 -1
- package/hooks/features/pivoting/gridPivotingSelectors.d.ts +1 -4
- package/hooks/features/pivoting/gridPivotingSelectors.js +2 -3
- package/hooks/features/rows/gridRowsMetaInterfaces.d.ts +2 -8
- package/hooks/features/rows/gridRowsMetaState.d.ts +2 -18
- package/hooks/features/rows/useGridRowAriaAttributes.js +3 -1
- package/hooks/features/rows/useGridRowSpanning.d.ts +2 -12
- package/hooks/features/rows/useGridRowSpanning.js +54 -85
- package/hooks/features/rows/useGridRowsMeta.d.ts +1 -1
- package/hooks/features/rows/useGridRowsMeta.js +15 -186
- package/hooks/features/virtualization/gridVirtualizationSelectors.d.ts +1 -1
- package/hooks/features/virtualization/index.d.ts +1 -0
- package/hooks/features/virtualization/index.js +12 -0
- package/hooks/features/virtualization/useGridVirtualization.d.ts +5 -16
- package/hooks/features/virtualization/useGridVirtualization.js +42 -24
- package/hooks/utils/index.d.ts +1 -1
- package/hooks/utils/index.js +12 -12
- package/hooks/utils/useFirstRender.d.ts +1 -1
- package/hooks/utils/useFirstRender.js +11 -11
- package/index.js +1 -1
- package/internals/index.d.ts +1 -1
- package/internals/index.js +4 -11
- package/internals/utils/getPinnedCellOffset.js +5 -0
- package/locales/frFR.js +18 -21
- package/locales/heIL.js +12 -12
- package/locales/plPL.js +22 -24
- package/models/api/gridApiCommon.d.ts +4 -1
- package/models/api/gridColumnSpanning.d.ts +5 -11
- package/models/props/DataGridProps.d.ts +5 -0
- package/package.json +5 -5
- package/utils/roundToDecimalPlaces.d.ts +1 -1
- package/utils/roundToDecimalPlaces.js +7 -4
- package/esm/hooks/features/rows/gridRowSpanningSelectors.d.ts +0 -10
- package/esm/hooks/features/rows/gridRowSpanningSelectors.js +0 -5
- package/esm/hooks/features/virtualization/useGridVirtualScroller.d.ts +0 -56
- package/esm/hooks/features/virtualization/useGridVirtualScroller.js +0 -843
- package/esm/hooks/utils/useRunOnce.d.ts +0 -5
- package/esm/hooks/utils/useRunOnce.js +0 -18
- package/esm/utils/platform.d.ts +0 -1
- package/esm/utils/platform.js +0 -2
- package/hooks/features/rows/gridRowSpanningSelectors.d.ts +0 -10
- package/hooks/features/rows/gridRowSpanningSelectors.js +0 -11
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +0 -56
- package/hooks/features/virtualization/useGridVirtualScroller.js +0 -854
- package/hooks/utils/useRunOnce.d.ts +0 -5
- package/hooks/utils/useRunOnce.js +0 -27
- package/utils/platform.d.ts +0 -1
- package/utils/platform.js +0 -8
|
@@ -3,12 +3,12 @@ import * as React from 'react';
|
|
|
3
3
|
import { styled } from '@mui/system';
|
|
4
4
|
import composeClasses from '@mui/utils/composeClasses';
|
|
5
5
|
import { gridHasBottomFillerSelector, gridHasScrollXSelector, gridHasScrollYSelector } from "../../hooks/features/dimensions/gridDimensionsSelectors.js";
|
|
6
|
+
import { gridRowTreeSelector } from "../../hooks/features/rows/index.js";
|
|
6
7
|
import { GridScrollArea } from "../GridScrollArea.js";
|
|
7
8
|
import { useGridRootProps } from "../../hooks/utils/useGridRootProps.js";
|
|
8
|
-
import {
|
|
9
|
+
import { useGridPrivateApiContext } from "../../hooks/utils/useGridPrivateApiContext.js";
|
|
9
10
|
import { useGridSelector } from "../../hooks/utils/useGridSelector.js";
|
|
10
11
|
import { getDataGridUtilityClass } from "../../constants/gridClasses.js";
|
|
11
|
-
import { useGridVirtualScroller } from "../../hooks/features/virtualization/useGridVirtualScroller.js";
|
|
12
12
|
import { useGridOverlays } from "../../hooks/features/overlays/useGridOverlays.js";
|
|
13
13
|
import { GridHeaders } from "../GridHeaders.js";
|
|
14
14
|
import { GridMainContainer as Container } from "./GridMainContainer.js";
|
|
@@ -61,7 +61,7 @@ const Scroller = styled('div', {
|
|
|
61
61
|
});
|
|
62
62
|
const hasPinnedRightSelector = apiRef => apiRef.current.state.dimensions.rightPinnedWidth > 0;
|
|
63
63
|
function GridVirtualScroller(props) {
|
|
64
|
-
const apiRef =
|
|
64
|
+
const apiRef = useGridPrivateApiContext();
|
|
65
65
|
const rootProps = useGridRootProps();
|
|
66
66
|
const hasScrollY = useGridSelector(apiRef, gridHasScrollYSelector);
|
|
67
67
|
const hasScrollX = useGridSelector(apiRef, gridHasScrollXSelector);
|
|
@@ -77,7 +77,7 @@ function GridVirtualScroller(props) {
|
|
|
77
77
|
hasPinnedRight
|
|
78
78
|
}, overlaysProps);
|
|
79
79
|
const classes = useUtilityClasses(ownerState);
|
|
80
|
-
const virtualScroller =
|
|
80
|
+
const virtualScroller = apiRef.current.virtualizer.api.useVirtualization().getters;
|
|
81
81
|
const {
|
|
82
82
|
getContainerProps,
|
|
83
83
|
getScrollerProps,
|
|
@@ -88,7 +88,7 @@ function GridVirtualScroller(props) {
|
|
|
88
88
|
getRows,
|
|
89
89
|
getScrollAreaProps
|
|
90
90
|
} = virtualScroller;
|
|
91
|
-
const rows = getRows();
|
|
91
|
+
const rows = getRows(undefined, gridRowTreeSelector(apiRef));
|
|
92
92
|
return /*#__PURE__*/_jsxs(Container, _extends({
|
|
93
93
|
className: classes.root
|
|
94
94
|
}, getContainerProps(), {
|
|
@@ -10,6 +10,7 @@ export const DATA_GRID_PROPS_DEFAULT_VALUES = {
|
|
|
10
10
|
checkboxSelectionVisibleOnly: false,
|
|
11
11
|
clipboardCopyCellDelimiter: '\t',
|
|
12
12
|
columnBufferPx: 150,
|
|
13
|
+
columnFilterDebounceMs: 150,
|
|
13
14
|
columnHeaderHeight: 56,
|
|
14
15
|
disableAutosize: false,
|
|
15
16
|
disableColumnFilter: false,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RefObject } from '@mui/x-internals/types';
|
|
2
|
+
import { GridPrivateApiCommunity } from "../../models/api/gridApiCommunity.js";
|
|
3
|
+
import { DataGridProcessedProps } from "../../models/props/DataGridProps.js";
|
|
4
|
+
type RootProps = DataGridProcessedProps;
|
|
5
|
+
/**
|
|
6
|
+
* Virtualizer setup
|
|
7
|
+
*/
|
|
8
|
+
export declare function useGridVirtualizer(apiRef: RefObject<GridPrivateApiCommunity>, rootProps: RootProps): void;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import useEventCallback from '@mui/utils/useEventCallback';
|
|
4
|
+
import { useRtl } from '@mui/system/RtlProvider';
|
|
5
|
+
import { roundToDecimalPlaces } from '@mui/x-internals/math';
|
|
6
|
+
import { useStoreEffect } from '@mui/x-internals/store';
|
|
7
|
+
import { useVirtualizer } from '@mui/x-virtualizer';
|
|
8
|
+
import { useFirstRender } from "../utils/useFirstRender.js";
|
|
9
|
+
import { createSelector } from "../../utils/createSelector.js";
|
|
10
|
+
import { useGridSelector } from "../utils/useGridSelector.js";
|
|
11
|
+
import { gridContentHeightSelector, gridHasFillerSelector, gridVerticalScrollbarWidthSelector } from "../features/dimensions/gridDimensionsSelectors.js";
|
|
12
|
+
import { gridDensityFactorSelector } from "../features/density/index.js";
|
|
13
|
+
import { gridVisibleColumnDefinitionsSelector, gridVisiblePinnedColumnDefinitionsSelector, gridColumnPositionsSelector, gridHasColSpanSelector } from "../features/columns/gridColumnsSelector.js";
|
|
14
|
+
import { gridPinnedRowsSelector, gridRowCountSelector } from "../features/rows/gridRowsSelector.js";
|
|
15
|
+
import { useGridVisibleRows } from "../utils/useGridVisibleRows.js";
|
|
16
|
+
import { gridPaginationSelector } from "../features/pagination/index.js";
|
|
17
|
+
import { gridFocusedVirtualCellSelector } from "../features/virtualization/gridFocusedVirtualCellSelector.js";
|
|
18
|
+
import { gridRowSelectionManagerSelector } from "../features/rowSelection/index.js";
|
|
19
|
+
import { DATA_GRID_PROPS_DEFAULT_VALUES } from "../../constants/dataGridPropsDefaultValues.js";
|
|
20
|
+
import { getValidRowHeight, minimalContentHeight, rowHeightWarning } from "../features/rows/gridRowsUtils.js";
|
|
21
|
+
import { getTotalHeaderHeight } from "../features/columns/gridColumnsUtils.js";
|
|
22
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
23
|
+
function identity(x) {
|
|
24
|
+
return x;
|
|
25
|
+
}
|
|
26
|
+
const columnsTotalWidthSelector = createSelector(gridVisibleColumnDefinitionsSelector, gridColumnPositionsSelector, (visibleColumns, positions) => {
|
|
27
|
+
const colCount = visibleColumns.length;
|
|
28
|
+
if (colCount === 0) {
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
return roundToDecimalPlaces(positions[colCount - 1] + visibleColumns[colCount - 1].computedWidth, 1);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Virtualizer setup
|
|
36
|
+
*/
|
|
37
|
+
export function useGridVirtualizer(apiRef, rootProps) {
|
|
38
|
+
const isRtl = useRtl();
|
|
39
|
+
const {
|
|
40
|
+
listView
|
|
41
|
+
} = rootProps;
|
|
42
|
+
const visibleColumns = useGridSelector(apiRef, gridVisibleColumnDefinitionsSelector);
|
|
43
|
+
const pinnedRows = useGridSelector(apiRef, gridPinnedRowsSelector);
|
|
44
|
+
const pinnedColumns = gridVisiblePinnedColumnDefinitionsSelector(apiRef);
|
|
45
|
+
const rowSelectionManager = useGridSelector(apiRef, gridRowSelectionManagerSelector);
|
|
46
|
+
const isRowSelected = id => rowSelectionManager.has(id) && apiRef.current.isRowSelectable(id);
|
|
47
|
+
const currentPage = useGridVisibleRows(apiRef);
|
|
48
|
+
const hasColSpan = useGridSelector(apiRef, gridHasColSpanSelector);
|
|
49
|
+
|
|
50
|
+
/* TODO: extract dimensions code */
|
|
51
|
+
const contentHeight = useGridSelector(apiRef, gridContentHeightSelector);
|
|
52
|
+
const verticalScrollbarWidth = useGridSelector(apiRef, gridVerticalScrollbarWidthSelector);
|
|
53
|
+
const hasFiller = useGridSelector(apiRef, gridHasFillerSelector);
|
|
54
|
+
const {
|
|
55
|
+
autoHeight
|
|
56
|
+
} = rootProps;
|
|
57
|
+
const scrollReset = listView;
|
|
58
|
+
|
|
59
|
+
// <DIMENSIONS>
|
|
60
|
+
const density = useGridSelector(apiRef, gridDensityFactorSelector);
|
|
61
|
+
const baseRowHeight = getValidRowHeight(rootProps.rowHeight, DATA_GRID_PROPS_DEFAULT_VALUES.rowHeight, rowHeightWarning);
|
|
62
|
+
const rowHeight = Math.floor(baseRowHeight * density);
|
|
63
|
+
const headerHeight = Math.floor(rootProps.columnHeaderHeight * density);
|
|
64
|
+
const groupHeaderHeight = Math.floor((rootProps.columnGroupHeaderHeight ?? rootProps.columnHeaderHeight) * density);
|
|
65
|
+
const headerFilterHeight = Math.floor((rootProps.headerFilterHeight ?? rootProps.columnHeaderHeight) * density);
|
|
66
|
+
const columnsTotalWidth = useGridSelector(apiRef, columnsTotalWidthSelector);
|
|
67
|
+
const headersTotalHeight = getTotalHeaderHeight(apiRef, rootProps);
|
|
68
|
+
const leftPinnedWidth = pinnedColumns.left.reduce((w, col) => w + col.computedWidth, 0);
|
|
69
|
+
const rightPinnedWidth = pinnedColumns.right.reduce((w, col) => w + col.computedWidth, 0);
|
|
70
|
+
const dimensions = {
|
|
71
|
+
rowHeight,
|
|
72
|
+
headerHeight,
|
|
73
|
+
groupHeaderHeight,
|
|
74
|
+
headerFilterHeight,
|
|
75
|
+
columnsTotalWidth,
|
|
76
|
+
headersTotalHeight,
|
|
77
|
+
leftPinnedWidth,
|
|
78
|
+
rightPinnedWidth
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// </DIMENSIONS>
|
|
82
|
+
|
|
83
|
+
// <ROWS_META>
|
|
84
|
+
const dataRowCount = useGridSelector(apiRef, gridRowCountSelector);
|
|
85
|
+
const pagination = useGridSelector(apiRef, gridPaginationSelector);
|
|
86
|
+
const rowCount = Math.min(pagination.enabled ? pagination.paginationModel.pageSize : dataRowCount, dataRowCount);
|
|
87
|
+
const {
|
|
88
|
+
getRowHeight,
|
|
89
|
+
getEstimatedRowHeight,
|
|
90
|
+
getRowSpacing
|
|
91
|
+
} = rootProps;
|
|
92
|
+
// </ROWS_META>
|
|
93
|
+
|
|
94
|
+
const focusedVirtualCell = useGridSelector(apiRef, gridFocusedVirtualCellSelector);
|
|
95
|
+
const virtualizer = useVirtualizer({
|
|
96
|
+
scrollbarSize: rootProps.scrollbarSize,
|
|
97
|
+
dimensions,
|
|
98
|
+
initialState: {
|
|
99
|
+
scroll: rootProps.initialState?.scroll,
|
|
100
|
+
dimensions: apiRef.current.state.dimensions,
|
|
101
|
+
rowSpanning: apiRef.current.state.rowSpanning,
|
|
102
|
+
virtualization: apiRef.current.state.virtualization
|
|
103
|
+
},
|
|
104
|
+
isRtl,
|
|
105
|
+
rows: currentPage.rows,
|
|
106
|
+
range: currentPage.range,
|
|
107
|
+
rowIdToIndexMap: currentPage.rowIdToIndexMap,
|
|
108
|
+
rowCount,
|
|
109
|
+
columns: visibleColumns,
|
|
110
|
+
pinnedRows,
|
|
111
|
+
pinnedColumns,
|
|
112
|
+
refs: {
|
|
113
|
+
container: apiRef.current.mainElementRef,
|
|
114
|
+
scroller: apiRef.current.virtualScrollerRef,
|
|
115
|
+
scrollbarVertical: apiRef.current.virtualScrollbarVerticalRef,
|
|
116
|
+
scrollbarHorizontal: apiRef.current.virtualScrollbarHorizontalRef
|
|
117
|
+
},
|
|
118
|
+
hasColSpan,
|
|
119
|
+
contentHeight,
|
|
120
|
+
minimalContentHeight,
|
|
121
|
+
autoHeight,
|
|
122
|
+
getRowHeight: React.useMemo(() => {
|
|
123
|
+
if (!getRowHeight) {
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
return rowEntry => getRowHeight(_extends({}, rowEntry, {
|
|
127
|
+
densityFactor: density
|
|
128
|
+
}));
|
|
129
|
+
}, [getRowHeight, density]),
|
|
130
|
+
getEstimatedRowHeight: React.useMemo(() => getEstimatedRowHeight ? rowEntry => getEstimatedRowHeight(_extends({}, rowEntry, {
|
|
131
|
+
densityFactor: density
|
|
132
|
+
})) : undefined, [getEstimatedRowHeight, density]),
|
|
133
|
+
getRowSpacing: React.useMemo(() => getRowSpacing ? (rowEntry, visibility) => getRowSpacing(_extends({}, rowEntry, visibility, {
|
|
134
|
+
indexRelativeToCurrentPage: apiRef.current.getRowIndexRelativeToVisibleRows(rowEntry.id)
|
|
135
|
+
})) : undefined, [apiRef, getRowSpacing]),
|
|
136
|
+
applyRowHeight: useEventCallback((entry, row) => apiRef.current.unstable_applyPipeProcessors('rowHeight', entry, row)),
|
|
137
|
+
virtualizeColumnsWithAutoRowHeight: rootProps.virtualizeColumnsWithAutoRowHeight,
|
|
138
|
+
focusedVirtualCell: useEventCallback(() => focusedVirtualCell),
|
|
139
|
+
rowBufferPx: rootProps.rowBufferPx,
|
|
140
|
+
columnBufferPx: rootProps.columnBufferPx,
|
|
141
|
+
resizeThrottleMs: rootProps.resizeThrottleMs,
|
|
142
|
+
onResize: useEventCallback(size => apiRef.current.publishEvent('resize', size)),
|
|
143
|
+
onWheel: useEventCallback(event => {
|
|
144
|
+
apiRef.current.publishEvent('virtualScrollerWheel', {}, event);
|
|
145
|
+
}),
|
|
146
|
+
onTouchMove: useEventCallback(event => {
|
|
147
|
+
apiRef.current.publishEvent('virtualScrollerTouchMove', {}, event);
|
|
148
|
+
}),
|
|
149
|
+
onRenderContextChange: useEventCallback(nextRenderContext => {
|
|
150
|
+
apiRef.current.publishEvent('renderedRowsIntervalChange', nextRenderContext);
|
|
151
|
+
}),
|
|
152
|
+
onScrollChange: (scrollPosition, nextRenderContext) => {
|
|
153
|
+
apiRef.current.publishEvent('scrollPositionChange', {
|
|
154
|
+
top: scrollPosition.top,
|
|
155
|
+
left: scrollPosition.left,
|
|
156
|
+
renderContext: nextRenderContext
|
|
157
|
+
});
|
|
158
|
+
},
|
|
159
|
+
scrollReset,
|
|
160
|
+
getColspan: (rowId, column) => {
|
|
161
|
+
if (typeof column.colSpan === 'function') {
|
|
162
|
+
const row = apiRef.current.getRow(rowId);
|
|
163
|
+
const value = apiRef.current.getRowValue(row, column);
|
|
164
|
+
return column.colSpan(value, row, column, apiRef) ?? 0;
|
|
165
|
+
}
|
|
166
|
+
return column.colSpan ?? 0;
|
|
167
|
+
},
|
|
168
|
+
renderRow: params => /*#__PURE__*/_jsx(rootProps.slots.row, _extends({
|
|
169
|
+
row: params.model,
|
|
170
|
+
rowId: params.id,
|
|
171
|
+
index: params.rowIndex,
|
|
172
|
+
selected: isRowSelected(params.id),
|
|
173
|
+
offsetLeft: params.offsetLeft,
|
|
174
|
+
columnsTotalWidth: columnsTotalWidth,
|
|
175
|
+
rowHeight: params.baseRowHeight,
|
|
176
|
+
pinnedColumns: pinnedColumns,
|
|
177
|
+
visibleColumns: params.columns,
|
|
178
|
+
firstColumnIndex: params.firstColumnIndex,
|
|
179
|
+
lastColumnIndex: params.lastColumnIndex,
|
|
180
|
+
focusedColumnIndex: params.focusedColumnIndex,
|
|
181
|
+
isFirstVisible: params.isFirstVisible,
|
|
182
|
+
isLastVisible: params.isLastVisible,
|
|
183
|
+
isNotVisible: params.isVirtualFocusRow,
|
|
184
|
+
showBottomBorder: params.showBottomBorder,
|
|
185
|
+
scrollbarWidth: verticalScrollbarWidth,
|
|
186
|
+
gridHasFiller: hasFiller
|
|
187
|
+
}, rootProps.slotProps?.row), params.id),
|
|
188
|
+
renderInfiniteLoadingTrigger: id => apiRef.current.getInfiniteLoadingTriggerElement?.({
|
|
189
|
+
lastRowId: id
|
|
190
|
+
})
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// HACK: Keep the grid's store in sync with the virtualizer store. We set up the
|
|
194
|
+
// subscription in the render phase rather than in an effect because other grid
|
|
195
|
+
// initialization code runs between those two moments.
|
|
196
|
+
//
|
|
197
|
+
// TODO(v9): Remove this
|
|
198
|
+
useFirstRender(() => {
|
|
199
|
+
apiRef.current.store.state.dimensions = virtualizer.store.state.dimensions;
|
|
200
|
+
apiRef.current.store.state.rowsMeta = virtualizer.store.state.rowsMeta;
|
|
201
|
+
apiRef.current.store.state.virtualization = virtualizer.store.state.virtualization;
|
|
202
|
+
});
|
|
203
|
+
useStoreEffect(virtualizer.store, identity, (_, state) => {
|
|
204
|
+
if (state.dimensions !== apiRef.current.state.dimensions) {
|
|
205
|
+
apiRef.current.setState(gridState => _extends({}, gridState, {
|
|
206
|
+
dimensions: state.dimensions
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
209
|
+
if (state.rowsMeta !== apiRef.current.state.rowsMeta) {
|
|
210
|
+
apiRef.current.setState(gridState => _extends({}, gridState, {
|
|
211
|
+
rowsMeta: state.rowsMeta
|
|
212
|
+
}));
|
|
213
|
+
}
|
|
214
|
+
if (state.virtualization !== apiRef.current.state.virtualization) {
|
|
215
|
+
apiRef.current.setState(gridState => _extends({}, gridState, {
|
|
216
|
+
virtualization: state.virtualization
|
|
217
|
+
}));
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
apiRef.current.register('private', {
|
|
221
|
+
virtualizer
|
|
222
|
+
});
|
|
223
|
+
}
|
|
@@ -31,7 +31,7 @@ export interface GetHeadersParams {
|
|
|
31
31
|
type OwnerState = DataGridProcessedProps;
|
|
32
32
|
export declare const GridColumnHeaderRow: import("@emotion/styled").StyledComponent<import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme> & {
|
|
33
33
|
ownerState: OwnerState;
|
|
34
|
-
}, Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, keyof React.
|
|
34
|
+
}, Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, keyof React.ClassAttributes<HTMLDivElement> | keyof React.HTMLAttributes<HTMLDivElement>>, {}>;
|
|
35
35
|
export declare const useGridColumnHeaders: (props: UseGridColumnHeadersProps) => {
|
|
36
36
|
renderContext: GridColumnsRenderContext;
|
|
37
37
|
leftRenderContext: {
|
|
@@ -4,6 +4,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import clsx from 'clsx';
|
|
6
6
|
import { styled } from '@mui/material/styles';
|
|
7
|
+
import { computeOffsetLeft } from '@mui/x-virtualizer';
|
|
7
8
|
import { useGridSelector } from "../../utils/index.js";
|
|
8
9
|
import { useGridRootProps } from "../../utils/useGridRootProps.js";
|
|
9
10
|
import { useGridPrivateApiContext } from "../../utils/useGridPrivateApiContext.js";
|
|
@@ -11,7 +12,6 @@ import { useGridEvent } from "../../utils/useGridEvent.js";
|
|
|
11
12
|
import { GridColumnHeaderItem } from "../../../components/columnHeaders/GridColumnHeaderItem.js";
|
|
12
13
|
import { gridColumnsTotalWidthSelector, gridGroupHeaderHeightSelector, gridHasFillerSelector, gridHeaderHeightSelector, gridVerticalScrollbarWidthSelector } from "../dimensions/gridDimensionsSelectors.js";
|
|
13
14
|
import { gridRenderContextColumnsSelector } from "../virtualization/index.js";
|
|
14
|
-
import { computeOffsetLeft } from "../virtualization/useGridVirtualScroller.js";
|
|
15
15
|
import { GridColumnGroupHeader } from "../../../components/columnHeaders/GridColumnGroupHeader.js";
|
|
16
16
|
import { gridColumnPositionsSelector, gridVisiblePinnedColumnDefinitionsSelector, gridColumnLookupSelector } from "../columns/index.js";
|
|
17
17
|
import { gridColumnGroupsUnwrappedModelSelector } from "../columnGrouping/gridColumnGroupsSelector.js";
|
|
@@ -85,7 +85,8 @@ export const useGridColumnHeaders = props => {
|
|
|
85
85
|
renderContext: currentContext = renderContext
|
|
86
86
|
} = params || {};
|
|
87
87
|
const firstColumnToRender = currentContext.firstColumnIndex;
|
|
88
|
-
|
|
88
|
+
// HACK: renderContext ins't always synchronized, this should be handled properly.
|
|
89
|
+
const lastColumnToRender = Math.min(currentContext.lastColumnIndex, visibleColumns.length);
|
|
89
90
|
const renderedColumns = visibleColumns.slice(firstColumnToRender, lastColumnToRender);
|
|
90
91
|
return {
|
|
91
92
|
renderedColumns,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
1
|
import { useGridApiMethod } from "../../utils/useGridApiMethod.js";
|
|
3
2
|
import { useGridEvent } from "../../utils/useGridEvent.js";
|
|
4
3
|
/**
|
|
@@ -6,36 +5,10 @@ import { useGridEvent } from "../../utils/useGridEvent.js";
|
|
|
6
5
|
* @requires useGridParamsApi (method)
|
|
7
6
|
*/
|
|
8
7
|
export const useGridColumnSpanning = apiRef => {
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const resetColSpan = () => {
|
|
14
|
-
lookup.current = {};
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
// Calculate `colSpan` for each cell in the row
|
|
18
|
-
const calculateColSpan = React.useCallback(({
|
|
19
|
-
rowId,
|
|
20
|
-
minFirstColumn,
|
|
21
|
-
maxLastColumn,
|
|
22
|
-
columns
|
|
23
|
-
}) => {
|
|
24
|
-
for (let i = minFirstColumn; i < maxLastColumn; i += 1) {
|
|
25
|
-
const cellProps = calculateCellColSpan({
|
|
26
|
-
apiRef,
|
|
27
|
-
lookup: lookup.current,
|
|
28
|
-
columnIndex: i,
|
|
29
|
-
rowId,
|
|
30
|
-
minFirstColumnIndex: minFirstColumn,
|
|
31
|
-
maxLastColumnIndex: maxLastColumn,
|
|
32
|
-
columns
|
|
33
|
-
});
|
|
34
|
-
if (cellProps.colSpan > 1) {
|
|
35
|
-
i += cellProps.colSpan - 1;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
}, [apiRef]);
|
|
8
|
+
const virtualizer = apiRef.current.virtualizer;
|
|
9
|
+
const resetColSpan = virtualizer.api.resetColSpan;
|
|
10
|
+
const getCellColSpanInfo = virtualizer.api.getCellColSpanInfo;
|
|
11
|
+
const calculateColSpan = virtualizer.api.calculateColSpan;
|
|
39
12
|
const columnSpanningPublicApi = {
|
|
40
13
|
unstable_getCellColSpanInfo: getCellColSpanInfo
|
|
41
14
|
};
|
|
@@ -46,62 +19,4 @@ export const useGridColumnSpanning = apiRef => {
|
|
|
46
19
|
useGridApiMethod(apiRef, columnSpanningPublicApi, 'public');
|
|
47
20
|
useGridApiMethod(apiRef, columnSpanningPrivateApi, 'private');
|
|
48
21
|
useGridEvent(apiRef, 'columnOrderChange', resetColSpan);
|
|
49
|
-
};
|
|
50
|
-
function calculateCellColSpan(params) {
|
|
51
|
-
const {
|
|
52
|
-
apiRef,
|
|
53
|
-
lookup,
|
|
54
|
-
columnIndex,
|
|
55
|
-
rowId,
|
|
56
|
-
minFirstColumnIndex,
|
|
57
|
-
maxLastColumnIndex,
|
|
58
|
-
columns
|
|
59
|
-
} = params;
|
|
60
|
-
const columnsLength = columns.length;
|
|
61
|
-
const column = columns[columnIndex];
|
|
62
|
-
const row = apiRef.current.getRow(rowId);
|
|
63
|
-
const value = apiRef.current.getRowValue(row, column);
|
|
64
|
-
const colSpan = typeof column.colSpan === 'function' ? column.colSpan(value, row, column, apiRef) : column.colSpan;
|
|
65
|
-
if (!colSpan || colSpan === 1) {
|
|
66
|
-
setCellColSpanInfo(lookup, rowId, columnIndex, {
|
|
67
|
-
spannedByColSpan: false,
|
|
68
|
-
cellProps: {
|
|
69
|
-
colSpan: 1,
|
|
70
|
-
width: column.computedWidth
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
return {
|
|
74
|
-
colSpan: 1
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
let width = column.computedWidth;
|
|
78
|
-
for (let j = 1; j < colSpan; j += 1) {
|
|
79
|
-
const nextColumnIndex = columnIndex + j;
|
|
80
|
-
// Cells should be spanned only within their column section (left-pinned, right-pinned and unpinned).
|
|
81
|
-
if (nextColumnIndex >= minFirstColumnIndex && nextColumnIndex < maxLastColumnIndex) {
|
|
82
|
-
const nextColumn = columns[nextColumnIndex];
|
|
83
|
-
width += nextColumn.computedWidth;
|
|
84
|
-
setCellColSpanInfo(lookup, rowId, columnIndex + j, {
|
|
85
|
-
spannedByColSpan: true,
|
|
86
|
-
rightVisibleCellIndex: Math.min(columnIndex + colSpan, columnsLength - 1),
|
|
87
|
-
leftVisibleCellIndex: columnIndex
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
setCellColSpanInfo(lookup, rowId, columnIndex, {
|
|
91
|
-
spannedByColSpan: false,
|
|
92
|
-
cellProps: {
|
|
93
|
-
colSpan,
|
|
94
|
-
width
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return {
|
|
99
|
-
colSpan
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
function setCellColSpanInfo(lookup, rowId, columnIndex, cellColSpanInfo) {
|
|
103
|
-
if (!lookup[rowId]) {
|
|
104
|
-
lookup[rowId] = {};
|
|
105
|
-
}
|
|
106
|
-
lookup[rowId][columnIndex] = cellColSpanInfo;
|
|
107
|
-
}
|
|
22
|
+
};
|