@mui/x-data-grid 7.0.0-beta.6 → 7.0.0-beta.7
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 +117 -1
- package/DataGrid/DataGrid.js +44 -0
- package/DataGrid/useDataGridComponent.js +3 -0
- package/DataGrid/useDataGridProps.js +3 -2
- package/components/GridColumnHeaders.d.ts +1 -2
- package/components/GridColumnHeaders.js +6 -17
- package/components/GridHeaders.js +1 -4
- package/components/GridPagination.js +2 -7
- package/components/GridRow.d.ts +1 -1
- package/components/GridRow.js +4 -19
- package/components/GridScrollArea.d.ts +10 -0
- package/components/GridScrollArea.js +150 -0
- package/components/cell/GridCell.d.ts +7 -0
- package/components/cell/GridCell.js +11 -3
- package/components/columnHeaders/GridBaseColumnHeaders.js +1 -0
- package/components/columnHeaders/GridColumnGroupHeader.d.ts +5 -0
- package/components/columnHeaders/GridColumnGroupHeader.js +18 -8
- package/components/columnHeaders/GridColumnHeaderItem.d.ts +5 -0
- package/components/columnHeaders/GridColumnHeaderItem.js +21 -6
- package/components/columnHeaders/GridGenericColumnHeaderItem.d.ts +1 -0
- package/components/columnHeaders/GridGenericColumnHeaderItem.js +6 -5
- package/components/containers/GridRootStyles.js +12 -20
- package/components/virtualization/GridVirtualScrollbar.js +4 -0
- package/components/virtualization/GridVirtualScroller.js +6 -1
- package/components/virtualization/GridVirtualScrollerFiller.js +2 -1
- package/constants/gridClasses.d.ts +6 -32
- package/constants/gridClasses.js +1 -1
- package/hooks/core/pipeProcessing/gridPipeProcessingApi.d.ts +5 -1
- package/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +23 -7
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +186 -99
- package/hooks/features/columnResize/columnResizeSelector.d.ts +3 -0
- package/hooks/features/columnResize/columnResizeSelector.js +3 -0
- package/hooks/features/columnResize/columnResizeState.d.ts +3 -0
- package/hooks/features/columnResize/columnResizeState.js +1 -0
- package/hooks/features/columnResize/gridColumnResizeApi.d.ts +44 -0
- package/hooks/features/columnResize/gridColumnResizeApi.js +10 -0
- package/hooks/features/columnResize/index.d.ts +3 -0
- package/hooks/features/columnResize/index.js +3 -0
- package/hooks/features/columnResize/useGridColumnResize.d.ts +10 -0
- package/hooks/features/columnResize/useGridColumnResize.js +563 -0
- package/hooks/features/columns/gridColumnsUtils.js +4 -1
- package/hooks/features/dimensions/useGridDimensions.js +4 -5
- package/hooks/features/editing/useGridCellEditing.js +21 -2
- package/hooks/features/export/useGridPrintExport.js +8 -7
- package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.d.ts +1 -0
- package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +6 -0
- package/hooks/features/headerFiltering/useGridHeaderFiltering.js +30 -7
- package/hooks/features/index.d.ts +1 -0
- package/hooks/features/index.js +1 -0
- 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 -157
- package/hooks/features/pagination/useGridPaginationModel.d.ts +11 -0
- package/hooks/features/pagination/useGridPaginationModel.js +170 -0
- package/hooks/features/pagination/useGridRowCount.d.ts +8 -0
- package/hooks/features/pagination/useGridRowCount.js +97 -0
- package/hooks/features/scroll/useGridScroll.js +1 -1
- package/hooks/features/virtualization/gridVirtualizationSelectors.d.ts +4 -4
- package/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +2 -2
- package/hooks/utils/useLazyRef.d.ts +1 -2
- package/hooks/utils/useLazyRef.js +1 -11
- package/hooks/utils/useOnMount.d.ts +1 -2
- package/hooks/utils/useOnMount.js +1 -7
- package/hooks/utils/useTimeout.d.ts +1 -11
- package/hooks/utils/useTimeout.js +1 -36
- package/index.js +1 -1
- package/internals/index.d.ts +1 -1
- package/internals/index.js +1 -1
- package/internals/utils/getPinnedCellOffset.d.ts +3 -0
- package/internals/utils/getPinnedCellOffset.js +17 -0
- package/joy/joySlots.js +13 -52
- package/locales/jaJP.js +3 -4
- package/material/index.js +0 -2
- package/models/api/gridApiCommon.d.ts +3 -3
- package/models/api/gridCoreApi.d.ts +1 -5
- package/models/events/gridEventLookup.d.ts +6 -0
- package/models/gridHeaderFilteringModel.d.ts +1 -0
- package/models/gridSlotsComponent.d.ts +0 -5
- package/models/gridStateCommunity.d.ts +2 -0
- package/models/params/gridScrollParams.d.ts +5 -3
- package/models/props/DataGridProps.d.ts +35 -1
- package/modern/DataGrid/DataGrid.js +44 -0
- package/modern/DataGrid/useDataGridComponent.js +3 -0
- package/modern/DataGrid/useDataGridProps.js +3 -2
- package/modern/components/GridColumnHeaders.js +6 -17
- package/modern/components/GridHeaders.js +1 -4
- package/modern/components/GridPagination.js +2 -4
- package/modern/components/GridRow.js +4 -19
- package/modern/components/GridScrollArea.js +150 -0
- package/modern/components/cell/GridCell.js +11 -3
- package/modern/components/columnHeaders/GridBaseColumnHeaders.js +1 -0
- package/modern/components/columnHeaders/GridColumnGroupHeader.js +18 -8
- package/modern/components/columnHeaders/GridColumnHeaderItem.js +21 -6
- package/modern/components/columnHeaders/GridGenericColumnHeaderItem.js +6 -5
- package/modern/components/containers/GridRootStyles.js +12 -20
- package/modern/components/virtualization/GridVirtualScrollbar.js +4 -0
- package/modern/components/virtualization/GridVirtualScroller.js +6 -1
- package/modern/components/virtualization/GridVirtualScrollerFiller.js +2 -1
- package/modern/constants/gridClasses.js +1 -1
- package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +184 -97
- package/modern/hooks/features/columnResize/columnResizeSelector.js +3 -0
- package/modern/hooks/features/columnResize/columnResizeState.js +1 -0
- package/modern/hooks/features/columnResize/gridColumnResizeApi.js +10 -0
- package/modern/hooks/features/columnResize/index.js +3 -0
- package/modern/hooks/features/columnResize/useGridColumnResize.js +553 -0
- package/modern/hooks/features/columns/gridColumnsUtils.js +4 -1
- package/modern/hooks/features/dimensions/useGridDimensions.js +4 -5
- package/modern/hooks/features/editing/useGridCellEditing.js +21 -2
- package/modern/hooks/features/export/useGridPrintExport.js +8 -7
- package/modern/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +3 -0
- package/modern/hooks/features/headerFiltering/useGridHeaderFiltering.js +21 -2
- package/modern/hooks/features/index.js +1 -0
- package/modern/hooks/features/pagination/gridPaginationSelector.js +8 -2
- package/modern/hooks/features/pagination/useGridPagination.js +8 -149
- package/modern/hooks/features/pagination/useGridPaginationModel.js +165 -0
- package/modern/hooks/features/pagination/useGridRowCount.js +94 -0
- package/modern/hooks/features/scroll/useGridScroll.js +1 -1
- package/modern/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
- package/modern/hooks/utils/useLazyRef.js +1 -11
- package/modern/hooks/utils/useOnMount.js +1 -7
- package/modern/hooks/utils/useTimeout.js +1 -36
- package/modern/index.js +1 -1
- package/modern/internals/index.js +1 -1
- package/modern/internals/utils/getPinnedCellOffset.js +17 -0
- package/modern/joy/joySlots.js +11 -50
- package/modern/locales/jaJP.js +3 -4
- package/modern/material/index.js +0 -2
- package/modern/utils/cellBorderUtils.js +8 -0
- package/modern/utils/domUtils.js +144 -0
- package/node/DataGrid/DataGrid.js +44 -0
- package/node/DataGrid/useDataGridComponent.js +3 -0
- package/node/DataGrid/useDataGridProps.js +3 -2
- package/node/components/GridColumnHeaders.js +6 -16
- package/node/components/GridHeaders.js +1 -4
- package/node/components/GridPagination.js +1 -3
- package/node/components/GridRow.js +3 -18
- package/node/components/GridScrollArea.js +158 -0
- package/node/components/cell/GridCell.js +12 -4
- package/node/components/columnHeaders/GridBaseColumnHeaders.js +1 -0
- package/node/components/columnHeaders/GridColumnGroupHeader.js +18 -8
- package/node/components/columnHeaders/GridColumnHeaderItem.js +21 -6
- package/node/components/columnHeaders/GridGenericColumnHeaderItem.js +6 -5
- package/node/components/containers/GridRootStyles.js +12 -20
- package/node/components/virtualization/GridVirtualScrollbar.js +4 -0
- package/node/components/virtualization/GridVirtualScroller.js +6 -1
- package/node/components/virtualization/GridVirtualScrollerFiller.js +2 -1
- package/node/constants/gridClasses.js +1 -1
- package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +190 -103
- package/node/hooks/features/columnResize/columnResizeSelector.js +10 -0
- package/node/hooks/features/columnResize/columnResizeState.js +5 -0
- package/node/hooks/features/columnResize/gridColumnResizeApi.js +16 -0
- package/node/hooks/features/columnResize/index.js +38 -0
- package/node/hooks/features/columnResize/useGridColumnResize.js +564 -0
- package/node/hooks/features/columns/gridColumnsUtils.js +4 -1
- package/node/hooks/features/dimensions/useGridDimensions.js +4 -5
- package/node/hooks/features/editing/useGridCellEditing.js +21 -2
- package/node/hooks/features/export/useGridPrintExport.js +8 -7
- package/node/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +4 -1
- package/node/hooks/features/headerFiltering/useGridHeaderFiltering.js +21 -2
- package/node/hooks/features/index.js +11 -0
- package/node/hooks/features/pagination/gridPaginationSelector.js +8 -2
- package/node/hooks/features/pagination/useGridPagination.js +9 -153
- package/node/hooks/features/pagination/useGridPaginationModel.js +176 -0
- package/node/hooks/features/pagination/useGridRowCount.js +103 -0
- package/node/hooks/features/scroll/useGridScroll.js +1 -1
- package/node/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
- package/node/hooks/utils/useLazyRef.js +7 -13
- package/node/hooks/utils/useOnMount.js +8 -10
- package/node/hooks/utils/useTimeout.js +7 -37
- package/node/index.js +1 -1
- package/node/internals/index.js +15 -8
- package/node/internals/utils/getPinnedCellOffset.js +24 -0
- package/node/joy/joySlots.js +11 -50
- package/node/locales/jaJP.js +3 -4
- package/node/material/index.js +0 -2
- package/node/utils/cellBorderUtils.js +16 -0
- package/node/utils/domUtils.js +155 -0
- package/package.json +1 -1
- package/utils/cellBorderUtils.d.ts +3 -0
- package/utils/cellBorderUtils.js +8 -0
- package/utils/domUtils.d.ts +14 -1
- package/utils/domUtils.js +147 -0
- package/components/columnHeaders/GridColumnHeadersInner.d.ts +0 -8
- package/components/columnHeaders/GridColumnHeadersInner.js +0 -58
- package/modern/components/columnHeaders/GridColumnHeadersInner.js +0 -58
- package/node/components/columnHeaders/GridColumnHeadersInner.js +0 -67
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GridStateCommunity } from '../../../models/gridStateCommunity';
|
|
2
2
|
export declare const gridHeaderFilteringStateSelector: (state: GridStateCommunity) => import("../../../models/gridHeaderFilteringModel").GridHeaderFilteringState;
|
|
3
|
+
export declare const gridHeaderFilteringEnabledSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, boolean>;
|
|
3
4
|
export declare const gridHeaderFilteringEditFieldSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, string | null>;
|
|
4
5
|
export declare const gridHeaderFilteringMenuSelector: import("../../../utils/createSelector").OutputSelector<GridStateCommunity, string | null>;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { createSelector } from '../../../utils/createSelector';
|
|
2
2
|
export const gridHeaderFilteringStateSelector = state => state.headerFiltering;
|
|
3
|
+
export const gridHeaderFilteringEnabledSelector = createSelector(gridHeaderFilteringStateSelector,
|
|
4
|
+
// No initialization in MIT, so we need to default to false to be used by `getTotalHeaderHeight`
|
|
5
|
+
headerFilteringState => {
|
|
6
|
+
var _headerFilteringState;
|
|
7
|
+
return (_headerFilteringState = headerFilteringState == null ? void 0 : headerFilteringState.enabled) != null ? _headerFilteringState : false;
|
|
8
|
+
});
|
|
3
9
|
export const gridHeaderFilteringEditFieldSelector = createSelector(gridHeaderFilteringStateSelector, headerFilteringState => headerFilteringState.editing);
|
|
4
10
|
export const gridHeaderFilteringMenuSelector = createSelector(gridHeaderFilteringStateSelector, headerFilteringState => headerFilteringState.menuOpen);
|
|
@@ -3,14 +3,22 @@ import * as React from 'react';
|
|
|
3
3
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
4
4
|
import { useGridLogger } from '../../utils';
|
|
5
5
|
import { gridColumnLookupSelector, gridColumnVisibilityModelSelector, gridColumnFieldsSelector } from '../columns/gridColumnsSelector';
|
|
6
|
-
export const headerFilteringStateInitializer = state =>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
export const headerFilteringStateInitializer = (state, props) => {
|
|
7
|
+
var _props$headerFilters;
|
|
8
|
+
return _extends({}, state, {
|
|
9
|
+
// @ts-expect-error Access `Pro` prop in MIT
|
|
10
|
+
headerFiltering: {
|
|
11
|
+
enabled: (_props$headerFilters = props.headerFilters) != null ? _props$headerFilters : false,
|
|
12
|
+
editing: null,
|
|
13
|
+
menuOpen: null
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
};
|
|
12
17
|
export const useGridHeaderFiltering = (apiRef, props) => {
|
|
18
|
+
var _props$headerFilters2;
|
|
13
19
|
const logger = useGridLogger(apiRef, 'useGridHeaderFiltering');
|
|
20
|
+
// @ts-expect-error Access `Pro` prop in MIT
|
|
21
|
+
const isHeaderFilteringEnabled = (_props$headerFilters2 = props.headerFilters) != null ? _props$headerFilters2 : false;
|
|
14
22
|
const setHeaderFilterState = React.useCallback(headerFilterState => {
|
|
15
23
|
apiRef.current.setState(state => {
|
|
16
24
|
var _headerFilterState$ed, _headerFilterState$me;
|
|
@@ -21,13 +29,14 @@ export const useGridHeaderFiltering = (apiRef, props) => {
|
|
|
21
29
|
}
|
|
22
30
|
return _extends({}, state, {
|
|
23
31
|
headerFiltering: {
|
|
32
|
+
enabled: isHeaderFilteringEnabled != null ? isHeaderFilteringEnabled : false,
|
|
24
33
|
editing: (_headerFilterState$ed = headerFilterState.editing) != null ? _headerFilterState$ed : null,
|
|
25
34
|
menuOpen: (_headerFilterState$me = headerFilterState.menuOpen) != null ? _headerFilterState$me : null
|
|
26
35
|
}
|
|
27
36
|
});
|
|
28
37
|
});
|
|
29
38
|
apiRef.current.forceUpdate();
|
|
30
|
-
}, [apiRef, props.signature]);
|
|
39
|
+
}, [apiRef, props.signature, isHeaderFilteringEnabled]);
|
|
31
40
|
const startHeaderFilterEditMode = React.useCallback(field => {
|
|
32
41
|
logger.debug(`Starting edit mode on header filter for field: ${field}`);
|
|
33
42
|
apiRef.current.setHeaderFilterState({
|
|
@@ -88,4 +97,18 @@ export const useGridHeaderFiltering = (apiRef, props) => {
|
|
|
88
97
|
};
|
|
89
98
|
useGridApiMethod(apiRef, headerFilterApi, 'public');
|
|
90
99
|
useGridApiMethod(apiRef, headerFilterPrivateApi, 'private');
|
|
100
|
+
|
|
101
|
+
/*
|
|
102
|
+
* EFFECTS
|
|
103
|
+
*/
|
|
104
|
+
const isFirstRender = React.useRef(true);
|
|
105
|
+
React.useEffect(() => {
|
|
106
|
+
if (isFirstRender.current) {
|
|
107
|
+
isFirstRender.current = false;
|
|
108
|
+
} else {
|
|
109
|
+
apiRef.current.setHeaderFilterState({
|
|
110
|
+
enabled: isHeaderFilteringEnabled
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}, [apiRef, isHeaderFilteringEnabled]);
|
|
91
114
|
};
|
package/hooks/features/index.js
CHANGED
|
@@ -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,173 +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 { getPageCount, noRowCountInServerMode, defaultPageSize, throwIfPageSizeExceedsTheLimit, getDefaultGridPaginationModel, getValidPage } from './gridPaginationUtils';
|
|
2
|
+
import { throwIfPageSizeExceedsTheLimit, getDefaultGridPaginationModel } from './gridPaginationUtils';
|
|
3
|
+
import { useGridPaginationModel } from './useGridPaginationModel';
|
|
4
|
+
import { useGridRowCount } from './useGridRowCount';
|
|
9
5
|
export const paginationStateInitializer = (state, props) => {
|
|
10
|
-
var _props$paginationMode, _props$initialState;
|
|
6
|
+
var _props$paginationMode, _props$initialState, _props$rowCount, _props$initialState2;
|
|
11
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);
|
|
12
8
|
throwIfPageSizeExceedsTheLimit(paginationModel.pageSize, props.signature);
|
|
9
|
+
const rowCount = (_props$rowCount = props.rowCount) != null ? _props$rowCount : (_props$initialState2 = props.initialState) == null || (_props$initialState2 = _props$initialState2.pagination) == null ? void 0 : _props$initialState2.rowCount;
|
|
13
10
|
return _extends({}, state, {
|
|
14
11
|
pagination: {
|
|
15
|
-
paginationModel
|
|
12
|
+
paginationModel,
|
|
13
|
+
rowCount
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
16
|
};
|
|
19
|
-
export const mergeStateWithPaginationModel = (rowCount, signature, paginationModelProp) => paginationState => {
|
|
20
|
-
var _paginationModelProp$;
|
|
21
|
-
let paginationModel = paginationState.paginationModel;
|
|
22
|
-
const pageSize = (_paginationModelProp$ = paginationModelProp == null ? void 0 : paginationModelProp.pageSize) != null ? _paginationModelProp$ : paginationModel.pageSize;
|
|
23
|
-
const pageCount = getPageCount(rowCount, pageSize);
|
|
24
|
-
if (paginationModelProp && ((paginationModelProp == null ? void 0 : paginationModelProp.page) !== paginationModel.page || (paginationModelProp == null ? void 0 : paginationModelProp.pageSize) !== paginationModel.pageSize)) {
|
|
25
|
-
paginationModel = paginationModelProp;
|
|
26
|
-
}
|
|
27
|
-
const validPage = getValidPage(paginationModel.page, pageCount);
|
|
28
|
-
if (validPage !== paginationModel.page) {
|
|
29
|
-
paginationModel = _extends({}, paginationModel, {
|
|
30
|
-
page: validPage
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
throwIfPageSizeExceedsTheLimit(paginationModel.pageSize, signature);
|
|
34
|
-
return {
|
|
35
|
-
paginationModel
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
17
|
|
|
39
18
|
/**
|
|
40
19
|
* @requires useGridFilter (state)
|
|
41
20
|
* @requires useGridDimensions (event) - can be after
|
|
42
21
|
*/
|
|
43
22
|
export const useGridPagination = (apiRef, props) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const visibleTopLevelRowCount = useGridSelector(apiRef, gridFilteredTopLevelRowCountSelector);
|
|
47
|
-
const densityFactor = useGridSelector(apiRef, gridDensityFactorSelector);
|
|
48
|
-
const rowHeight = Math.floor(props.rowHeight * densityFactor);
|
|
49
|
-
apiRef.current.registerControlState({
|
|
50
|
-
stateId: 'pagination',
|
|
51
|
-
propModel: props.paginationModel,
|
|
52
|
-
propOnChange: props.onPaginationModelChange,
|
|
53
|
-
stateSelector: gridPaginationModelSelector,
|
|
54
|
-
changeEvent: 'paginationModelChange'
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* API METHODS
|
|
59
|
-
*/
|
|
60
|
-
const setPage = React.useCallback(page => {
|
|
61
|
-
const currentModel = gridPaginationModelSelector(apiRef);
|
|
62
|
-
if (page === currentModel.page) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
logger.debug(`Setting page to ${page}`);
|
|
66
|
-
apiRef.current.setPaginationModel({
|
|
67
|
-
page,
|
|
68
|
-
pageSize: currentModel.pageSize
|
|
69
|
-
});
|
|
70
|
-
}, [apiRef, logger]);
|
|
71
|
-
const setPageSize = React.useCallback(pageSize => {
|
|
72
|
-
const currentModel = gridPaginationModelSelector(apiRef);
|
|
73
|
-
if (pageSize === currentModel.pageSize) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
logger.debug(`Setting page size to ${pageSize}`);
|
|
77
|
-
apiRef.current.setPaginationModel({
|
|
78
|
-
pageSize,
|
|
79
|
-
page: currentModel.page
|
|
80
|
-
});
|
|
81
|
-
}, [apiRef, logger]);
|
|
82
|
-
const setPaginationModel = React.useCallback(paginationModel => {
|
|
83
|
-
var _props$rowCount;
|
|
84
|
-
const currentModel = gridPaginationModelSelector(apiRef);
|
|
85
|
-
if (paginationModel === currentModel) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
logger.debug("Setting 'paginationModel' to", paginationModel);
|
|
89
|
-
apiRef.current.updateControlState('pagination', mergeStateWithPaginationModel((_props$rowCount = props.rowCount) != null ? _props$rowCount : visibleTopLevelRowCount, props.signature, paginationModel), 'setPaginationModel');
|
|
90
|
-
apiRef.current.forceUpdate();
|
|
91
|
-
}, [apiRef, logger, props.rowCount, props.signature, visibleTopLevelRowCount]);
|
|
92
|
-
const pageApi = {
|
|
93
|
-
setPage,
|
|
94
|
-
setPageSize,
|
|
95
|
-
setPaginationModel
|
|
96
|
-
};
|
|
97
|
-
useGridApiMethod(apiRef, pageApi, 'public');
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* PRE-PROCESSING
|
|
101
|
-
*/
|
|
102
|
-
const stateExportPreProcessing = React.useCallback((prevState, context) => {
|
|
103
|
-
var _props$initialState2;
|
|
104
|
-
const paginationModel = gridPaginationModelSelector(apiRef);
|
|
105
|
-
const shouldExportPaginationModel =
|
|
106
|
-
// Always export if the `exportOnlyDirtyModels` property is not activated
|
|
107
|
-
!context.exportOnlyDirtyModels ||
|
|
108
|
-
// Always export if the `paginationModel` is controlled
|
|
109
|
-
props.paginationModel != null ||
|
|
110
|
-
// Always export if the `paginationModel` has been initialized
|
|
111
|
-
((_props$initialState2 = props.initialState) == null || (_props$initialState2 = _props$initialState2.pagination) == null ? void 0 : _props$initialState2.paginationModel) != null ||
|
|
112
|
-
// Export if `page` or `pageSize` is not equal to the default value
|
|
113
|
-
paginationModel.page !== 0 && paginationModel.pageSize !== defaultPageSize(props.autoPageSize);
|
|
114
|
-
if (!shouldExportPaginationModel) {
|
|
115
|
-
return prevState;
|
|
116
|
-
}
|
|
117
|
-
return _extends({}, prevState, {
|
|
118
|
-
pagination: _extends({}, prevState.pagination, {
|
|
119
|
-
paginationModel
|
|
120
|
-
})
|
|
121
|
-
});
|
|
122
|
-
}, [apiRef, props.paginationModel, (_props$initialState3 = props.initialState) == null || (_props$initialState3 = _props$initialState3.pagination) == null ? void 0 : _props$initialState3.paginationModel, props.autoPageSize]);
|
|
123
|
-
const stateRestorePreProcessing = React.useCallback((params, context) => {
|
|
124
|
-
var _context$stateToResto, _context$stateToResto2, _props$rowCount2;
|
|
125
|
-
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);
|
|
126
|
-
apiRef.current.updateControlState('pagination', mergeStateWithPaginationModel((_props$rowCount2 = props.rowCount) != null ? _props$rowCount2 : visibleTopLevelRowCount, props.signature, paginationModel), 'stateRestorePreProcessing');
|
|
127
|
-
return params;
|
|
128
|
-
}, [apiRef, props.autoPageSize, props.rowCount, props.signature, visibleTopLevelRowCount]);
|
|
129
|
-
useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
|
|
130
|
-
useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* EVENTS
|
|
134
|
-
*/
|
|
135
|
-
const handlePaginationModelChange = () => {
|
|
136
|
-
var _apiRef$current$virtu;
|
|
137
|
-
const paginationModel = gridPaginationModelSelector(apiRef);
|
|
138
|
-
if ((_apiRef$current$virtu = apiRef.current.virtualScrollerRef) != null && _apiRef$current$virtu.current) {
|
|
139
|
-
apiRef.current.scrollToIndexes({
|
|
140
|
-
rowIndex: paginationModel.page * paginationModel.pageSize
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
apiRef.current.forceUpdate();
|
|
144
|
-
};
|
|
145
|
-
const handleUpdateAutoPageSize = React.useCallback(() => {
|
|
146
|
-
if (!props.autoPageSize) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
const dimensions = apiRef.current.getRootDimensions();
|
|
150
|
-
const maximumPageSizeWithoutScrollBar = Math.floor(dimensions.viewportInnerSize.height / rowHeight);
|
|
151
|
-
apiRef.current.setPageSize(maximumPageSizeWithoutScrollBar);
|
|
152
|
-
}, [apiRef, props.autoPageSize, rowHeight]);
|
|
153
|
-
useGridApiEventHandler(apiRef, 'viewportInnerSizeChange', handleUpdateAutoPageSize);
|
|
154
|
-
useGridApiEventHandler(apiRef, 'paginationModelChange', handlePaginationModelChange);
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* EFFECTS
|
|
158
|
-
*/
|
|
159
|
-
React.useEffect(() => {
|
|
160
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
161
|
-
if (props.paginationMode === 'server' && props.rowCount == null) {
|
|
162
|
-
noRowCountInServerMode();
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
}, [props.rowCount, props.paginationMode]);
|
|
166
|
-
React.useEffect(() => {
|
|
167
|
-
var _props$rowCount3;
|
|
168
|
-
apiRef.current.updateControlState('pagination', mergeStateWithPaginationModel((_props$rowCount3 = props.rowCount) != null ? _props$rowCount3 : visibleTopLevelRowCount, props.signature, props.paginationModel));
|
|
169
|
-
}, [apiRef, props.paginationModel, props.rowCount, props.paginationMode, visibleTopLevelRowCount, props.signature]);
|
|
170
|
-
React.useEffect(() => {
|
|
171
|
-
handleUpdateAutoPageSize();
|
|
172
|
-
}, [handleUpdateAutoPageSize]);
|
|
23
|
+
useGridPaginationModel(apiRef, props);
|
|
24
|
+
useGridRowCount(apiRef, props);
|
|
173
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,170 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { gridDensityFactorSelector } from '../density';
|
|
4
|
+
import { useGridLogger, useGridSelector, useGridApiMethod, useGridApiEventHandler } from '../../utils';
|
|
5
|
+
import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
|
|
6
|
+
import { gridPageCountSelector, gridPaginationModelSelector } from './gridPaginationSelector';
|
|
7
|
+
import { getPageCount, defaultPageSize, throwIfPageSizeExceedsTheLimit, getDefaultGridPaginationModel, getValidPage } from './gridPaginationUtils';
|
|
8
|
+
export const getDerivedPaginationModel = (paginationState, signature, paginationModelProp) => {
|
|
9
|
+
var _paginationModelProp$;
|
|
10
|
+
let paginationModel = paginationState.paginationModel;
|
|
11
|
+
const rowCount = paginationState.rowCount;
|
|
12
|
+
const pageSize = (_paginationModelProp$ = paginationModelProp == null ? void 0 : paginationModelProp.pageSize) != null ? _paginationModelProp$ : paginationModel.pageSize;
|
|
13
|
+
const pageCount = getPageCount(rowCount, pageSize);
|
|
14
|
+
if (paginationModelProp && ((paginationModelProp == null ? void 0 : paginationModelProp.page) !== paginationModel.page || (paginationModelProp == null ? void 0 : paginationModelProp.pageSize) !== paginationModel.pageSize)) {
|
|
15
|
+
paginationModel = paginationModelProp;
|
|
16
|
+
}
|
|
17
|
+
const validPage = getValidPage(paginationModel.page, pageCount);
|
|
18
|
+
if (validPage !== paginationModel.page) {
|
|
19
|
+
paginationModel = _extends({}, paginationModel, {
|
|
20
|
+
page: validPage
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
throwIfPageSizeExceedsTheLimit(paginationModel.pageSize, signature);
|
|
24
|
+
return paginationModel;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @requires useGridFilter (state)
|
|
29
|
+
* @requires useGridDimensions (event) - can be after
|
|
30
|
+
*/
|
|
31
|
+
export const useGridPaginationModel = (apiRef, props) => {
|
|
32
|
+
var _props$initialState2;
|
|
33
|
+
const logger = useGridLogger(apiRef, 'useGridPaginationModel');
|
|
34
|
+
const densityFactor = useGridSelector(apiRef, gridDensityFactorSelector);
|
|
35
|
+
const rowHeight = Math.floor(props.rowHeight * densityFactor);
|
|
36
|
+
apiRef.current.registerControlState({
|
|
37
|
+
stateId: 'paginationModel',
|
|
38
|
+
propModel: props.paginationModel,
|
|
39
|
+
propOnChange: props.onPaginationModelChange,
|
|
40
|
+
stateSelector: gridPaginationModelSelector,
|
|
41
|
+
changeEvent: 'paginationModelChange'
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* API METHODS
|
|
46
|
+
*/
|
|
47
|
+
const setPage = React.useCallback(page => {
|
|
48
|
+
const currentModel = gridPaginationModelSelector(apiRef);
|
|
49
|
+
if (page === currentModel.page) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
logger.debug(`Setting page to ${page}`);
|
|
53
|
+
apiRef.current.setPaginationModel({
|
|
54
|
+
page,
|
|
55
|
+
pageSize: currentModel.pageSize
|
|
56
|
+
});
|
|
57
|
+
}, [apiRef, logger]);
|
|
58
|
+
const setPageSize = React.useCallback(pageSize => {
|
|
59
|
+
const currentModel = gridPaginationModelSelector(apiRef);
|
|
60
|
+
if (pageSize === currentModel.pageSize) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
logger.debug(`Setting page size to ${pageSize}`);
|
|
64
|
+
apiRef.current.setPaginationModel({
|
|
65
|
+
pageSize,
|
|
66
|
+
page: currentModel.page
|
|
67
|
+
});
|
|
68
|
+
}, [apiRef, logger]);
|
|
69
|
+
const setPaginationModel = React.useCallback(paginationModel => {
|
|
70
|
+
const currentModel = gridPaginationModelSelector(apiRef);
|
|
71
|
+
if (paginationModel === currentModel) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
logger.debug("Setting 'paginationModel' to", paginationModel);
|
|
75
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
76
|
+
pagination: _extends({}, state.pagination, {
|
|
77
|
+
paginationModel: getDerivedPaginationModel(state.pagination, props.signature, paginationModel)
|
|
78
|
+
})
|
|
79
|
+
}));
|
|
80
|
+
}, [apiRef, logger, props.signature]);
|
|
81
|
+
const paginationModelApi = {
|
|
82
|
+
setPage,
|
|
83
|
+
setPageSize,
|
|
84
|
+
setPaginationModel
|
|
85
|
+
};
|
|
86
|
+
useGridApiMethod(apiRef, paginationModelApi, 'public');
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* PRE-PROCESSING
|
|
90
|
+
*/
|
|
91
|
+
const stateExportPreProcessing = React.useCallback((prevState, context) => {
|
|
92
|
+
var _props$initialState;
|
|
93
|
+
const paginationModel = gridPaginationModelSelector(apiRef);
|
|
94
|
+
const shouldExportPaginationModel =
|
|
95
|
+
// Always export if the `exportOnlyDirtyModels` property is not activated
|
|
96
|
+
!context.exportOnlyDirtyModels ||
|
|
97
|
+
// Always export if the `paginationModel` is controlled
|
|
98
|
+
props.paginationModel != null ||
|
|
99
|
+
// Always export if the `paginationModel` has been initialized
|
|
100
|
+
((_props$initialState = props.initialState) == null || (_props$initialState = _props$initialState.pagination) == null ? void 0 : _props$initialState.paginationModel) != null ||
|
|
101
|
+
// Export if `page` or `pageSize` is not equal to the default value
|
|
102
|
+
paginationModel.page !== 0 && paginationModel.pageSize !== defaultPageSize(props.autoPageSize);
|
|
103
|
+
if (!shouldExportPaginationModel) {
|
|
104
|
+
return prevState;
|
|
105
|
+
}
|
|
106
|
+
return _extends({}, prevState, {
|
|
107
|
+
pagination: _extends({}, prevState.pagination, {
|
|
108
|
+
paginationModel
|
|
109
|
+
})
|
|
110
|
+
});
|
|
111
|
+
}, [apiRef, props.paginationModel, (_props$initialState2 = props.initialState) == null || (_props$initialState2 = _props$initialState2.pagination) == null ? void 0 : _props$initialState2.paginationModel, props.autoPageSize]);
|
|
112
|
+
const stateRestorePreProcessing = React.useCallback((params, context) => {
|
|
113
|
+
var _context$stateToResto, _context$stateToResto2;
|
|
114
|
+
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);
|
|
115
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
116
|
+
pagination: _extends({}, state.pagination, {
|
|
117
|
+
paginationModel: getDerivedPaginationModel(state.pagination, props.signature, paginationModel)
|
|
118
|
+
})
|
|
119
|
+
}));
|
|
120
|
+
return params;
|
|
121
|
+
}, [apiRef, props.autoPageSize, props.signature]);
|
|
122
|
+
useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
|
|
123
|
+
useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* EVENTS
|
|
127
|
+
*/
|
|
128
|
+
const handlePaginationModelChange = () => {
|
|
129
|
+
var _apiRef$current$virtu;
|
|
130
|
+
const paginationModel = gridPaginationModelSelector(apiRef);
|
|
131
|
+
if ((_apiRef$current$virtu = apiRef.current.virtualScrollerRef) != null && _apiRef$current$virtu.current) {
|
|
132
|
+
apiRef.current.scrollToIndexes({
|
|
133
|
+
rowIndex: paginationModel.page * paginationModel.pageSize
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const handleUpdateAutoPageSize = React.useCallback(() => {
|
|
138
|
+
if (!props.autoPageSize) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const dimensions = apiRef.current.getRootDimensions();
|
|
142
|
+
const maximumPageSizeWithoutScrollBar = Math.floor(dimensions.viewportInnerSize.height / rowHeight);
|
|
143
|
+
apiRef.current.setPageSize(maximumPageSizeWithoutScrollBar);
|
|
144
|
+
}, [apiRef, props.autoPageSize, rowHeight]);
|
|
145
|
+
const handleRowCountChange = React.useCallback(newRowCount => {
|
|
146
|
+
if (newRowCount == null) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const paginationModel = gridPaginationModelSelector(apiRef);
|
|
150
|
+
const pageCount = gridPageCountSelector(apiRef);
|
|
151
|
+
if (paginationModel.page > pageCount - 1) {
|
|
152
|
+
apiRef.current.setPage(Math.max(0, pageCount - 1));
|
|
153
|
+
}
|
|
154
|
+
}, [apiRef]);
|
|
155
|
+
useGridApiEventHandler(apiRef, 'viewportInnerSizeChange', handleUpdateAutoPageSize);
|
|
156
|
+
useGridApiEventHandler(apiRef, 'paginationModelChange', handlePaginationModelChange);
|
|
157
|
+
useGridApiEventHandler(apiRef, 'rowCountChange', handleRowCountChange);
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* EFFECTS
|
|
161
|
+
*/
|
|
162
|
+
React.useEffect(() => {
|
|
163
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
164
|
+
pagination: _extends({}, state.pagination, {
|
|
165
|
+
paginationModel: getDerivedPaginationModel(state.pagination, props.signature, props.paginationModel)
|
|
166
|
+
})
|
|
167
|
+
}));
|
|
168
|
+
}, [apiRef, props.paginationModel, props.paginationMode, props.signature]);
|
|
169
|
+
React.useEffect(handleUpdateAutoPageSize, [handleUpdateAutoPageSize]);
|
|
170
|
+
};
|
|
@@ -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;
|