@mui/x-data-grid 6.20.1 → 6.20.4
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 +63 -0
- package/DataGrid/DataGrid.js +5 -0
- package/components/GridPagination.js +2 -7
- package/components/panel/GridPanel.js +4 -1
- package/hooks/features/export/useGridPrintExport.js +8 -4
- package/hooks/features/pagination/gridPaginationInterfaces.d.ts +19 -2
- package/hooks/features/pagination/gridPaginationSelector.d.ts +5 -0
- package/hooks/features/pagination/gridPaginationSelector.js +8 -2
- package/hooks/features/pagination/useGridPagination.d.ts +1 -6
- package/hooks/features/pagination/useGridPagination.js +9 -159
- package/hooks/features/pagination/useGridPaginationModel.d.ts +11 -0
- package/hooks/features/pagination/useGridPaginationModel.js +176 -0
- package/hooks/features/pagination/useGridRowCount.d.ts +8 -0
- package/hooks/features/pagination/useGridRowCount.js +97 -0
- package/index.js +1 -1
- package/legacy/DataGrid/DataGrid.js +5 -0
- package/legacy/components/GridPagination.js +2 -7
- package/legacy/components/panel/GridPanel.js +4 -1
- package/legacy/hooks/features/export/useGridPrintExport.js +10 -4
- package/legacy/hooks/features/pagination/gridPaginationSelector.js +11 -3
- package/legacy/hooks/features/pagination/useGridPagination.js +9 -161
- package/legacy/hooks/features/pagination/useGridPaginationModel.js +182 -0
- package/legacy/hooks/features/pagination/useGridRowCount.js +101 -0
- package/legacy/index.js +1 -1
- package/models/events/gridEventLookup.d.ts +6 -0
- package/models/props/DataGridProps.d.ts +5 -0
- package/modern/DataGrid/DataGrid.js +5 -0
- package/modern/components/GridPagination.js +2 -4
- package/modern/components/panel/GridPanel.js +4 -1
- package/modern/hooks/features/export/useGridPrintExport.js +8 -4
- package/modern/hooks/features/pagination/gridPaginationSelector.js +8 -2
- package/modern/hooks/features/pagination/useGridPagination.js +8 -151
- package/modern/hooks/features/pagination/useGridPaginationModel.js +171 -0
- package/modern/hooks/features/pagination/useGridRowCount.js +94 -0
- package/modern/index.js +1 -1
- package/node/DataGrid/DataGrid.js +5 -0
- package/node/components/GridPagination.js +1 -3
- package/node/components/panel/GridPanel.js +4 -1
- package/node/hooks/features/export/useGridPrintExport.js +8 -4
- package/node/hooks/features/pagination/gridPaginationSelector.js +8 -2
- package/node/hooks/features/pagination/useGridPagination.js +9 -155
- package/node/hooks/features/pagination/useGridPaginationModel.js +182 -0
- package/node/hooks/features/pagination/useGridRowCount.js +103 -0
- package/node/index.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,69 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 6.20.4
|
|
7
|
+
|
|
8
|
+
_Jul 18, 2024_
|
|
9
|
+
|
|
10
|
+
We'd like to offer a big thanks to the 1 contributors who made this release possible. Here are some highlights ✨:
|
|
11
|
+
|
|
12
|
+
- 🐞 Bugfixes
|
|
13
|
+
|
|
14
|
+
### Data Grid
|
|
15
|
+
|
|
16
|
+
#### `@mui/x-data-grid@6.20.4`
|
|
17
|
+
|
|
18
|
+
- [DataGrid] Enable flip on preferences panel (#13812) @romgrk
|
|
19
|
+
|
|
20
|
+
#### `@mui/x-data-grid-pro@6.20.4` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
21
|
+
|
|
22
|
+
Same changes as in `@mui/x-data-grid@6.20.4`.
|
|
23
|
+
|
|
24
|
+
#### `@mui/x-data-grid-premium@6.20.4` [](https://mui.com/r/x-premium-svg-link 'Premium plan')
|
|
25
|
+
|
|
26
|
+
Same changes as in `@mui/x-data-grid-pro@6.20.4`.
|
|
27
|
+
|
|
28
|
+
## v6.20.3
|
|
29
|
+
|
|
30
|
+
_Jun 28, 2024_
|
|
31
|
+
|
|
32
|
+
We'd like to offer a big thanks to the 2 contributors who made this release possible. Here are some highlights ✨:
|
|
33
|
+
|
|
34
|
+
- 🐞 Bugfixes
|
|
35
|
+
|
|
36
|
+
### Data Grid
|
|
37
|
+
|
|
38
|
+
#### `@mui/x-data-grid@6.20.3`
|
|
39
|
+
|
|
40
|
+
- [DataGrid] Make `rowCount` part of the state (#12406) @MBilalShafi
|
|
41
|
+
|
|
42
|
+
#### `@mui/x-data-grid-pro@6.20.3` [](https://mui.com/r/x-pro-svg-link 'Pro plan')
|
|
43
|
+
|
|
44
|
+
Same changes as in `@mui/x-data-grid@6.20.3`.
|
|
45
|
+
|
|
46
|
+
#### `@mui/x-data-grid-premium@6.20.3` [](https://mui.com/r/x-premium-svg-link 'Premium plan')
|
|
47
|
+
|
|
48
|
+
Same changes as in `@mui/x-data-grid-pro@6.20.3`.
|
|
49
|
+
|
|
50
|
+
### Core
|
|
51
|
+
|
|
52
|
+
- [core] Update release readme with `pnpm` notice (#13577) @LukasTy
|
|
53
|
+
|
|
54
|
+
## 6.20.2
|
|
55
|
+
|
|
56
|
+
_Jun 20, 2024_
|
|
57
|
+
|
|
58
|
+
We'd like to offer a big thanks to the 2 contributors who made this release possible. Here are some highlights ✨:
|
|
59
|
+
|
|
60
|
+
- 🐞 Bugfixes
|
|
61
|
+
|
|
62
|
+
### Date Pickers
|
|
63
|
+
|
|
64
|
+
#### `@mui/x-date-pickers@6.20.2`
|
|
65
|
+
|
|
66
|
+
- [fields] Do not apply digit editing when pressing `Space` (#13516) @flaviendelangle
|
|
67
|
+
- [pickers] Fix controlled `view` behavior (#13559) @LukasTy
|
|
68
|
+
|
|
6
69
|
## 6.20.1
|
|
7
70
|
|
|
8
71
|
_Jun 6, 2024_
|
package/DataGrid/DataGrid.js
CHANGED
|
@@ -495,6 +495,11 @@ DataGridRaw.propTypes = {
|
|
|
495
495
|
* @param {GridCallbackDetails} details Additional details for this callback.
|
|
496
496
|
*/
|
|
497
497
|
onRowClick: PropTypes.func,
|
|
498
|
+
/**
|
|
499
|
+
* Callback fired when the row count has changed.
|
|
500
|
+
* @param {number} count Updated row count.
|
|
501
|
+
*/
|
|
502
|
+
onRowCountChange: PropTypes.func,
|
|
498
503
|
/**
|
|
499
504
|
* Callback fired when a double click event comes from a row container element.
|
|
500
505
|
* @param {GridRowParams} params With all properties from [[RowParams]].
|
|
@@ -6,8 +6,7 @@ import { styled } from '@mui/material/styles';
|
|
|
6
6
|
import { useGridSelector } from '../hooks/utils/useGridSelector';
|
|
7
7
|
import { useGridApiContext } from '../hooks/utils/useGridApiContext';
|
|
8
8
|
import { useGridRootProps } from '../hooks/utils/useGridRootProps';
|
|
9
|
-
import {
|
|
10
|
-
import { gridPaginationModelSelector } from '../hooks/features/pagination/gridPaginationSelector';
|
|
9
|
+
import { gridPaginationModelSelector, gridPaginationRowCountSelector } from '../hooks/features/pagination/gridPaginationSelector';
|
|
11
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
11
|
const GridPaginationRoot = styled(TablePagination)(({
|
|
13
12
|
theme
|
|
@@ -32,11 +31,7 @@ const GridPagination = /*#__PURE__*/React.forwardRef(function GridPagination(pro
|
|
|
32
31
|
const apiRef = useGridApiContext();
|
|
33
32
|
const rootProps = useGridRootProps();
|
|
34
33
|
const paginationModel = useGridSelector(apiRef, gridPaginationModelSelector);
|
|
35
|
-
const
|
|
36
|
-
const rowCount = React.useMemo(() => {
|
|
37
|
-
var _ref, _rootProps$rowCount;
|
|
38
|
-
return (_ref = (_rootProps$rowCount = rootProps.rowCount) != null ? _rootProps$rowCount : visibleTopLevelRowCount) != null ? _ref : 0;
|
|
39
|
-
}, [rootProps.rowCount, visibleTopLevelRowCount]);
|
|
34
|
+
const rowCount = useGridSelector(apiRef, gridPaginationRowCountSelector);
|
|
40
35
|
const lastPage = React.useMemo(() => Math.floor(rowCount / (paginationModel.pageSize || 1)), [rowCount, paginationModel.pageSize]);
|
|
41
36
|
const handlePageSizeChange = React.useCallback(event => {
|
|
42
37
|
const pageSize = Number(event.target.value);
|
|
@@ -56,7 +56,10 @@ const GridPanel = /*#__PURE__*/React.forwardRef((props, ref) => {
|
|
|
56
56
|
}, [apiRef]);
|
|
57
57
|
const modifiers = React.useMemo(() => [{
|
|
58
58
|
name: 'flip',
|
|
59
|
-
enabled:
|
|
59
|
+
enabled: true,
|
|
60
|
+
options: {
|
|
61
|
+
rootBoundary: 'document'
|
|
62
|
+
}
|
|
60
63
|
}, {
|
|
61
64
|
name: 'isPlaced',
|
|
62
65
|
enabled: true,
|
|
@@ -8,7 +8,7 @@ import { gridClasses } from '../../../constants/gridClasses';
|
|
|
8
8
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
9
9
|
import { gridRowsMetaSelector } from '../rows/gridRowsMetaSelector';
|
|
10
10
|
import { getColumnsToExport } from './utils';
|
|
11
|
-
import {
|
|
11
|
+
import { getDerivedPaginationModel } from '../pagination/useGridPaginationModel';
|
|
12
12
|
import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
|
|
13
13
|
import { GridPrintExportMenuItem } from '../../../components/toolbar/GridToolbarExport';
|
|
14
14
|
import { getTotalHeaderHeight } from '../columns/gridColumnsUtils';
|
|
@@ -226,9 +226,13 @@ export const useGridPrintExport = (apiRef, props) => {
|
|
|
226
226
|
page: 0,
|
|
227
227
|
pageSize: visibleRowCount
|
|
228
228
|
};
|
|
229
|
-
apiRef.current.
|
|
230
|
-
|
|
231
|
-
|
|
229
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
230
|
+
pagination: _extends({}, state.pagination, {
|
|
231
|
+
paginationModel: getDerivedPaginationModel(state.pagination,
|
|
232
|
+
// Using signature `DataGridPro` to allow more than 100 rows in the print export
|
|
233
|
+
'DataGridPro', paginationModel)
|
|
234
|
+
})
|
|
235
|
+
}));
|
|
232
236
|
apiRef.current.forceUpdate();
|
|
233
237
|
}
|
|
234
238
|
await updateGridColumnsForPrint(options == null ? void 0 : options.fields, options == null ? void 0 : options.allColumns, options == null ? void 0 : options.includeCheckboxes);
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { GridPaginationModel } from '../../../models/gridPaginationProps';
|
|
2
2
|
export interface GridPaginationState {
|
|
3
3
|
paginationModel: GridPaginationModel;
|
|
4
|
+
rowCount: number;
|
|
4
5
|
}
|
|
5
6
|
export interface GridPaginationInitialState {
|
|
6
7
|
paginationModel?: Partial<GridPaginationModel>;
|
|
8
|
+
rowCount?: number;
|
|
7
9
|
}
|
|
8
10
|
/**
|
|
9
|
-
* The pagination API interface that is available in the grid `apiRef`.
|
|
11
|
+
* The pagination model API interface that is available in the grid `apiRef`.
|
|
10
12
|
*/
|
|
11
|
-
export interface
|
|
13
|
+
export interface GridPaginationModelApi {
|
|
12
14
|
/**
|
|
13
15
|
* Sets the displayed page to the value given by `page`.
|
|
14
16
|
* @param {number} page The new page number.
|
|
@@ -25,3 +27,18 @@ export interface GridPaginationApi {
|
|
|
25
27
|
*/
|
|
26
28
|
setPaginationModel: (model: GridPaginationModel) => void;
|
|
27
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* The pagination row count API interface that is available in the grid `apiRef`.
|
|
32
|
+
*/
|
|
33
|
+
export interface GridPaginationRowCountApi {
|
|
34
|
+
/**
|
|
35
|
+
* Sets the `rowCount` to a new value.
|
|
36
|
+
* @param {number} rowCount The new row count value.
|
|
37
|
+
*/
|
|
38
|
+
setRowCount: (rowCount: number) => void;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The pagination API interface that is available in the grid `apiRef`.
|
|
42
|
+
*/
|
|
43
|
+
export interface GridPaginationApi extends GridPaginationModelApi, GridPaginationRowCountApi {
|
|
44
|
+
}
|
|
@@ -9,6 +9,11 @@ export declare const gridPaginationSelector: (state: GridStateCommunity) => impo
|
|
|
9
9
|
* @category Pagination
|
|
10
10
|
*/
|
|
11
11
|
export declare const gridPaginationModelSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, import("../../..").GridPaginationModel>;
|
|
12
|
+
/**
|
|
13
|
+
* Get the row count
|
|
14
|
+
* @category Pagination
|
|
15
|
+
*/
|
|
16
|
+
export declare const gridPaginationRowCountSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, number>;
|
|
12
17
|
/**
|
|
13
18
|
* Get the index of the page to render if the pagination is enabled
|
|
14
19
|
* @category Pagination
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createSelector, createSelectorMemoized } from '../../../utils/createSelector';
|
|
2
|
-
import {
|
|
2
|
+
import { gridExpandedSortedRowEntriesSelector, gridExpandedSortedRowIdsSelector, gridFilteredSortedTopLevelRowEntriesSelector } from '../filter/gridFilterSelector';
|
|
3
3
|
import { gridRowMaximumTreeDepthSelector, gridRowTreeSelector } from '../rows/gridRowsSelector';
|
|
4
4
|
import { getPageCount } from './gridPaginationUtils';
|
|
5
5
|
|
|
@@ -15,6 +15,12 @@ export const gridPaginationSelector = state => state.pagination;
|
|
|
15
15
|
*/
|
|
16
16
|
export const gridPaginationModelSelector = createSelector(gridPaginationSelector, pagination => pagination.paginationModel);
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Get the row count
|
|
20
|
+
* @category Pagination
|
|
21
|
+
*/
|
|
22
|
+
export const gridPaginationRowCountSelector = createSelector(gridPaginationSelector, pagination => pagination.rowCount);
|
|
23
|
+
|
|
18
24
|
/**
|
|
19
25
|
* Get the index of the page to render if the pagination is enabled
|
|
20
26
|
* @category Pagination
|
|
@@ -31,7 +37,7 @@ export const gridPageSizeSelector = createSelector(gridPaginationModelSelector,
|
|
|
31
37
|
* Get the amount of pages needed to display all the rows if the pagination is enabled
|
|
32
38
|
* @category Pagination
|
|
33
39
|
*/
|
|
34
|
-
export const gridPageCountSelector = createSelector(
|
|
40
|
+
export const gridPageCountSelector = createSelector(gridPageSizeSelector, gridPaginationRowCountSelector, (pageSize, rowCount) => getPageCount(rowCount, pageSize));
|
|
35
41
|
|
|
36
42
|
/**
|
|
37
43
|
* Get the index of the first and the last row to include in the current page if the pagination is enabled.
|
|
@@ -2,14 +2,9 @@ import * as React from 'react';
|
|
|
2
2
|
import { GridPrivateApiCommunity } from '../../../models/api/gridApiCommunity';
|
|
3
3
|
import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
|
|
4
4
|
import { GridStateInitializer } from '../../utils/useGridInitializeState';
|
|
5
|
-
import { GridPaginationState } from './gridPaginationInterfaces';
|
|
6
|
-
import { GridPaginationModel } from '../../../models/gridPaginationProps';
|
|
7
5
|
export declare const paginationStateInitializer: GridStateInitializer<Pick<DataGridProcessedProps, 'paginationModel' | 'rowCount' | 'initialState' | 'autoPageSize' | 'signature'>>;
|
|
8
|
-
export declare const mergeStateWithPaginationModel: (rowCount: number, signature: DataGridProcessedProps['signature'], paginationModelProp?: GridPaginationModel) => (paginationState: GridPaginationState) => {
|
|
9
|
-
paginationModel: GridPaginationModel;
|
|
10
|
-
};
|
|
11
6
|
/**
|
|
12
7
|
* @requires useGridFilter (state)
|
|
13
8
|
* @requires useGridDimensions (event) - can be after
|
|
14
9
|
*/
|
|
15
|
-
export declare const useGridPagination: (apiRef: React.MutableRefObject<GridPrivateApiCommunity>, props:
|
|
10
|
+
export declare const useGridPagination: (apiRef: React.MutableRefObject<GridPrivateApiCommunity>, props: DataGridProcessedProps) => void;
|
|
@@ -1,175 +1,25 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { useGridLogger, useGridSelector, useGridApiMethod, useGridApiEventHandler } from '../../utils';
|
|
6
|
-
import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
|
|
7
|
-
import { gridPaginationModelSelector } from './gridPaginationSelector';
|
|
8
|
-
import { calculatePinnedRowsHeight } from '../rows/gridRowsUtils';
|
|
9
|
-
import { getPageCount, noRowCountInServerMode, defaultPageSize, throwIfPageSizeExceedsTheLimit, getDefaultGridPaginationModel, getValidPage } from './gridPaginationUtils';
|
|
2
|
+
import { throwIfPageSizeExceedsTheLimit, getDefaultGridPaginationModel } from './gridPaginationUtils';
|
|
3
|
+
import { useGridPaginationModel } from './useGridPaginationModel';
|
|
4
|
+
import { useGridRowCount } from './useGridRowCount';
|
|
10
5
|
export const paginationStateInitializer = (state, props) => {
|
|
11
|
-
var _props$paginationMode, _props$initialState;
|
|
6
|
+
var _props$paginationMode, _props$initialState, _ref, _props$rowCount, _props$initialState2;
|
|
12
7
|
const paginationModel = _extends({}, getDefaultGridPaginationModel(props.autoPageSize), (_props$paginationMode = props.paginationModel) != null ? _props$paginationMode : (_props$initialState = props.initialState) == null || (_props$initialState = _props$initialState.pagination) == null ? void 0 : _props$initialState.paginationModel);
|
|
13
8
|
throwIfPageSizeExceedsTheLimit(paginationModel.pageSize, props.signature);
|
|
9
|
+
const rowCount = (_ref = (_props$rowCount = props.rowCount) != null ? _props$rowCount : (_props$initialState2 = props.initialState) == null || (_props$initialState2 = _props$initialState2.pagination) == null ? void 0 : _props$initialState2.rowCount) != null ? _ref : 0;
|
|
14
10
|
return _extends({}, state, {
|
|
15
11
|
pagination: {
|
|
16
|
-
paginationModel
|
|
12
|
+
paginationModel,
|
|
13
|
+
rowCount
|
|
17
14
|
}
|
|
18
15
|
});
|
|
19
16
|
};
|
|
20
|
-
export const mergeStateWithPaginationModel = (rowCount, signature, paginationModelProp) => paginationState => {
|
|
21
|
-
var _paginationModelProp$;
|
|
22
|
-
let paginationModel = paginationState.paginationModel;
|
|
23
|
-
const pageSize = (_paginationModelProp$ = paginationModelProp == null ? void 0 : paginationModelProp.pageSize) != null ? _paginationModelProp$ : paginationModel.pageSize;
|
|
24
|
-
const pageCount = getPageCount(rowCount, pageSize);
|
|
25
|
-
if (paginationModelProp && ((paginationModelProp == null ? void 0 : paginationModelProp.page) !== paginationModel.page || (paginationModelProp == null ? void 0 : paginationModelProp.pageSize) !== paginationModel.pageSize)) {
|
|
26
|
-
paginationModel = paginationModelProp;
|
|
27
|
-
}
|
|
28
|
-
const validPage = getValidPage(paginationModel.page, pageCount);
|
|
29
|
-
if (validPage !== paginationModel.page) {
|
|
30
|
-
paginationModel = _extends({}, paginationModel, {
|
|
31
|
-
page: validPage
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
throwIfPageSizeExceedsTheLimit(paginationModel.pageSize, signature);
|
|
35
|
-
return {
|
|
36
|
-
paginationModel
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
17
|
|
|
40
18
|
/**
|
|
41
19
|
* @requires useGridFilter (state)
|
|
42
20
|
* @requires useGridDimensions (event) - can be after
|
|
43
21
|
*/
|
|
44
22
|
export const useGridPagination = (apiRef, props) => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const visibleTopLevelRowCount = useGridSelector(apiRef, gridFilteredTopLevelRowCountSelector);
|
|
48
|
-
const densityFactor = useGridSelector(apiRef, gridDensityFactorSelector);
|
|
49
|
-
const rowHeight = Math.floor(props.rowHeight * densityFactor);
|
|
50
|
-
apiRef.current.registerControlState({
|
|
51
|
-
stateId: 'pagination',
|
|
52
|
-
propModel: props.paginationModel,
|
|
53
|
-
propOnChange: props.onPaginationModelChange,
|
|
54
|
-
stateSelector: gridPaginationModelSelector,
|
|
55
|
-
changeEvent: 'paginationModelChange'
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* API METHODS
|
|
60
|
-
*/
|
|
61
|
-
const setPage = React.useCallback(page => {
|
|
62
|
-
const currentModel = gridPaginationModelSelector(apiRef);
|
|
63
|
-
if (page === currentModel.page) {
|
|
64
|
-
return;
|
|
65
|
-
}
|
|
66
|
-
logger.debug(`Setting page to ${page}`);
|
|
67
|
-
apiRef.current.setPaginationModel({
|
|
68
|
-
page,
|
|
69
|
-
pageSize: currentModel.pageSize
|
|
70
|
-
});
|
|
71
|
-
}, [apiRef, logger]);
|
|
72
|
-
const setPageSize = React.useCallback(pageSize => {
|
|
73
|
-
const currentModel = gridPaginationModelSelector(apiRef);
|
|
74
|
-
if (pageSize === currentModel.pageSize) {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
logger.debug(`Setting page size to ${pageSize}`);
|
|
78
|
-
apiRef.current.setPaginationModel({
|
|
79
|
-
pageSize,
|
|
80
|
-
page: currentModel.page
|
|
81
|
-
});
|
|
82
|
-
}, [apiRef, logger]);
|
|
83
|
-
const setPaginationModel = React.useCallback(paginationModel => {
|
|
84
|
-
var _props$rowCount;
|
|
85
|
-
const currentModel = gridPaginationModelSelector(apiRef);
|
|
86
|
-
if (paginationModel === currentModel) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
logger.debug("Setting 'paginationModel' to", paginationModel);
|
|
90
|
-
apiRef.current.updateControlState('pagination', mergeStateWithPaginationModel((_props$rowCount = props.rowCount) != null ? _props$rowCount : visibleTopLevelRowCount, props.signature, paginationModel), 'setPaginationModel');
|
|
91
|
-
apiRef.current.forceUpdate();
|
|
92
|
-
}, [apiRef, logger, props.rowCount, props.signature, visibleTopLevelRowCount]);
|
|
93
|
-
const pageApi = {
|
|
94
|
-
setPage,
|
|
95
|
-
setPageSize,
|
|
96
|
-
setPaginationModel
|
|
97
|
-
};
|
|
98
|
-
useGridApiMethod(apiRef, pageApi, 'public');
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* PRE-PROCESSING
|
|
102
|
-
*/
|
|
103
|
-
const stateExportPreProcessing = React.useCallback((prevState, context) => {
|
|
104
|
-
var _props$initialState2;
|
|
105
|
-
const paginationModel = gridPaginationModelSelector(apiRef);
|
|
106
|
-
const shouldExportPaginationModel =
|
|
107
|
-
// Always export if the `exportOnlyDirtyModels` property is not activated
|
|
108
|
-
!context.exportOnlyDirtyModels ||
|
|
109
|
-
// Always export if the `paginationModel` is controlled
|
|
110
|
-
props.paginationModel != null ||
|
|
111
|
-
// Always export if the `paginationModel` has been initialized
|
|
112
|
-
((_props$initialState2 = props.initialState) == null || (_props$initialState2 = _props$initialState2.pagination) == null ? void 0 : _props$initialState2.paginationModel) != null ||
|
|
113
|
-
// Export if `page` or `pageSize` is not equal to the default value
|
|
114
|
-
paginationModel.page !== 0 && paginationModel.pageSize !== defaultPageSize(props.autoPageSize);
|
|
115
|
-
if (!shouldExportPaginationModel) {
|
|
116
|
-
return prevState;
|
|
117
|
-
}
|
|
118
|
-
return _extends({}, prevState, {
|
|
119
|
-
pagination: _extends({}, prevState.pagination, {
|
|
120
|
-
paginationModel
|
|
121
|
-
})
|
|
122
|
-
});
|
|
123
|
-
}, [apiRef, props.paginationModel, (_props$initialState3 = props.initialState) == null || (_props$initialState3 = _props$initialState3.pagination) == null ? void 0 : _props$initialState3.paginationModel, props.autoPageSize]);
|
|
124
|
-
const stateRestorePreProcessing = React.useCallback((params, context) => {
|
|
125
|
-
var _context$stateToResto, _context$stateToResto2, _props$rowCount2;
|
|
126
|
-
const paginationModel = (_context$stateToResto = context.stateToRestore.pagination) != null && _context$stateToResto.paginationModel ? _extends({}, getDefaultGridPaginationModel(props.autoPageSize), (_context$stateToResto2 = context.stateToRestore.pagination) == null ? void 0 : _context$stateToResto2.paginationModel) : gridPaginationModelSelector(apiRef);
|
|
127
|
-
apiRef.current.updateControlState('pagination', mergeStateWithPaginationModel((_props$rowCount2 = props.rowCount) != null ? _props$rowCount2 : visibleTopLevelRowCount, props.signature, paginationModel), 'stateRestorePreProcessing');
|
|
128
|
-
return params;
|
|
129
|
-
}, [apiRef, props.autoPageSize, props.rowCount, props.signature, visibleTopLevelRowCount]);
|
|
130
|
-
useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
|
|
131
|
-
useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* EVENTS
|
|
135
|
-
*/
|
|
136
|
-
const handlePaginationModelChange = () => {
|
|
137
|
-
var _apiRef$current$virtu;
|
|
138
|
-
const paginationModel = gridPaginationModelSelector(apiRef);
|
|
139
|
-
if ((_apiRef$current$virtu = apiRef.current.virtualScrollerRef) != null && _apiRef$current$virtu.current) {
|
|
140
|
-
apiRef.current.scrollToIndexes({
|
|
141
|
-
rowIndex: paginationModel.page * paginationModel.pageSize
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
apiRef.current.forceUpdate();
|
|
145
|
-
};
|
|
146
|
-
const handleUpdateAutoPageSize = React.useCallback(() => {
|
|
147
|
-
const dimensions = apiRef.current.getRootDimensions();
|
|
148
|
-
if (!props.autoPageSize || !dimensions) {
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
const pinnedRowsHeight = calculatePinnedRowsHeight(apiRef);
|
|
152
|
-
const maximumPageSizeWithoutScrollBar = Math.floor((dimensions.viewportInnerSize.height - pinnedRowsHeight.top - pinnedRowsHeight.bottom) / rowHeight);
|
|
153
|
-
apiRef.current.setPageSize(maximumPageSizeWithoutScrollBar);
|
|
154
|
-
}, [apiRef, props.autoPageSize, rowHeight]);
|
|
155
|
-
useGridApiEventHandler(apiRef, 'viewportInnerSizeChange', handleUpdateAutoPageSize);
|
|
156
|
-
useGridApiEventHandler(apiRef, 'paginationModelChange', handlePaginationModelChange);
|
|
157
|
-
|
|
158
|
-
/**
|
|
159
|
-
* EFFECTS
|
|
160
|
-
*/
|
|
161
|
-
React.useEffect(() => {
|
|
162
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
163
|
-
if (props.paginationMode === 'server' && props.rowCount == null) {
|
|
164
|
-
noRowCountInServerMode();
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}, [props.rowCount, props.paginationMode]);
|
|
168
|
-
React.useEffect(() => {
|
|
169
|
-
var _props$rowCount3;
|
|
170
|
-
apiRef.current.updateControlState('pagination', mergeStateWithPaginationModel((_props$rowCount3 = props.rowCount) != null ? _props$rowCount3 : visibleTopLevelRowCount, props.signature, props.paginationModel));
|
|
171
|
-
}, [apiRef, props.paginationModel, props.rowCount, props.paginationMode, visibleTopLevelRowCount, props.signature]);
|
|
172
|
-
React.useEffect(() => {
|
|
173
|
-
handleUpdateAutoPageSize();
|
|
174
|
-
}, [handleUpdateAutoPageSize]);
|
|
23
|
+
useGridPaginationModel(apiRef, props);
|
|
24
|
+
useGridRowCount(apiRef, props);
|
|
175
25
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { GridPrivateApiCommunity } from '../../../models/api/gridApiCommunity';
|
|
3
|
+
import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
|
|
4
|
+
import { GridPaginationState } from './gridPaginationInterfaces';
|
|
5
|
+
import { GridPaginationModel } from '../../../models/gridPaginationProps';
|
|
6
|
+
export declare const getDerivedPaginationModel: (paginationState: GridPaginationState, signature: DataGridProcessedProps['signature'], paginationModelProp?: GridPaginationModel) => GridPaginationModel;
|
|
7
|
+
/**
|
|
8
|
+
* @requires useGridFilter (state)
|
|
9
|
+
* @requires useGridDimensions (event) - can be after
|
|
10
|
+
*/
|
|
11
|
+
export declare const useGridPaginationModel: (apiRef: React.MutableRefObject<GridPrivateApiCommunity>, props: Pick<DataGridProcessedProps, 'paginationModel' | 'onPaginationModelChange' | 'autoPageSize' | 'initialState' | 'paginationMode' | 'signature' | 'rowHeight'>) => void;
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { gridDensityFactorSelector } from '../density';
|
|
4
|
+
import { calculatePinnedRowsHeight } from '../rows/gridRowsUtils';
|
|
5
|
+
import { useGridLogger, useGridSelector, useGridApiMethod, useGridApiEventHandler } from '../../utils';
|
|
6
|
+
import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
|
|
7
|
+
import { gridPageCountSelector, gridPaginationModelSelector } from './gridPaginationSelector';
|
|
8
|
+
import { getPageCount, defaultPageSize, throwIfPageSizeExceedsTheLimit, getDefaultGridPaginationModel, getValidPage } from './gridPaginationUtils';
|
|
9
|
+
export const getDerivedPaginationModel = (paginationState, signature, paginationModelProp) => {
|
|
10
|
+
var _paginationModelProp$;
|
|
11
|
+
let paginationModel = paginationState.paginationModel;
|
|
12
|
+
const rowCount = paginationState.rowCount;
|
|
13
|
+
const pageSize = (_paginationModelProp$ = paginationModelProp == null ? void 0 : paginationModelProp.pageSize) != null ? _paginationModelProp$ : paginationModel.pageSize;
|
|
14
|
+
const pageCount = getPageCount(rowCount, pageSize);
|
|
15
|
+
if (paginationModelProp && ((paginationModelProp == null ? void 0 : paginationModelProp.page) !== paginationModel.page || (paginationModelProp == null ? void 0 : paginationModelProp.pageSize) !== paginationModel.pageSize)) {
|
|
16
|
+
paginationModel = paginationModelProp;
|
|
17
|
+
}
|
|
18
|
+
const validPage = getValidPage(paginationModel.page, pageCount);
|
|
19
|
+
if (validPage !== paginationModel.page) {
|
|
20
|
+
paginationModel = _extends({}, paginationModel, {
|
|
21
|
+
page: validPage
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
throwIfPageSizeExceedsTheLimit(paginationModel.pageSize, signature);
|
|
25
|
+
return paginationModel;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @requires useGridFilter (state)
|
|
30
|
+
* @requires useGridDimensions (event) - can be after
|
|
31
|
+
*/
|
|
32
|
+
export const useGridPaginationModel = (apiRef, props) => {
|
|
33
|
+
var _props$initialState2;
|
|
34
|
+
const logger = useGridLogger(apiRef, 'useGridPaginationModel');
|
|
35
|
+
const densityFactor = useGridSelector(apiRef, gridDensityFactorSelector);
|
|
36
|
+
const rowHeight = Math.floor(props.rowHeight * densityFactor);
|
|
37
|
+
apiRef.current.registerControlState({
|
|
38
|
+
stateId: 'paginationModel',
|
|
39
|
+
propModel: props.paginationModel,
|
|
40
|
+
propOnChange: props.onPaginationModelChange,
|
|
41
|
+
stateSelector: gridPaginationModelSelector,
|
|
42
|
+
changeEvent: 'paginationModelChange'
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* API METHODS
|
|
47
|
+
*/
|
|
48
|
+
const setPage = React.useCallback(page => {
|
|
49
|
+
const currentModel = gridPaginationModelSelector(apiRef);
|
|
50
|
+
if (page === currentModel.page) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
logger.debug(`Setting page to ${page}`);
|
|
54
|
+
apiRef.current.setPaginationModel({
|
|
55
|
+
page,
|
|
56
|
+
pageSize: currentModel.pageSize
|
|
57
|
+
});
|
|
58
|
+
}, [apiRef, logger]);
|
|
59
|
+
const setPageSize = React.useCallback(pageSize => {
|
|
60
|
+
const currentModel = gridPaginationModelSelector(apiRef);
|
|
61
|
+
if (pageSize === currentModel.pageSize) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
logger.debug(`Setting page size to ${pageSize}`);
|
|
65
|
+
apiRef.current.setPaginationModel({
|
|
66
|
+
pageSize,
|
|
67
|
+
page: currentModel.page
|
|
68
|
+
});
|
|
69
|
+
}, [apiRef, logger]);
|
|
70
|
+
const setPaginationModel = React.useCallback(paginationModel => {
|
|
71
|
+
const currentModel = gridPaginationModelSelector(apiRef);
|
|
72
|
+
if (paginationModel === currentModel) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
logger.debug("Setting 'paginationModel' to", paginationModel);
|
|
76
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
77
|
+
pagination: _extends({}, state.pagination, {
|
|
78
|
+
paginationModel: getDerivedPaginationModel(state.pagination, props.signature, paginationModel)
|
|
79
|
+
})
|
|
80
|
+
}));
|
|
81
|
+
}, [apiRef, logger, props.signature]);
|
|
82
|
+
const paginationModelApi = {
|
|
83
|
+
setPage,
|
|
84
|
+
setPageSize,
|
|
85
|
+
setPaginationModel
|
|
86
|
+
};
|
|
87
|
+
useGridApiMethod(apiRef, paginationModelApi, 'public');
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* PRE-PROCESSING
|
|
91
|
+
*/
|
|
92
|
+
const stateExportPreProcessing = React.useCallback((prevState, context) => {
|
|
93
|
+
var _props$initialState;
|
|
94
|
+
const paginationModel = gridPaginationModelSelector(apiRef);
|
|
95
|
+
const shouldExportPaginationModel =
|
|
96
|
+
// Always export if the `exportOnlyDirtyModels` property is not activated
|
|
97
|
+
!context.exportOnlyDirtyModels ||
|
|
98
|
+
// Always export if the `paginationModel` is controlled
|
|
99
|
+
props.paginationModel != null ||
|
|
100
|
+
// Always export if the `paginationModel` has been initialized
|
|
101
|
+
((_props$initialState = props.initialState) == null || (_props$initialState = _props$initialState.pagination) == null ? void 0 : _props$initialState.paginationModel) != null ||
|
|
102
|
+
// Export if `page` or `pageSize` is not equal to the default value
|
|
103
|
+
paginationModel.page !== 0 && paginationModel.pageSize !== defaultPageSize(props.autoPageSize);
|
|
104
|
+
if (!shouldExportPaginationModel) {
|
|
105
|
+
return prevState;
|
|
106
|
+
}
|
|
107
|
+
return _extends({}, prevState, {
|
|
108
|
+
pagination: _extends({}, prevState.pagination, {
|
|
109
|
+
paginationModel
|
|
110
|
+
})
|
|
111
|
+
});
|
|
112
|
+
}, [apiRef, props.paginationModel, (_props$initialState2 = props.initialState) == null || (_props$initialState2 = _props$initialState2.pagination) == null ? void 0 : _props$initialState2.paginationModel, props.autoPageSize]);
|
|
113
|
+
const stateRestorePreProcessing = React.useCallback((params, context) => {
|
|
114
|
+
var _context$stateToResto, _context$stateToResto2;
|
|
115
|
+
const paginationModel = (_context$stateToResto = context.stateToRestore.pagination) != null && _context$stateToResto.paginationModel ? _extends({}, getDefaultGridPaginationModel(props.autoPageSize), (_context$stateToResto2 = context.stateToRestore.pagination) == null ? void 0 : _context$stateToResto2.paginationModel) : gridPaginationModelSelector(apiRef);
|
|
116
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
117
|
+
pagination: _extends({}, state.pagination, {
|
|
118
|
+
paginationModel: getDerivedPaginationModel(state.pagination, props.signature, paginationModel)
|
|
119
|
+
})
|
|
120
|
+
}));
|
|
121
|
+
return params;
|
|
122
|
+
}, [apiRef, props.autoPageSize, props.signature]);
|
|
123
|
+
useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
|
|
124
|
+
useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* EVENTS
|
|
128
|
+
*/
|
|
129
|
+
const handlePaginationModelChange = () => {
|
|
130
|
+
var _apiRef$current$virtu;
|
|
131
|
+
const paginationModel = gridPaginationModelSelector(apiRef);
|
|
132
|
+
if ((_apiRef$current$virtu = apiRef.current.virtualScrollerRef) != null && _apiRef$current$virtu.current) {
|
|
133
|
+
apiRef.current.scrollToIndexes({
|
|
134
|
+
rowIndex: paginationModel.page * paginationModel.pageSize
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const handleUpdateAutoPageSize = React.useCallback(() => {
|
|
139
|
+
if (!props.autoPageSize) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
const dimensions = apiRef.current.getRootDimensions() || {
|
|
143
|
+
viewportInnerSize: {
|
|
144
|
+
height: 0
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
const pinnedRowsHeight = calculatePinnedRowsHeight(apiRef);
|
|
148
|
+
const maximumPageSizeWithoutScrollBar = Math.floor((dimensions.viewportInnerSize.height - pinnedRowsHeight.top - pinnedRowsHeight.bottom) / rowHeight);
|
|
149
|
+
apiRef.current.setPageSize(maximumPageSizeWithoutScrollBar);
|
|
150
|
+
}, [apiRef, props.autoPageSize, rowHeight]);
|
|
151
|
+
const handleRowCountChange = React.useCallback(newRowCount => {
|
|
152
|
+
if (newRowCount == null) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const paginationModel = gridPaginationModelSelector(apiRef);
|
|
156
|
+
const pageCount = gridPageCountSelector(apiRef);
|
|
157
|
+
if (paginationModel.page > pageCount - 1) {
|
|
158
|
+
apiRef.current.setPage(Math.max(0, pageCount - 1));
|
|
159
|
+
}
|
|
160
|
+
}, [apiRef]);
|
|
161
|
+
useGridApiEventHandler(apiRef, 'viewportInnerSizeChange', handleUpdateAutoPageSize);
|
|
162
|
+
useGridApiEventHandler(apiRef, 'paginationModelChange', handlePaginationModelChange);
|
|
163
|
+
useGridApiEventHandler(apiRef, 'rowCountChange', handleRowCountChange);
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* EFFECTS
|
|
167
|
+
*/
|
|
168
|
+
React.useEffect(() => {
|
|
169
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
170
|
+
pagination: _extends({}, state.pagination, {
|
|
171
|
+
paginationModel: getDerivedPaginationModel(state.pagination, props.signature, props.paginationModel)
|
|
172
|
+
})
|
|
173
|
+
}));
|
|
174
|
+
}, [apiRef, props.paginationModel, props.paginationMode, props.signature]);
|
|
175
|
+
React.useEffect(handleUpdateAutoPageSize, [handleUpdateAutoPageSize]);
|
|
176
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { GridPrivateApiCommunity } from '../../../models/api/gridApiCommunity';
|
|
3
|
+
import { DataGridProcessedProps } from '../../../models/props/DataGridProps';
|
|
4
|
+
/**
|
|
5
|
+
* @requires useGridFilter (state)
|
|
6
|
+
* @requires useGridDimensions (event) - can be after
|
|
7
|
+
*/
|
|
8
|
+
export declare const useGridRowCount: (apiRef: React.MutableRefObject<GridPrivateApiCommunity>, props: Pick<DataGridProcessedProps, 'rowCount' | 'initialState' | 'paginationMode' | 'onRowCountChange'>) => void;
|