@mui/x-data-grid 7.25.0 → 7.27.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +133 -0
- package/DataGrid/DataGrid.js +6 -0
- package/DataGrid/useDataGridComponent.js +3 -3
- package/components/GridRow.js +8 -2
- package/components/GridScrollArea.d.ts +5 -2
- package/components/GridScrollArea.js +32 -25
- package/components/GridSkeletonLoadingOverlay.js +2 -1
- package/components/containers/GridRoot.js +11 -9
- package/components/containers/GridRootStyles.js +3 -3
- package/components/virtualization/GridMainContainer.d.ts +2 -2
- package/components/virtualization/GridMainContainer.js +1 -1
- package/components/virtualization/GridVirtualScroller.js +21 -14
- package/constants/dataGridPropsDefaultValues.js +1 -0
- package/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.d.ts +1 -1
- package/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.js +6 -4
- package/hooks/core/useGridStateInitialization.js +3 -2
- package/hooks/features/clipboard/useGridClipboard.js +1 -1
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +10 -14
- package/hooks/features/columns/gridColumnsSelector.d.ts +0 -5
- package/hooks/features/columns/gridColumnsSelector.js +0 -12
- package/hooks/features/dimensions/gridDimensionsSelectors.d.ts +16 -0
- package/hooks/features/dimensions/gridDimensionsSelectors.js +26 -1
- package/hooks/features/dimensions/index.d.ts +1 -1
- package/hooks/features/dimensions/index.js +1 -2
- package/hooks/features/dimensions/useGridDimensions.js +97 -70
- package/hooks/features/editing/gridEditingSelectors.d.ts +5 -1
- package/hooks/features/editing/gridEditingSelectors.js +6 -1
- package/hooks/features/editing/useGridRowEditing.js +4 -4
- package/hooks/features/filter/gridFilterState.d.ts +5 -0
- package/hooks/features/filter/gridFilterState.js +5 -0
- package/hooks/features/filter/useGridFilter.js +6 -13
- package/hooks/features/pagination/useGridPagination.js +1 -1
- package/hooks/features/pagination/useGridPaginationModel.d.ts +1 -1
- package/hooks/features/pagination/useGridPaginationModel.js +44 -0
- package/hooks/features/rowSelection/useGridRowSelection.js +1 -1
- package/hooks/features/rowSelection/utils.js +1 -1
- package/hooks/features/rows/gridRowsMetaState.d.ts +8 -0
- package/hooks/features/rows/gridRowsUtils.d.ts +0 -4
- package/hooks/features/rows/gridRowsUtils.js +0 -16
- package/hooks/features/rows/useGridRowsMeta.js +33 -17
- package/hooks/features/sorting/gridSortingSelector.js +10 -9
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +6 -0
- package/hooks/features/virtualization/useGridVirtualScroller.js +43 -27
- package/hooks/utils/useGridNativeEventListener.d.ts +0 -1
- package/hooks/utils/useGridNativeEventListener.js +12 -22
- package/hooks/utils/useGridSelector.d.ts +8 -1
- package/hooks/utils/useGridSelector.js +42 -8
- package/hooks/utils/useIsSSR.d.ts +1 -0
- package/hooks/utils/useIsSSR.js +5 -0
- package/index.js +1 -1
- package/internals/index.d.ts +2 -1
- package/internals/index.js +2 -1
- package/locales/plPL.js +31 -35
- package/locales/ukUA.js +9 -10
- package/models/api/gridStateApi.d.ts +1 -0
- package/models/events/gridEventLookup.d.ts +6 -0
- package/models/props/DataGridProps.d.ts +6 -0
- package/modern/DataGrid/DataGrid.js +6 -0
- package/modern/DataGrid/useDataGridComponent.js +3 -3
- package/modern/components/GridRow.js +8 -2
- package/modern/components/GridScrollArea.js +32 -25
- package/modern/components/GridSkeletonLoadingOverlay.js +2 -1
- package/modern/components/containers/GridRoot.js +11 -9
- package/modern/components/containers/GridRootStyles.js +3 -3
- package/modern/components/virtualization/GridMainContainer.js +1 -1
- package/modern/components/virtualization/GridVirtualScroller.js +21 -14
- package/modern/constants/dataGridPropsDefaultValues.js +1 -0
- package/modern/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.js +6 -4
- package/modern/hooks/core/useGridStateInitialization.js +3 -2
- package/modern/hooks/features/clipboard/useGridClipboard.js +1 -1
- package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +10 -14
- package/modern/hooks/features/columns/gridColumnsSelector.js +0 -12
- package/modern/hooks/features/dimensions/gridDimensionsSelectors.js +26 -1
- package/modern/hooks/features/dimensions/index.js +1 -2
- package/modern/hooks/features/dimensions/useGridDimensions.js +97 -70
- package/modern/hooks/features/editing/gridEditingSelectors.js +6 -1
- package/modern/hooks/features/editing/useGridRowEditing.js +4 -4
- package/modern/hooks/features/filter/gridFilterState.js +5 -0
- package/modern/hooks/features/filter/useGridFilter.js +6 -13
- package/modern/hooks/features/pagination/useGridPagination.js +1 -1
- package/modern/hooks/features/pagination/useGridPaginationModel.js +44 -0
- package/modern/hooks/features/rowSelection/useGridRowSelection.js +1 -1
- package/modern/hooks/features/rowSelection/utils.js +1 -1
- package/modern/hooks/features/rows/gridRowsUtils.js +0 -16
- package/modern/hooks/features/rows/useGridRowsMeta.js +33 -17
- package/modern/hooks/features/sorting/gridSortingSelector.js +10 -9
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +43 -27
- package/modern/hooks/utils/useGridNativeEventListener.js +12 -22
- package/modern/hooks/utils/useGridSelector.js +42 -8
- package/modern/hooks/utils/useIsSSR.js +5 -0
- package/modern/index.js +1 -1
- package/modern/internals/index.js +2 -1
- package/modern/locales/plPL.js +31 -35
- package/modern/locales/ukUA.js +9 -10
- package/node/DataGrid/DataGrid.js +6 -0
- package/node/DataGrid/useDataGridComponent.js +3 -3
- package/node/components/GridRow.js +7 -2
- package/node/components/GridScrollArea.js +31 -24
- package/node/components/GridSkeletonLoadingOverlay.js +2 -1
- package/node/components/containers/GridRoot.js +10 -8
- package/node/components/containers/GridRootStyles.js +3 -3
- package/node/components/virtualization/GridMainContainer.js +1 -1
- package/node/components/virtualization/GridVirtualScroller.js +21 -14
- package/node/constants/dataGridPropsDefaultValues.js +1 -0
- package/node/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.js +6 -4
- package/node/hooks/core/useGridStateInitialization.js +3 -2
- package/node/hooks/features/clipboard/useGridClipboard.js +1 -1
- package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +10 -14
- package/node/hooks/features/columns/gridColumnsSelector.js +1 -13
- package/node/hooks/features/dimensions/gridDimensionsSelectors.js +38 -2
- package/node/hooks/features/dimensions/index.js +13 -11
- package/node/hooks/features/dimensions/useGridDimensions.js +94 -67
- package/node/hooks/features/editing/gridEditingSelectors.js +5 -1
- package/node/hooks/features/editing/useGridRowEditing.js +4 -4
- package/node/hooks/features/filter/gridFilterState.js +6 -1
- package/node/hooks/features/filter/useGridFilter.js +5 -12
- package/node/hooks/features/pagination/useGridPagination.js +1 -1
- package/node/hooks/features/pagination/useGridPaginationModel.js +44 -0
- package/node/hooks/features/rowSelection/useGridRowSelection.js +1 -1
- package/node/hooks/features/rowSelection/utils.js +1 -1
- package/node/hooks/features/rows/gridRowsUtils.js +0 -17
- package/node/hooks/features/rows/useGridRowsMeta.js +31 -15
- package/node/hooks/features/sorting/gridSortingSelector.js +10 -9
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +42 -26
- package/node/hooks/utils/useGridNativeEventListener.js +12 -23
- package/node/hooks/utils/useGridSelector.js +42 -8
- package/node/hooks/utils/useIsSSR.js +12 -0
- package/node/index.js +1 -1
- package/node/internals/index.js +20 -7
- package/node/locales/plPL.js +31 -35
- package/node/locales/ukUA.js +9 -10
- package/package.json +3 -2
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useFirstRender } from "../../utils/useFirstRender.js";
|
|
3
|
-
export const useGridRegisterPipeProcessor = (apiRef, group, callback) => {
|
|
3
|
+
export const useGridRegisterPipeProcessor = (apiRef, group, callback, enabled = true) => {
|
|
4
4
|
const cleanup = React.useRef(null);
|
|
5
5
|
const id = React.useRef(`mui-${Math.round(Math.random() * 1e9)}`);
|
|
6
6
|
const registerPreProcessor = React.useCallback(() => {
|
|
7
7
|
cleanup.current = apiRef.current.registerPipeProcessor(group, id.current, callback);
|
|
8
8
|
}, [apiRef, callback, group]);
|
|
9
9
|
useFirstRender(() => {
|
|
10
|
-
|
|
10
|
+
if (enabled) {
|
|
11
|
+
registerPreProcessor();
|
|
12
|
+
}
|
|
11
13
|
});
|
|
12
14
|
const isFirstRender = React.useRef(true);
|
|
13
15
|
React.useEffect(() => {
|
|
14
16
|
if (isFirstRender.current) {
|
|
15
17
|
isFirstRender.current = false;
|
|
16
|
-
} else {
|
|
18
|
+
} else if (enabled) {
|
|
17
19
|
registerPreProcessor();
|
|
18
20
|
}
|
|
19
21
|
return () => {
|
|
@@ -22,5 +24,5 @@ export const useGridRegisterPipeProcessor = (apiRef, group, callback) => {
|
|
|
22
24
|
cleanup.current = null;
|
|
23
25
|
}
|
|
24
26
|
};
|
|
25
|
-
}, [registerPreProcessor]);
|
|
27
|
+
}, [registerPreProcessor, enabled]);
|
|
26
28
|
};
|
|
@@ -4,7 +4,6 @@ import { useGridApiMethod } from "../utils/index.js";
|
|
|
4
4
|
import { isFunction } from "../../utils/utils.js";
|
|
5
5
|
export const useGridStateInitialization = apiRef => {
|
|
6
6
|
const controlStateMapRef = React.useRef({});
|
|
7
|
-
const [, rawForceUpdate] = React.useState();
|
|
8
7
|
const registerControlState = React.useCallback(controlStateItem => {
|
|
9
8
|
controlStateMapRef.current[controlStateItem.stateId] = controlStateItem;
|
|
10
9
|
}, []);
|
|
@@ -79,7 +78,9 @@ export const useGridStateInitialization = apiRef => {
|
|
|
79
78
|
});
|
|
80
79
|
}, reason);
|
|
81
80
|
}, [apiRef]);
|
|
82
|
-
const forceUpdate = React.useCallback(() =>
|
|
81
|
+
const forceUpdate = React.useCallback(() => {
|
|
82
|
+
// @deprecated - do nothing
|
|
83
|
+
}, []);
|
|
83
84
|
const publicStateApi = {
|
|
84
85
|
setState,
|
|
85
86
|
forceUpdate
|
|
@@ -91,6 +91,6 @@ export const useGridClipboard = (apiRef, props) => {
|
|
|
91
91
|
apiRef.current.publishEvent('clipboardCopy', textToCopy);
|
|
92
92
|
}
|
|
93
93
|
}, [apiRef, ignoreValueFormatter, clipboardCopyCellDelimiter]);
|
|
94
|
-
useGridNativeEventListener(apiRef, apiRef.current.rootElementRef, 'keydown', handleCopy);
|
|
94
|
+
useGridNativeEventListener(apiRef, () => apiRef.current.rootElementRef.current, 'keydown', handleCopy);
|
|
95
95
|
useGridApiOptionHandler(apiRef, 'clipboardCopy', props.onClipboardCopy);
|
|
96
96
|
};
|
|
@@ -7,7 +7,7 @@ import { useGridRootProps } from "../../utils/useGridRootProps.js";
|
|
|
7
7
|
import { useGridPrivateApiContext } from "../../utils/useGridPrivateApiContext.js";
|
|
8
8
|
import { useGridApiEventHandler } from "../../utils/useGridApiEventHandler.js";
|
|
9
9
|
import { GridColumnHeaderItem } from "../../../components/columnHeaders/GridColumnHeaderItem.js";
|
|
10
|
-
import {
|
|
10
|
+
import { gridColumnsTotalWidthSelector, gridGroupHeaderHeightSelector, gridHasFillerSelector, gridHeaderHeightSelector, gridVerticalScrollbarWidthSelector } from "../dimensions/gridDimensionsSelectors.js";
|
|
11
11
|
import { gridRenderContextColumnsSelector } from "../virtualization/index.js";
|
|
12
12
|
import { computeOffsetLeft } from "../virtualization/useGridVirtualScroller.js";
|
|
13
13
|
import { GridColumnGroupHeader } from "../../../components/columnHeaders/GridColumnGroupHeader.js";
|
|
@@ -46,19 +46,17 @@ export const useGridColumnHeaders = props => {
|
|
|
46
46
|
const [resizeCol, setResizeCol] = React.useState('');
|
|
47
47
|
const apiRef = useGridPrivateApiContext();
|
|
48
48
|
const rootProps = useGridRootProps();
|
|
49
|
-
const dimensions = useGridSelector(apiRef, gridDimensionsSelector);
|
|
50
49
|
const columnGroupsModel = useGridSelector(apiRef, gridColumnGroupsUnwrappedModelSelector);
|
|
51
50
|
const columnPositions = useGridSelector(apiRef, gridColumnPositionsSelector);
|
|
52
51
|
const renderContext = useGridSelector(apiRef, gridRenderContextColumnsSelector);
|
|
53
52
|
const pinnedColumns = useGridSelector(apiRef, gridVisiblePinnedColumnDefinitionsSelector);
|
|
54
53
|
const columnsLookup = useGridSelector(apiRef, gridColumnLookupSelector);
|
|
55
54
|
const offsetLeft = computeOffsetLeft(columnPositions, renderContext, pinnedColumns.left.length);
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}, [apiRef]);
|
|
55
|
+
const columnsTotalWidth = useGridSelector(apiRef, gridColumnsTotalWidthSelector);
|
|
56
|
+
const gridHasFiller = useGridSelector(apiRef, gridHasFillerSelector);
|
|
57
|
+
const headerHeight = useGridSelector(apiRef, gridHeaderHeightSelector);
|
|
58
|
+
const groupHeaderHeight = useGridSelector(apiRef, gridGroupHeaderHeightSelector);
|
|
59
|
+
const scrollbarWidth = useGridSelector(apiRef, gridVerticalScrollbarWidthSelector);
|
|
62
60
|
const handleColumnResizeStart = React.useCallback(params => setResizeCol(params.field), []);
|
|
63
61
|
const handleColumnResizeStop = React.useCallback(() => setResizeCol(''), []);
|
|
64
62
|
const handleColumnReorderStart = React.useCallback(params => setDragCol(params.field), []);
|
|
@@ -130,8 +128,7 @@ export const useGridColumnHeaders = props => {
|
|
|
130
128
|
const hasFocus = columnHeaderFocus !== null && columnHeaderFocus.field === colDef.field;
|
|
131
129
|
const open = columnMenuState.open && columnMenuState.field === colDef.field;
|
|
132
130
|
const pinnedPosition = params?.position;
|
|
133
|
-
const
|
|
134
|
-
const pinnedOffset = getPinnedCellOffset(pinnedPosition, colDef.computedWidth, columnIndex, columnPositions, dimensions.columnsTotalWidth, scrollbarWidth);
|
|
131
|
+
const pinnedOffset = getPinnedCellOffset(pinnedPosition, colDef.computedWidth, columnIndex, columnPositions, columnsTotalWidth, scrollbarWidth);
|
|
135
132
|
const siblingWithBorderingSeparator = pinnedPosition === PinnedColumnPosition.RIGHT ? renderedColumns[i - 1] : renderedColumns[i + 1];
|
|
136
133
|
const isSiblingFocused = siblingWithBorderingSeparator ? columnHeaderFocus !== null && columnHeaderFocus.field === siblingWithBorderingSeparator.field : false;
|
|
137
134
|
const isLastUnpinned = columnIndex + 1 === columnPositions.length - pinnedColumns.right.length;
|
|
@@ -142,7 +139,7 @@ export const useGridColumnHeaders = props => {
|
|
|
142
139
|
columns.push(/*#__PURE__*/_jsx(GridColumnHeaderItem, _extends({}, sortColumnLookup[colDef.field], {
|
|
143
140
|
columnMenuOpen: open,
|
|
144
141
|
filterItemsCounter: filterColumnLookup[colDef.field] && filterColumnLookup[colDef.field].length,
|
|
145
|
-
headerHeight:
|
|
142
|
+
headerHeight: headerHeight,
|
|
146
143
|
isDragging: colDef.field === dragCol,
|
|
147
144
|
colDef: colDef,
|
|
148
145
|
colIndex: columnIndex,
|
|
@@ -234,8 +231,7 @@ export const useGridColumnHeaders = props => {
|
|
|
234
231
|
tabIndex
|
|
235
232
|
};
|
|
236
233
|
const pinnedPosition = params.position;
|
|
237
|
-
const
|
|
238
|
-
const pinnedOffset = getPinnedCellOffset(pinnedPosition, headerInfo.width, columnIndex, columnPositions, dimensions.columnsTotalWidth, scrollbarWidth);
|
|
234
|
+
const pinnedOffset = getPinnedCellOffset(pinnedPosition, headerInfo.width, columnIndex, columnPositions, columnsTotalWidth, scrollbarWidth);
|
|
239
235
|
columnIndex += columnFields.length;
|
|
240
236
|
let indexInSection = index;
|
|
241
237
|
if (pinnedPosition === PinnedColumnPosition.LEFT) {
|
|
@@ -250,7 +246,7 @@ export const useGridColumnHeaders = props => {
|
|
|
250
246
|
depth: depth,
|
|
251
247
|
isLastColumn: index === visibleColumnGroupHeader.length - 1,
|
|
252
248
|
maxDepth: headerGroupingMaxDepth,
|
|
253
|
-
height:
|
|
249
|
+
height: groupHeaderHeight,
|
|
254
250
|
hasFocus: hasFocus,
|
|
255
251
|
tabIndex: tabIndex,
|
|
256
252
|
pinnedPosition: pinnedPosition,
|
|
@@ -107,18 +107,6 @@ export const gridColumnPositionsSelector = createSelectorMemoized(gridVisibleCol
|
|
|
107
107
|
return positions;
|
|
108
108
|
});
|
|
109
109
|
|
|
110
|
-
/**
|
|
111
|
-
* Get the summed width of all the visible columns.
|
|
112
|
-
* @category Visible Columns
|
|
113
|
-
*/
|
|
114
|
-
export const gridColumnsTotalWidthSelector = createSelector(gridVisibleColumnDefinitionsSelector, gridColumnPositionsSelector, (visibleColumns, positions) => {
|
|
115
|
-
const colCount = visibleColumns.length;
|
|
116
|
-
if (colCount === 0) {
|
|
117
|
-
return 0;
|
|
118
|
-
}
|
|
119
|
-
return positions[colCount - 1] + visibleColumns[colCount - 1].computedWidth;
|
|
120
|
-
});
|
|
121
|
-
|
|
122
110
|
/**
|
|
123
111
|
* Get the filterable columns as an array.
|
|
124
112
|
* @category Columns
|
|
@@ -1 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
import { createSelector } from "../../../utils/createSelector.js";
|
|
2
|
+
export const gridDimensionsSelector = state => state.dimensions;
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Get the summed width of all the visible columns.
|
|
6
|
+
* @category Visible Columns
|
|
7
|
+
*/
|
|
8
|
+
export const gridColumnsTotalWidthSelector = createSelector(gridDimensionsSelector, dimensions => dimensions.columnsTotalWidth);
|
|
9
|
+
export const gridRowHeightSelector = state => state.dimensions.rowHeight;
|
|
10
|
+
export const gridContentHeightSelector = state => state.dimensions.contentSize.height;
|
|
11
|
+
export const gridHasScrollXSelector = state => state.dimensions.hasScrollX;
|
|
12
|
+
export const gridHasScrollYSelector = state => state.dimensions.hasScrollY;
|
|
13
|
+
export const gridHasFillerSelector = state => state.dimensions.columnsTotalWidth < state.dimensions.viewportOuterSize.width;
|
|
14
|
+
export const gridHeaderHeightSelector = state => state.dimensions.headerHeight;
|
|
15
|
+
export const gridGroupHeaderHeightSelector = state => state.dimensions.groupHeaderHeight;
|
|
16
|
+
export const gridHeaderFilterHeightSelector = state => state.dimensions.headerFilterHeight;
|
|
17
|
+
export const gridVerticalScrollbarWidthSelector = state => state.dimensions.hasScrollY ? state.dimensions.scrollbarSize : 0;
|
|
18
|
+
export const gridHorizontalScrollbarHeightSelector = state => state.dimensions.hasScrollX ? state.dimensions.scrollbarSize : 0;
|
|
19
|
+
export const gridHasBottomFillerSelector = state => {
|
|
20
|
+
const height = state.dimensions.hasScrollX ? state.dimensions.scrollbarSize : 0;
|
|
21
|
+
const needsLastRowBorder = state.dimensions.viewportOuterSize.height - state.dimensions.minimumSize.height > 0;
|
|
22
|
+
if (height === 0 && !needsLastRowBorder) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
};
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export {};
|
|
1
|
+
export { gridDimensionsSelector, gridColumnsTotalWidthSelector } from "./gridDimensionsSelectors.js";
|
|
@@ -2,21 +2,23 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { unstable_ownerDocument as ownerDocument, unstable_useEnhancedEffect as useEnhancedEffect, unstable_useEventCallback as useEventCallback, unstable_ownerWindow as ownerWindow } from '@mui/utils';
|
|
4
4
|
import { throttle } from '@mui/x-internals/throttle';
|
|
5
|
-
import {
|
|
5
|
+
import { useGridApiOptionHandler } from "../../utils/useGridApiEventHandler.js";
|
|
6
6
|
import { useGridApiMethod } from "../../utils/useGridApiMethod.js";
|
|
7
|
+
import { createSelector } from "../../../utils/createSelector.js";
|
|
7
8
|
import { useGridLogger } from "../../utils/useGridLogger.js";
|
|
8
|
-
import {
|
|
9
|
+
import { gridColumnPositionsSelector, gridVisibleColumnDefinitionsSelector, gridVisiblePinnedColumnDefinitionsSelector } from "../columns/index.js";
|
|
9
10
|
import { gridDimensionsSelector } from "./gridDimensionsSelectors.js";
|
|
10
11
|
import { gridDensityFactorSelector } from "../density/index.js";
|
|
11
12
|
import { gridRenderContextSelector } from "../virtualization/index.js";
|
|
12
13
|
import { useGridSelector } from "../../utils/index.js";
|
|
13
14
|
import { getVisibleRows } from "../../utils/useGridVisibleRows.js";
|
|
14
15
|
import { gridRowsMetaSelector } from "../rows/gridRowsMetaSelector.js";
|
|
15
|
-
import {
|
|
16
|
+
import { getValidRowHeight, rowHeightWarning } from "../rows/gridRowsUtils.js";
|
|
16
17
|
import { getTotalHeaderHeight } from "../columns/gridColumnsUtils.js";
|
|
17
18
|
import { DATA_GRID_PROPS_DEFAULT_VALUES } from "../../../constants/dataGridPropsDefaultValues.js";
|
|
18
19
|
import { roundToDecimalPlaces } from "../../../utils/roundToDecimalPlaces.js";
|
|
19
20
|
import { isJSDOM } from "../../../utils/isJSDOM.js";
|
|
21
|
+
import { isDeepEqual } from "../../../utils/utils.js";
|
|
20
22
|
const EMPTY_SIZE = {
|
|
21
23
|
width: 0,
|
|
22
24
|
height: 0
|
|
@@ -43,39 +45,47 @@ const EMPTY_DIMENSIONS = {
|
|
|
43
45
|
topContainerHeight: 0,
|
|
44
46
|
bottomContainerHeight: 0
|
|
45
47
|
};
|
|
46
|
-
export const dimensionsStateInitializer = state => {
|
|
48
|
+
export const dimensionsStateInitializer = (state, props, apiRef) => {
|
|
47
49
|
const dimensions = EMPTY_DIMENSIONS;
|
|
50
|
+
const density = gridDensityFactorSelector(apiRef);
|
|
48
51
|
return _extends({}, state, {
|
|
49
|
-
dimensions
|
|
52
|
+
dimensions: _extends({}, dimensions, getStaticDimensions(props, apiRef, density, gridVisiblePinnedColumnDefinitionsSelector(apiRef)))
|
|
50
53
|
});
|
|
51
54
|
};
|
|
55
|
+
const columnsTotalWidthSelector = createSelector(gridVisibleColumnDefinitionsSelector, gridColumnPositionsSelector, (visibleColumns, positions) => {
|
|
56
|
+
const colCount = visibleColumns.length;
|
|
57
|
+
if (colCount === 0) {
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
60
|
+
return roundToDecimalPlaces(positions[colCount - 1] + visibleColumns[colCount - 1].computedWidth, 1);
|
|
61
|
+
});
|
|
52
62
|
export function useGridDimensions(apiRef, props) {
|
|
53
63
|
const logger = useGridLogger(apiRef, 'useResizeContainer');
|
|
54
64
|
const errorShown = React.useRef(false);
|
|
55
65
|
const rootDimensionsRef = React.useRef(EMPTY_SIZE);
|
|
56
|
-
const dimensionsState = useGridSelector(apiRef, gridDimensionsSelector);
|
|
57
|
-
const rowsMeta = useGridSelector(apiRef, gridRowsMetaSelector);
|
|
58
66
|
const pinnedColumns = useGridSelector(apiRef, gridVisiblePinnedColumnDefinitionsSelector);
|
|
59
67
|
const densityFactor = useGridSelector(apiRef, gridDensityFactorSelector);
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
React.useEffect(() => debouncedSetSavedSize.clear, [debouncedSetSavedSize]);
|
|
68
|
+
const columnsTotalWidth = useGridSelector(apiRef, columnsTotalWidthSelector);
|
|
69
|
+
const isFirstSizing = React.useRef(true);
|
|
70
|
+
const {
|
|
71
|
+
rowHeight,
|
|
72
|
+
headerHeight,
|
|
73
|
+
groupHeaderHeight,
|
|
74
|
+
headerFilterHeight,
|
|
75
|
+
headersTotalHeight,
|
|
76
|
+
leftPinnedWidth,
|
|
77
|
+
rightPinnedWidth
|
|
78
|
+
} = getStaticDimensions(props, apiRef, densityFactor, pinnedColumns);
|
|
72
79
|
const previousSize = React.useRef(undefined);
|
|
73
|
-
const getRootDimensions = () => apiRef.current.state
|
|
74
|
-
const setDimensions =
|
|
80
|
+
const getRootDimensions = React.useCallback(() => gridDimensionsSelector(apiRef.current.state), [apiRef]);
|
|
81
|
+
const setDimensions = React.useCallback(dimensions => {
|
|
75
82
|
apiRef.current.setState(state => _extends({}, state, {
|
|
76
83
|
dimensions
|
|
77
84
|
}));
|
|
78
|
-
|
|
85
|
+
if (apiRef.current.rootElementRef.current) {
|
|
86
|
+
setCSSVariables(apiRef.current.rootElementRef.current, gridDimensionsSelector(apiRef.current.state));
|
|
87
|
+
}
|
|
88
|
+
}, [apiRef]);
|
|
79
89
|
const resize = React.useCallback(() => {
|
|
80
90
|
const element = apiRef.current.mainElementRef.current;
|
|
81
91
|
if (!element) {
|
|
@@ -96,10 +106,7 @@ export function useGridDimensions(apiRef, props) {
|
|
|
96
106
|
if (!dimensions.isReady) {
|
|
97
107
|
return 0;
|
|
98
108
|
}
|
|
99
|
-
const currentPage = getVisibleRows(apiRef
|
|
100
|
-
pagination: props.pagination,
|
|
101
|
-
paginationMode: props.paginationMode
|
|
102
|
-
});
|
|
109
|
+
const currentPage = getVisibleRows(apiRef);
|
|
103
110
|
|
|
104
111
|
// TODO: Use a combination of scrollTop, dimensions.viewportInnerSize.height and rowsMeta.possitions
|
|
105
112
|
// to find out the maximum number of rows that can fit in the visible part of the grid
|
|
@@ -110,16 +117,19 @@ export function useGridDimensions(apiRef, props) {
|
|
|
110
117
|
}
|
|
111
118
|
const maximumPageSizeWithoutScrollBar = Math.floor(dimensions.viewportInnerSize.height / rowHeight);
|
|
112
119
|
return Math.min(maximumPageSizeWithoutScrollBar, currentPage.rows.length);
|
|
113
|
-
}, [apiRef, props.
|
|
120
|
+
}, [apiRef, props.getRowHeight, rowHeight]);
|
|
114
121
|
const updateDimensions = React.useCallback(() => {
|
|
122
|
+
if (isFirstSizing.current) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
115
125
|
// All the floating point dimensions should be rounded to .1 decimal places to avoid subpixel rendering issues
|
|
116
126
|
// https://github.com/mui/mui-x/issues/9550#issuecomment-1619020477
|
|
117
127
|
// https://github.com/mui/mui-x/issues/15721
|
|
118
128
|
const rootElement = apiRef.current.rootElementRef.current;
|
|
119
|
-
const
|
|
120
|
-
const
|
|
121
|
-
const topContainerHeight = headersTotalHeight +
|
|
122
|
-
const bottomContainerHeight =
|
|
129
|
+
const scrollbarSize = measureScrollbarSize(rootElement, props.scrollbarSize);
|
|
130
|
+
const rowsMeta = gridRowsMetaSelector(apiRef.current.state);
|
|
131
|
+
const topContainerHeight = headersTotalHeight + rowsMeta.pinnedTopRowsTotalHeight;
|
|
132
|
+
const bottomContainerHeight = rowsMeta.pinnedBottomRowsTotalHeight;
|
|
123
133
|
const nonPinnedColumnsTotalWidth = columnsTotalWidth - leftPinnedWidth - rightPinnedWidth;
|
|
124
134
|
const contentSize = {
|
|
125
135
|
width: nonPinnedColumnsTotalWidth,
|
|
@@ -197,12 +207,21 @@ export function useGridDimensions(apiRef, props) {
|
|
|
197
207
|
bottomContainerHeight
|
|
198
208
|
};
|
|
199
209
|
const prevDimensions = apiRef.current.state.dimensions;
|
|
210
|
+
if (isDeepEqual(prevDimensions, newDimensions)) {
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
200
213
|
setDimensions(newDimensions);
|
|
201
214
|
if (!areElementSizesEqual(newDimensions.viewportInnerSize, prevDimensions.viewportInnerSize)) {
|
|
202
215
|
apiRef.current.publishEvent('viewportInnerSizeChange', newDimensions.viewportInnerSize);
|
|
203
216
|
}
|
|
204
217
|
apiRef.current.updateRenderContext?.();
|
|
205
|
-
}, [apiRef, setDimensions, props.scrollbarSize, props.autoHeight,
|
|
218
|
+
}, [apiRef, setDimensions, props.scrollbarSize, props.autoHeight, rowHeight, headerHeight, groupHeaderHeight, headerFilterHeight, columnsTotalWidth, headersTotalHeight, leftPinnedWidth, rightPinnedWidth]);
|
|
219
|
+
const updateDimensionCallback = useEventCallback(updateDimensions);
|
|
220
|
+
const debouncedUpdateDimensions = React.useMemo(() => props.resizeThrottleMs > 0 ? throttle(() => {
|
|
221
|
+
updateDimensionCallback();
|
|
222
|
+
apiRef.current.publishEvent('debouncedResize', rootDimensionsRef.current);
|
|
223
|
+
}, props.resizeThrottleMs) : undefined, [apiRef, props.resizeThrottleMs, updateDimensionCallback]);
|
|
224
|
+
React.useEffect(() => debouncedUpdateDimensions?.clear, [debouncedUpdateDimensions]);
|
|
206
225
|
const apiPublic = {
|
|
207
226
|
resize,
|
|
208
227
|
getRootDimensions
|
|
@@ -211,35 +230,12 @@ export function useGridDimensions(apiRef, props) {
|
|
|
211
230
|
updateDimensions,
|
|
212
231
|
getViewportPageSize
|
|
213
232
|
};
|
|
233
|
+
useEnhancedEffect(updateDimensions, [updateDimensions]);
|
|
214
234
|
useGridApiMethod(apiRef, apiPublic, 'public');
|
|
215
235
|
useGridApiMethod(apiRef, apiPrivate, 'private');
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
apiRef.current.publishEvent('debouncedResize', rootDimensionsRef.current);
|
|
220
|
-
}
|
|
221
|
-
}, [apiRef, savedSize, updateDimensions]);
|
|
222
|
-
const root = apiRef.current.rootElementRef.current;
|
|
223
|
-
useEnhancedEffect(() => {
|
|
224
|
-
if (!root) {
|
|
225
|
-
return;
|
|
226
|
-
}
|
|
227
|
-
const set = (k, v) => root.style.setProperty(k, v);
|
|
228
|
-
set('--DataGrid-width', `${dimensionsState.viewportOuterSize.width}px`);
|
|
229
|
-
set('--DataGrid-hasScrollX', `${Number(dimensionsState.hasScrollX)}`);
|
|
230
|
-
set('--DataGrid-hasScrollY', `${Number(dimensionsState.hasScrollY)}`);
|
|
231
|
-
set('--DataGrid-scrollbarSize', `${dimensionsState.scrollbarSize}px`);
|
|
232
|
-
set('--DataGrid-rowWidth', `${dimensionsState.rowWidth}px`);
|
|
233
|
-
set('--DataGrid-columnsTotalWidth', `${dimensionsState.columnsTotalWidth}px`);
|
|
234
|
-
set('--DataGrid-leftPinnedWidth', `${dimensionsState.leftPinnedWidth}px`);
|
|
235
|
-
set('--DataGrid-rightPinnedWidth', `${dimensionsState.rightPinnedWidth}px`);
|
|
236
|
-
set('--DataGrid-headerHeight', `${dimensionsState.headerHeight}px`);
|
|
237
|
-
set('--DataGrid-headersTotalHeight', `${dimensionsState.headersTotalHeight}px`);
|
|
238
|
-
set('--DataGrid-topContainerHeight', `${dimensionsState.topContainerHeight}px`);
|
|
239
|
-
set('--DataGrid-bottomContainerHeight', `${dimensionsState.bottomContainerHeight}px`);
|
|
240
|
-
set('--height', `${dimensionsState.rowHeight}px`);
|
|
241
|
-
}, [root, dimensionsState]);
|
|
242
|
-
const isFirstSizing = React.useRef(true);
|
|
236
|
+
const handleRootMount = React.useCallback(root => {
|
|
237
|
+
setCSSVariables(root, gridDimensionsSelector(apiRef.current.state));
|
|
238
|
+
}, [apiRef]);
|
|
243
239
|
const handleResize = React.useCallback(size => {
|
|
244
240
|
rootDimensionsRef.current = size;
|
|
245
241
|
if (size.height === 0 && !errorShown.current && !props.autoHeight && !isJSDOM) {
|
|
@@ -250,28 +246,58 @@ export function useGridDimensions(apiRef, props) {
|
|
|
250
246
|
logger.error(['The parent DOM element of the Data Grid has an empty width.', 'Please make sure that this element has an intrinsic width.', 'The grid displays with a width of 0px.', '', 'More details: https://mui.com/r/x-data-grid-no-dimensions.'].join('\n'));
|
|
251
247
|
errorShown.current = true;
|
|
252
248
|
}
|
|
253
|
-
if (isFirstSizing.current) {
|
|
249
|
+
if (isFirstSizing.current || !debouncedUpdateDimensions) {
|
|
254
250
|
// We want to initialize the grid dimensions as soon as possible to avoid flickering
|
|
255
|
-
setSavedSize(size);
|
|
256
251
|
isFirstSizing.current = false;
|
|
252
|
+
updateDimensions();
|
|
257
253
|
return;
|
|
258
254
|
}
|
|
259
|
-
|
|
260
|
-
}, [props.autoHeight,
|
|
261
|
-
|
|
262
|
-
useGridApiOptionHandler(apiRef, '
|
|
263
|
-
useGridApiOptionHandler(apiRef, 'paginationModelChange', updateDimensions);
|
|
264
|
-
useGridApiOptionHandler(apiRef, 'columnsChange', updateDimensions);
|
|
265
|
-
useGridApiEventHandler(apiRef, 'resize', handleResize);
|
|
255
|
+
debouncedUpdateDimensions();
|
|
256
|
+
}, [updateDimensions, props.autoHeight, debouncedUpdateDimensions, logger]);
|
|
257
|
+
useGridApiOptionHandler(apiRef, 'rootMount', handleRootMount);
|
|
258
|
+
useGridApiOptionHandler(apiRef, 'resize', handleResize);
|
|
266
259
|
useGridApiOptionHandler(apiRef, 'debouncedResize', props.onResize);
|
|
267
260
|
}
|
|
268
|
-
function
|
|
261
|
+
function setCSSVariables(root, dimensions) {
|
|
262
|
+
const set = (k, v) => root.style.setProperty(k, v);
|
|
263
|
+
set('--DataGrid-hasScrollX', `${Number(dimensions.hasScrollX)}`);
|
|
264
|
+
set('--DataGrid-hasScrollY', `${Number(dimensions.hasScrollY)}`);
|
|
265
|
+
set('--DataGrid-scrollbarSize', `${dimensions.scrollbarSize}px`);
|
|
266
|
+
set('--DataGrid-rowWidth', `${dimensions.rowWidth}px`);
|
|
267
|
+
set('--DataGrid-columnsTotalWidth', `${dimensions.columnsTotalWidth}px`);
|
|
268
|
+
set('--DataGrid-leftPinnedWidth', `${dimensions.leftPinnedWidth}px`);
|
|
269
|
+
set('--DataGrid-rightPinnedWidth', `${dimensions.rightPinnedWidth}px`);
|
|
270
|
+
set('--DataGrid-headerHeight', `${dimensions.headerHeight}px`);
|
|
271
|
+
set('--DataGrid-headersTotalHeight', `${dimensions.headersTotalHeight}px`);
|
|
272
|
+
set('--DataGrid-topContainerHeight', `${dimensions.topContainerHeight}px`);
|
|
273
|
+
set('--DataGrid-bottomContainerHeight', `${dimensions.bottomContainerHeight}px`);
|
|
274
|
+
set('--height', `${dimensions.rowHeight}px`);
|
|
275
|
+
}
|
|
276
|
+
function getStaticDimensions(props, apiRef, density, pinnedColumnns) {
|
|
277
|
+
const validRowHeight = getValidRowHeight(props.rowHeight, DATA_GRID_PROPS_DEFAULT_VALUES.rowHeight, rowHeightWarning);
|
|
278
|
+
return {
|
|
279
|
+
rowHeight: Math.floor(validRowHeight * density),
|
|
280
|
+
headerHeight: Math.floor(props.columnHeaderHeight * density),
|
|
281
|
+
groupHeaderHeight: Math.floor((props.columnGroupHeaderHeight ?? props.columnHeaderHeight) * density),
|
|
282
|
+
headerFilterHeight: Math.floor((props.headerFilterHeight ?? props.columnHeaderHeight) * density),
|
|
283
|
+
columnsTotalWidth: columnsTotalWidthSelector(apiRef),
|
|
284
|
+
headersTotalHeight: getTotalHeaderHeight(apiRef, props),
|
|
285
|
+
leftPinnedWidth: pinnedColumnns.left.reduce((w, col) => w + col.computedWidth, 0),
|
|
286
|
+
rightPinnedWidth: pinnedColumnns.right.reduce((w, col) => w + col.computedWidth, 0)
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
const scrollbarSizeCache = new WeakMap();
|
|
290
|
+
function measureScrollbarSize(rootElement, scrollbarSize) {
|
|
269
291
|
if (scrollbarSize !== undefined) {
|
|
270
292
|
return scrollbarSize;
|
|
271
293
|
}
|
|
272
|
-
if (rootElement === null
|
|
294
|
+
if (rootElement === null) {
|
|
273
295
|
return 0;
|
|
274
296
|
}
|
|
297
|
+
const cachedSize = scrollbarSizeCache.get(rootElement);
|
|
298
|
+
if (cachedSize !== undefined) {
|
|
299
|
+
return cachedSize;
|
|
300
|
+
}
|
|
275
301
|
const doc = ownerDocument(rootElement);
|
|
276
302
|
const scrollDiv = doc.createElement('div');
|
|
277
303
|
scrollDiv.style.width = '99px';
|
|
@@ -282,6 +308,7 @@ function measureScrollbarSize(rootElement, columnsTotalWidth, scrollbarSize) {
|
|
|
282
308
|
rootElement.appendChild(scrollDiv);
|
|
283
309
|
const size = scrollDiv.offsetWidth - scrollDiv.clientWidth;
|
|
284
310
|
rootElement.removeChild(scrollDiv);
|
|
311
|
+
scrollbarSizeCache.set(rootElement, size);
|
|
285
312
|
return size;
|
|
286
313
|
}
|
|
287
314
|
function areElementSizesEqual(a, b) {
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { createSelectorV8 } from "../../../utils/createSelector.js";
|
|
2
|
+
import { GridEditModes } from "../../../models/gridEditRowModel.js";
|
|
3
|
+
|
|
2
4
|
/**
|
|
3
5
|
* Select the row editing state.
|
|
4
6
|
*/
|
|
5
7
|
export const gridEditRowsStateSelector = state => state.editRows;
|
|
6
|
-
export const gridRowIsEditingSelector = createSelectorV8(gridEditRowsStateSelector, (editRows,
|
|
8
|
+
export const gridRowIsEditingSelector = createSelectorV8(gridEditRowsStateSelector, (editRows, {
|
|
9
|
+
rowId,
|
|
10
|
+
editMode
|
|
11
|
+
}) => editMode === GridEditModes.Row && Boolean(editRows[rowId]));
|
|
7
12
|
export const gridEditCellStateSelector = createSelectorV8(gridEditRowsStateSelector, (editRows, {
|
|
8
13
|
rowId,
|
|
9
14
|
field
|
|
@@ -232,10 +232,10 @@ export const useGridRowEditing = (apiRef, props) => {
|
|
|
232
232
|
useGridApiOptionHandler(apiRef, 'rowEditStart', props.onRowEditStart);
|
|
233
233
|
useGridApiOptionHandler(apiRef, 'rowEditStop', props.onRowEditStop);
|
|
234
234
|
const getRowMode = React.useCallback(id => {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
235
|
+
const isEditing = gridRowIsEditingSelector(apiRef, {
|
|
236
|
+
rowId: id,
|
|
237
|
+
editMode: props.editMode
|
|
238
|
+
});
|
|
239
239
|
return isEditing ? GridRowModes.Edit : GridRowModes.View;
|
|
240
240
|
}, [apiRef, props.editMode]);
|
|
241
241
|
const updateRowModesModel = useEventCallback(newModel => {
|
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { GridLogicOperator } from "../../../models/gridFilterItem.js";
|
|
2
|
+
export const defaultGridFilterLookup = {
|
|
3
|
+
filteredRowsLookup: {},
|
|
4
|
+
filteredChildrenCountLookup: {},
|
|
5
|
+
filteredDescendantCountLookup: {}
|
|
6
|
+
};
|
|
2
7
|
export const getDefaultGridFilterModel = () => ({
|
|
3
8
|
items: [],
|
|
4
9
|
logicOperator: GridLogicOperator.And,
|
|
@@ -8,7 +8,7 @@ import { useGridApiMethod } from "../../utils/useGridApiMethod.js";
|
|
|
8
8
|
import { useGridLogger } from "../../utils/useGridLogger.js";
|
|
9
9
|
import { gridColumnLookupSelector } from "../columns/gridColumnsSelector.js";
|
|
10
10
|
import { GridPreferencePanelsValue } from "../preferencesPanel/gridPreferencePanelsValue.js";
|
|
11
|
-
import { getDefaultGridFilterModel } from "./gridFilterState.js";
|
|
11
|
+
import { defaultGridFilterLookup, getDefaultGridFilterModel } from "./gridFilterState.js";
|
|
12
12
|
import { gridFilterModelSelector } from "./gridFilterSelector.js";
|
|
13
13
|
import { useFirstRender } from "../../utils/useFirstRender.js";
|
|
14
14
|
import { gridRowsLookupSelector } from "../rows/index.js";
|
|
@@ -20,12 +20,9 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
20
20
|
export const filterStateInitializer = (state, props, apiRef) => {
|
|
21
21
|
const filterModel = props.filterModel ?? props.initialState?.filter?.filterModel ?? getDefaultGridFilterModel();
|
|
22
22
|
return _extends({}, state, {
|
|
23
|
-
filter: {
|
|
24
|
-
filterModel: sanitizeFilterModel(filterModel, props.disableMultipleColumnsFiltering, apiRef)
|
|
25
|
-
|
|
26
|
-
filteredChildrenCountLookup: {},
|
|
27
|
-
filteredDescendantCountLookup: {}
|
|
28
|
-
},
|
|
23
|
+
filter: _extends({
|
|
24
|
+
filterModel: sanitizeFilterModel(filterModel, props.disableMultipleColumnsFiltering, apiRef)
|
|
25
|
+
}, defaultGridFilterLookup),
|
|
29
26
|
visibleRowsLookup: {}
|
|
30
27
|
});
|
|
31
28
|
};
|
|
@@ -271,12 +268,8 @@ export const useGridFilter = (apiRef, props) => {
|
|
|
271
268
|
} = props;
|
|
272
269
|
const getRowsRef = useLazyRef(createMemoizedValues);
|
|
273
270
|
const flatFilteringMethod = React.useCallback(params => {
|
|
274
|
-
if (props.filterMode !== 'client' || !params.isRowMatchingFilters) {
|
|
275
|
-
return
|
|
276
|
-
filteredRowsLookup: {},
|
|
277
|
-
filteredChildrenCountLookup: {},
|
|
278
|
-
filteredDescendantCountLookup: {}
|
|
279
|
-
};
|
|
271
|
+
if (props.filterMode !== 'client' || !params.isRowMatchingFilters || !params.filterModel.items.length && !params.filterModel.quickFilterValues?.length) {
|
|
272
|
+
return defaultGridFilterLookup;
|
|
280
273
|
}
|
|
281
274
|
const dataRowIdToModelLookup = gridRowsLookupSelector(apiRef);
|
|
282
275
|
const filteredRowsLookup = {};
|
|
@@ -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, {
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
import { gridFilterModelSelector, gridFilterActiveItemsSelector } from "../filter/gridFilterSelector.js";
|
|
3
4
|
import { gridDensityFactorSelector } from "../density/index.js";
|
|
4
5
|
import { useGridLogger, useGridSelector, useGridApiMethod, useGridApiEventHandler } from "../../utils/index.js";
|
|
6
|
+
import { isDeepEqual, runIf } from "../../../utils/utils.js";
|
|
5
7
|
import { useGridRegisterPipeProcessor } from "../../core/pipeProcessing/index.js";
|
|
6
8
|
import { gridPageCountSelector, gridPaginationModelSelector } from "./gridPaginationSelector.js";
|
|
7
9
|
import { getPageCount, defaultPageSize, throwIfPageSizeExceedsTheLimit, getDefaultGridPaginationModel, getValidPage } from "./gridPaginationUtils.js";
|
|
@@ -31,6 +33,7 @@ export const getDerivedPaginationModel = (paginationState, signature, pagination
|
|
|
31
33
|
export const useGridPaginationModel = (apiRef, props) => {
|
|
32
34
|
const logger = useGridLogger(apiRef, 'useGridPaginationModel');
|
|
33
35
|
const densityFactor = useGridSelector(apiRef, gridDensityFactorSelector);
|
|
36
|
+
const previousFilterModel = React.useRef(gridFilterModelSelector(apiRef));
|
|
34
37
|
const rowHeight = Math.floor(props.rowHeight * densityFactor);
|
|
35
38
|
apiRef.current.registerControlState({
|
|
36
39
|
stateId: 'paginationModel',
|
|
@@ -143,14 +146,55 @@ export const useGridPaginationModel = (apiRef, props) => {
|
|
|
143
146
|
return;
|
|
144
147
|
}
|
|
145
148
|
const paginationModel = gridPaginationModelSelector(apiRef);
|
|
149
|
+
if (paginationModel.page === 0) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
146
152
|
const pageCount = gridPageCountSelector(apiRef);
|
|
147
153
|
if (paginationModel.page > pageCount - 1) {
|
|
148
154
|
apiRef.current.setPage(Math.max(0, pageCount - 1));
|
|
149
155
|
}
|
|
150
156
|
}, [apiRef]);
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Goes to the first row of the grid
|
|
160
|
+
*/
|
|
161
|
+
const navigateToStart = React.useCallback(() => {
|
|
162
|
+
const paginationModel = gridPaginationModelSelector(apiRef);
|
|
163
|
+
if (paginationModel.page !== 0) {
|
|
164
|
+
apiRef.current.setPage(0);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// If the page was not changed it might be needed to scroll to the top
|
|
168
|
+
const scrollPosition = apiRef.current.getScrollPosition();
|
|
169
|
+
if (scrollPosition.top !== 0) {
|
|
170
|
+
apiRef.current.scroll({
|
|
171
|
+
top: 0
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}, [apiRef]);
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Resets the page only if the active items or quick filter has changed from the last time.
|
|
178
|
+
* This is to avoid resetting the page when the filter model is changed
|
|
179
|
+
* because of and update of the operator from an item that does not have the value
|
|
180
|
+
* or reseting when the filter panel is just opened
|
|
181
|
+
*/
|
|
182
|
+
const handleFilterModelChange = React.useCallback(filterModel => {
|
|
183
|
+
const currentActiveFilters = _extends({}, filterModel, {
|
|
184
|
+
// replace items with the active items
|
|
185
|
+
items: gridFilterActiveItemsSelector(apiRef)
|
|
186
|
+
});
|
|
187
|
+
if (isDeepEqual(currentActiveFilters, previousFilterModel.current)) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
previousFilterModel.current = currentActiveFilters;
|
|
191
|
+
navigateToStart();
|
|
192
|
+
}, [apiRef, navigateToStart]);
|
|
151
193
|
useGridApiEventHandler(apiRef, 'viewportInnerSizeChange', handleUpdateAutoPageSize);
|
|
152
194
|
useGridApiEventHandler(apiRef, 'paginationModelChange', handlePaginationModelChange);
|
|
153
195
|
useGridApiEventHandler(apiRef, 'rowCountChange', handleRowCountChange);
|
|
196
|
+
useGridApiEventHandler(apiRef, 'sortModelChange', runIf(props.resetPageOnSortFilter, navigateToStart));
|
|
197
|
+
useGridApiEventHandler(apiRef, 'filterModelChange', runIf(props.resetPageOnSortFilter, handleFilterModelChange));
|
|
154
198
|
|
|
155
199
|
/**
|
|
156
200
|
* EFFECTS
|
|
@@ -258,7 +258,7 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
258
258
|
if (props.filterMode === 'server') {
|
|
259
259
|
return !rowsLookup[id];
|
|
260
260
|
}
|
|
261
|
-
return filteredRowsLookup[id]
|
|
261
|
+
return !rowsLookup[id] || filteredRowsLookup[id] === false;
|
|
262
262
|
};
|
|
263
263
|
let hasChanged = false;
|
|
264
264
|
currentSelection.forEach(id => {
|