@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
|
@@ -3,14 +3,18 @@ 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 => _extends({}, state, {
|
|
6
|
+
export const headerFilteringStateInitializer = (state, props) => _extends({}, state, {
|
|
7
|
+
// @ts-expect-error Access `Pro` prop in MIT
|
|
7
8
|
headerFiltering: {
|
|
9
|
+
enabled: props.headerFilters ?? false,
|
|
8
10
|
editing: null,
|
|
9
11
|
menuOpen: null
|
|
10
12
|
}
|
|
11
13
|
});
|
|
12
14
|
export const useGridHeaderFiltering = (apiRef, props) => {
|
|
13
15
|
const logger = useGridLogger(apiRef, 'useGridHeaderFiltering');
|
|
16
|
+
// @ts-expect-error Access `Pro` prop in MIT
|
|
17
|
+
const isHeaderFilteringEnabled = props.headerFilters ?? false;
|
|
14
18
|
const setHeaderFilterState = React.useCallback(headerFilterState => {
|
|
15
19
|
apiRef.current.setState(state => {
|
|
16
20
|
// Safety check to avoid MIT users from using it
|
|
@@ -20,13 +24,14 @@ export const useGridHeaderFiltering = (apiRef, props) => {
|
|
|
20
24
|
}
|
|
21
25
|
return _extends({}, state, {
|
|
22
26
|
headerFiltering: {
|
|
27
|
+
enabled: isHeaderFilteringEnabled ?? false,
|
|
23
28
|
editing: headerFilterState.editing ?? null,
|
|
24
29
|
menuOpen: headerFilterState.menuOpen ?? null
|
|
25
30
|
}
|
|
26
31
|
});
|
|
27
32
|
});
|
|
28
33
|
apiRef.current.forceUpdate();
|
|
29
|
-
}, [apiRef, props.signature]);
|
|
34
|
+
}, [apiRef, props.signature, isHeaderFilteringEnabled]);
|
|
30
35
|
const startHeaderFilterEditMode = React.useCallback(field => {
|
|
31
36
|
logger.debug(`Starting edit mode on header filter for field: ${field}`);
|
|
32
37
|
apiRef.current.setHeaderFilterState({
|
|
@@ -87,4 +92,18 @@ export const useGridHeaderFiltering = (apiRef, props) => {
|
|
|
87
92
|
};
|
|
88
93
|
useGridApiMethod(apiRef, headerFilterApi, 'public');
|
|
89
94
|
useGridApiMethod(apiRef, headerFilterPrivateApi, 'private');
|
|
95
|
+
|
|
96
|
+
/*
|
|
97
|
+
* EFFECTS
|
|
98
|
+
*/
|
|
99
|
+
const isFirstRender = React.useRef(true);
|
|
100
|
+
React.useEffect(() => {
|
|
101
|
+
if (isFirstRender.current) {
|
|
102
|
+
isFirstRender.current = false;
|
|
103
|
+
} else {
|
|
104
|
+
apiRef.current.setHeaderFilterState({
|
|
105
|
+
enabled: isHeaderFilteringEnabled
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}, [apiRef, isHeaderFilteringEnabled]);
|
|
90
109
|
};
|
|
@@ -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.
|
|
@@ -1,165 +1,24 @@
|
|
|
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
6
|
const paginationModel = _extends({}, getDefaultGridPaginationModel(props.autoPageSize), props.paginationModel ?? props.initialState?.pagination?.paginationModel);
|
|
11
7
|
throwIfPageSizeExceedsTheLimit(paginationModel.pageSize, props.signature);
|
|
8
|
+
const rowCount = props.rowCount ?? props.initialState?.pagination?.rowCount;
|
|
12
9
|
return _extends({}, state, {
|
|
13
10
|
pagination: {
|
|
14
|
-
paginationModel
|
|
11
|
+
paginationModel,
|
|
12
|
+
rowCount
|
|
15
13
|
}
|
|
16
14
|
});
|
|
17
15
|
};
|
|
18
|
-
export const mergeStateWithPaginationModel = (rowCount, signature, paginationModelProp) => paginationState => {
|
|
19
|
-
let paginationModel = paginationState.paginationModel;
|
|
20
|
-
const pageSize = paginationModelProp?.pageSize ?? paginationModel.pageSize;
|
|
21
|
-
const pageCount = getPageCount(rowCount, pageSize);
|
|
22
|
-
if (paginationModelProp && (paginationModelProp?.page !== paginationModel.page || paginationModelProp?.pageSize !== paginationModel.pageSize)) {
|
|
23
|
-
paginationModel = paginationModelProp;
|
|
24
|
-
}
|
|
25
|
-
const validPage = getValidPage(paginationModel.page, pageCount);
|
|
26
|
-
if (validPage !== paginationModel.page) {
|
|
27
|
-
paginationModel = _extends({}, paginationModel, {
|
|
28
|
-
page: validPage
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
throwIfPageSizeExceedsTheLimit(paginationModel.pageSize, signature);
|
|
32
|
-
return {
|
|
33
|
-
paginationModel
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
16
|
|
|
37
17
|
/**
|
|
38
18
|
* @requires useGridFilter (state)
|
|
39
19
|
* @requires useGridDimensions (event) - can be after
|
|
40
20
|
*/
|
|
41
21
|
export const useGridPagination = (apiRef, props) => {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const densityFactor = useGridSelector(apiRef, gridDensityFactorSelector);
|
|
45
|
-
const rowHeight = Math.floor(props.rowHeight * densityFactor);
|
|
46
|
-
apiRef.current.registerControlState({
|
|
47
|
-
stateId: 'pagination',
|
|
48
|
-
propModel: props.paginationModel,
|
|
49
|
-
propOnChange: props.onPaginationModelChange,
|
|
50
|
-
stateSelector: gridPaginationModelSelector,
|
|
51
|
-
changeEvent: 'paginationModelChange'
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* API METHODS
|
|
56
|
-
*/
|
|
57
|
-
const setPage = React.useCallback(page => {
|
|
58
|
-
const currentModel = gridPaginationModelSelector(apiRef);
|
|
59
|
-
if (page === currentModel.page) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
logger.debug(`Setting page to ${page}`);
|
|
63
|
-
apiRef.current.setPaginationModel({
|
|
64
|
-
page,
|
|
65
|
-
pageSize: currentModel.pageSize
|
|
66
|
-
});
|
|
67
|
-
}, [apiRef, logger]);
|
|
68
|
-
const setPageSize = React.useCallback(pageSize => {
|
|
69
|
-
const currentModel = gridPaginationModelSelector(apiRef);
|
|
70
|
-
if (pageSize === currentModel.pageSize) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
logger.debug(`Setting page size to ${pageSize}`);
|
|
74
|
-
apiRef.current.setPaginationModel({
|
|
75
|
-
pageSize,
|
|
76
|
-
page: currentModel.page
|
|
77
|
-
});
|
|
78
|
-
}, [apiRef, logger]);
|
|
79
|
-
const setPaginationModel = React.useCallback(paginationModel => {
|
|
80
|
-
const currentModel = gridPaginationModelSelector(apiRef);
|
|
81
|
-
if (paginationModel === currentModel) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
logger.debug("Setting 'paginationModel' to", paginationModel);
|
|
85
|
-
apiRef.current.updateControlState('pagination', mergeStateWithPaginationModel(props.rowCount ?? visibleTopLevelRowCount, props.signature, paginationModel), 'setPaginationModel');
|
|
86
|
-
apiRef.current.forceUpdate();
|
|
87
|
-
}, [apiRef, logger, props.rowCount, props.signature, visibleTopLevelRowCount]);
|
|
88
|
-
const pageApi = {
|
|
89
|
-
setPage,
|
|
90
|
-
setPageSize,
|
|
91
|
-
setPaginationModel
|
|
92
|
-
};
|
|
93
|
-
useGridApiMethod(apiRef, pageApi, 'public');
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* PRE-PROCESSING
|
|
97
|
-
*/
|
|
98
|
-
const stateExportPreProcessing = React.useCallback((prevState, context) => {
|
|
99
|
-
const paginationModel = gridPaginationModelSelector(apiRef);
|
|
100
|
-
const shouldExportPaginationModel =
|
|
101
|
-
// Always export if the `exportOnlyDirtyModels` property is not activated
|
|
102
|
-
!context.exportOnlyDirtyModels ||
|
|
103
|
-
// Always export if the `paginationModel` is controlled
|
|
104
|
-
props.paginationModel != null ||
|
|
105
|
-
// Always export if the `paginationModel` has been initialized
|
|
106
|
-
props.initialState?.pagination?.paginationModel != null ||
|
|
107
|
-
// Export if `page` or `pageSize` is not equal to the default value
|
|
108
|
-
paginationModel.page !== 0 && paginationModel.pageSize !== defaultPageSize(props.autoPageSize);
|
|
109
|
-
if (!shouldExportPaginationModel) {
|
|
110
|
-
return prevState;
|
|
111
|
-
}
|
|
112
|
-
return _extends({}, prevState, {
|
|
113
|
-
pagination: _extends({}, prevState.pagination, {
|
|
114
|
-
paginationModel
|
|
115
|
-
})
|
|
116
|
-
});
|
|
117
|
-
}, [apiRef, props.paginationModel, props.initialState?.pagination?.paginationModel, props.autoPageSize]);
|
|
118
|
-
const stateRestorePreProcessing = React.useCallback((params, context) => {
|
|
119
|
-
const paginationModel = context.stateToRestore.pagination?.paginationModel ? _extends({}, getDefaultGridPaginationModel(props.autoPageSize), context.stateToRestore.pagination?.paginationModel) : gridPaginationModelSelector(apiRef);
|
|
120
|
-
apiRef.current.updateControlState('pagination', mergeStateWithPaginationModel(props.rowCount ?? visibleTopLevelRowCount, props.signature, paginationModel), 'stateRestorePreProcessing');
|
|
121
|
-
return params;
|
|
122
|
-
}, [apiRef, props.autoPageSize, props.rowCount, props.signature, visibleTopLevelRowCount]);
|
|
123
|
-
useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
|
|
124
|
-
useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* EVENTS
|
|
128
|
-
*/
|
|
129
|
-
const handlePaginationModelChange = () => {
|
|
130
|
-
const paginationModel = gridPaginationModelSelector(apiRef);
|
|
131
|
-
if (apiRef.current.virtualScrollerRef?.current) {
|
|
132
|
-
apiRef.current.scrollToIndexes({
|
|
133
|
-
rowIndex: paginationModel.page * paginationModel.pageSize
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
apiRef.current.forceUpdate();
|
|
137
|
-
};
|
|
138
|
-
const handleUpdateAutoPageSize = React.useCallback(() => {
|
|
139
|
-
if (!props.autoPageSize) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
const dimensions = apiRef.current.getRootDimensions();
|
|
143
|
-
const maximumPageSizeWithoutScrollBar = Math.floor(dimensions.viewportInnerSize.height / rowHeight);
|
|
144
|
-
apiRef.current.setPageSize(maximumPageSizeWithoutScrollBar);
|
|
145
|
-
}, [apiRef, props.autoPageSize, rowHeight]);
|
|
146
|
-
useGridApiEventHandler(apiRef, 'viewportInnerSizeChange', handleUpdateAutoPageSize);
|
|
147
|
-
useGridApiEventHandler(apiRef, 'paginationModelChange', handlePaginationModelChange);
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* EFFECTS
|
|
151
|
-
*/
|
|
152
|
-
React.useEffect(() => {
|
|
153
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
154
|
-
if (props.paginationMode === 'server' && props.rowCount == null) {
|
|
155
|
-
noRowCountInServerMode();
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}, [props.rowCount, props.paginationMode]);
|
|
159
|
-
React.useEffect(() => {
|
|
160
|
-
apiRef.current.updateControlState('pagination', mergeStateWithPaginationModel(props.rowCount ?? visibleTopLevelRowCount, props.signature, props.paginationModel));
|
|
161
|
-
}, [apiRef, props.paginationModel, props.rowCount, props.paginationMode, visibleTopLevelRowCount, props.signature]);
|
|
162
|
-
React.useEffect(() => {
|
|
163
|
-
handleUpdateAutoPageSize();
|
|
164
|
-
}, [handleUpdateAutoPageSize]);
|
|
22
|
+
useGridPaginationModel(apiRef, props);
|
|
23
|
+
useGridRowCount(apiRef, props);
|
|
165
24
|
};
|
|
@@ -0,0 +1,165 @@
|
|
|
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
|
+
let paginationModel = paginationState.paginationModel;
|
|
10
|
+
const rowCount = paginationState.rowCount;
|
|
11
|
+
const pageSize = paginationModelProp?.pageSize ?? paginationModel.pageSize;
|
|
12
|
+
const pageCount = getPageCount(rowCount, pageSize);
|
|
13
|
+
if (paginationModelProp && (paginationModelProp?.page !== paginationModel.page || paginationModelProp?.pageSize !== paginationModel.pageSize)) {
|
|
14
|
+
paginationModel = paginationModelProp;
|
|
15
|
+
}
|
|
16
|
+
const validPage = getValidPage(paginationModel.page, pageCount);
|
|
17
|
+
if (validPage !== paginationModel.page) {
|
|
18
|
+
paginationModel = _extends({}, paginationModel, {
|
|
19
|
+
page: validPage
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
throwIfPageSizeExceedsTheLimit(paginationModel.pageSize, signature);
|
|
23
|
+
return paginationModel;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @requires useGridFilter (state)
|
|
28
|
+
* @requires useGridDimensions (event) - can be after
|
|
29
|
+
*/
|
|
30
|
+
export const useGridPaginationModel = (apiRef, props) => {
|
|
31
|
+
const logger = useGridLogger(apiRef, 'useGridPaginationModel');
|
|
32
|
+
const densityFactor = useGridSelector(apiRef, gridDensityFactorSelector);
|
|
33
|
+
const rowHeight = Math.floor(props.rowHeight * densityFactor);
|
|
34
|
+
apiRef.current.registerControlState({
|
|
35
|
+
stateId: 'paginationModel',
|
|
36
|
+
propModel: props.paginationModel,
|
|
37
|
+
propOnChange: props.onPaginationModelChange,
|
|
38
|
+
stateSelector: gridPaginationModelSelector,
|
|
39
|
+
changeEvent: 'paginationModelChange'
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* API METHODS
|
|
44
|
+
*/
|
|
45
|
+
const setPage = React.useCallback(page => {
|
|
46
|
+
const currentModel = gridPaginationModelSelector(apiRef);
|
|
47
|
+
if (page === currentModel.page) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
logger.debug(`Setting page to ${page}`);
|
|
51
|
+
apiRef.current.setPaginationModel({
|
|
52
|
+
page,
|
|
53
|
+
pageSize: currentModel.pageSize
|
|
54
|
+
});
|
|
55
|
+
}, [apiRef, logger]);
|
|
56
|
+
const setPageSize = React.useCallback(pageSize => {
|
|
57
|
+
const currentModel = gridPaginationModelSelector(apiRef);
|
|
58
|
+
if (pageSize === currentModel.pageSize) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
logger.debug(`Setting page size to ${pageSize}`);
|
|
62
|
+
apiRef.current.setPaginationModel({
|
|
63
|
+
pageSize,
|
|
64
|
+
page: currentModel.page
|
|
65
|
+
});
|
|
66
|
+
}, [apiRef, logger]);
|
|
67
|
+
const setPaginationModel = React.useCallback(paginationModel => {
|
|
68
|
+
const currentModel = gridPaginationModelSelector(apiRef);
|
|
69
|
+
if (paginationModel === currentModel) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
logger.debug("Setting 'paginationModel' to", paginationModel);
|
|
73
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
74
|
+
pagination: _extends({}, state.pagination, {
|
|
75
|
+
paginationModel: getDerivedPaginationModel(state.pagination, props.signature, paginationModel)
|
|
76
|
+
})
|
|
77
|
+
}));
|
|
78
|
+
}, [apiRef, logger, props.signature]);
|
|
79
|
+
const paginationModelApi = {
|
|
80
|
+
setPage,
|
|
81
|
+
setPageSize,
|
|
82
|
+
setPaginationModel
|
|
83
|
+
};
|
|
84
|
+
useGridApiMethod(apiRef, paginationModelApi, 'public');
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* PRE-PROCESSING
|
|
88
|
+
*/
|
|
89
|
+
const stateExportPreProcessing = React.useCallback((prevState, context) => {
|
|
90
|
+
const paginationModel = gridPaginationModelSelector(apiRef);
|
|
91
|
+
const shouldExportPaginationModel =
|
|
92
|
+
// Always export if the `exportOnlyDirtyModels` property is not activated
|
|
93
|
+
!context.exportOnlyDirtyModels ||
|
|
94
|
+
// Always export if the `paginationModel` is controlled
|
|
95
|
+
props.paginationModel != null ||
|
|
96
|
+
// Always export if the `paginationModel` has been initialized
|
|
97
|
+
props.initialState?.pagination?.paginationModel != null ||
|
|
98
|
+
// Export if `page` or `pageSize` is not equal to the default value
|
|
99
|
+
paginationModel.page !== 0 && paginationModel.pageSize !== defaultPageSize(props.autoPageSize);
|
|
100
|
+
if (!shouldExportPaginationModel) {
|
|
101
|
+
return prevState;
|
|
102
|
+
}
|
|
103
|
+
return _extends({}, prevState, {
|
|
104
|
+
pagination: _extends({}, prevState.pagination, {
|
|
105
|
+
paginationModel
|
|
106
|
+
})
|
|
107
|
+
});
|
|
108
|
+
}, [apiRef, props.paginationModel, props.initialState?.pagination?.paginationModel, props.autoPageSize]);
|
|
109
|
+
const stateRestorePreProcessing = React.useCallback((params, context) => {
|
|
110
|
+
const paginationModel = context.stateToRestore.pagination?.paginationModel ? _extends({}, getDefaultGridPaginationModel(props.autoPageSize), context.stateToRestore.pagination?.paginationModel) : gridPaginationModelSelector(apiRef);
|
|
111
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
112
|
+
pagination: _extends({}, state.pagination, {
|
|
113
|
+
paginationModel: getDerivedPaginationModel(state.pagination, props.signature, paginationModel)
|
|
114
|
+
})
|
|
115
|
+
}));
|
|
116
|
+
return params;
|
|
117
|
+
}, [apiRef, props.autoPageSize, props.signature]);
|
|
118
|
+
useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
|
|
119
|
+
useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* EVENTS
|
|
123
|
+
*/
|
|
124
|
+
const handlePaginationModelChange = () => {
|
|
125
|
+
const paginationModel = gridPaginationModelSelector(apiRef);
|
|
126
|
+
if (apiRef.current.virtualScrollerRef?.current) {
|
|
127
|
+
apiRef.current.scrollToIndexes({
|
|
128
|
+
rowIndex: paginationModel.page * paginationModel.pageSize
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
const handleUpdateAutoPageSize = React.useCallback(() => {
|
|
133
|
+
if (!props.autoPageSize) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const dimensions = apiRef.current.getRootDimensions();
|
|
137
|
+
const maximumPageSizeWithoutScrollBar = Math.floor(dimensions.viewportInnerSize.height / rowHeight);
|
|
138
|
+
apiRef.current.setPageSize(maximumPageSizeWithoutScrollBar);
|
|
139
|
+
}, [apiRef, props.autoPageSize, rowHeight]);
|
|
140
|
+
const handleRowCountChange = React.useCallback(newRowCount => {
|
|
141
|
+
if (newRowCount == null) {
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const paginationModel = gridPaginationModelSelector(apiRef);
|
|
145
|
+
const pageCount = gridPageCountSelector(apiRef);
|
|
146
|
+
if (paginationModel.page > pageCount - 1) {
|
|
147
|
+
apiRef.current.setPage(Math.max(0, pageCount - 1));
|
|
148
|
+
}
|
|
149
|
+
}, [apiRef]);
|
|
150
|
+
useGridApiEventHandler(apiRef, 'viewportInnerSizeChange', handleUpdateAutoPageSize);
|
|
151
|
+
useGridApiEventHandler(apiRef, 'paginationModelChange', handlePaginationModelChange);
|
|
152
|
+
useGridApiEventHandler(apiRef, 'rowCountChange', handleRowCountChange);
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* EFFECTS
|
|
156
|
+
*/
|
|
157
|
+
React.useEffect(() => {
|
|
158
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
159
|
+
pagination: _extends({}, state.pagination, {
|
|
160
|
+
paginationModel: getDerivedPaginationModel(state.pagination, props.signature, props.paginationModel)
|
|
161
|
+
})
|
|
162
|
+
}));
|
|
163
|
+
}, [apiRef, props.paginationModel, props.paginationMode, props.signature]);
|
|
164
|
+
React.useEffect(handleUpdateAutoPageSize, [handleUpdateAutoPageSize]);
|
|
165
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { gridFilteredTopLevelRowCountSelector } from '../filter';
|
|
4
|
+
import { useGridLogger, useGridSelector, useGridApiMethod } from '../../utils';
|
|
5
|
+
import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
|
|
6
|
+
import { gridPaginationRowCountSelector } from './gridPaginationSelector';
|
|
7
|
+
import { noRowCountInServerMode } from './gridPaginationUtils';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @requires useGridFilter (state)
|
|
11
|
+
* @requires useGridDimensions (event) - can be after
|
|
12
|
+
*/
|
|
13
|
+
export const useGridRowCount = (apiRef, props) => {
|
|
14
|
+
const logger = useGridLogger(apiRef, 'useGridRowCount');
|
|
15
|
+
const visibleTopLevelRowCount = useGridSelector(apiRef, gridFilteredTopLevelRowCountSelector);
|
|
16
|
+
const rowCount = useGridSelector(apiRef, gridPaginationRowCountSelector);
|
|
17
|
+
apiRef.current.registerControlState({
|
|
18
|
+
stateId: 'paginationRowCount',
|
|
19
|
+
propModel: props.rowCount,
|
|
20
|
+
propOnChange: props.onRowCountChange,
|
|
21
|
+
stateSelector: gridPaginationRowCountSelector,
|
|
22
|
+
changeEvent: 'rowCountChange'
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* API METHODS
|
|
27
|
+
*/
|
|
28
|
+
const setRowCount = React.useCallback(newRowCount => {
|
|
29
|
+
if (rowCount === newRowCount) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
logger.debug("Setting 'rowCount' to", newRowCount);
|
|
33
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
34
|
+
pagination: _extends({}, state.pagination, {
|
|
35
|
+
rowCount: newRowCount
|
|
36
|
+
})
|
|
37
|
+
}));
|
|
38
|
+
}, [apiRef, logger, rowCount]);
|
|
39
|
+
const paginationRowCountApi = {
|
|
40
|
+
setRowCount
|
|
41
|
+
};
|
|
42
|
+
useGridApiMethod(apiRef, paginationRowCountApi, 'public');
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* PRE-PROCESSING
|
|
46
|
+
*/
|
|
47
|
+
const stateExportPreProcessing = React.useCallback((prevState, context) => {
|
|
48
|
+
const exportedRowCount = gridPaginationRowCountSelector(apiRef);
|
|
49
|
+
const shouldExportRowCount =
|
|
50
|
+
// Always export if the `exportOnlyDirtyModels` property is not activated
|
|
51
|
+
!context.exportOnlyDirtyModels ||
|
|
52
|
+
// Always export if the `rowCount` is controlled
|
|
53
|
+
props.rowCount != null ||
|
|
54
|
+
// Always export if the `rowCount` has been initialized
|
|
55
|
+
props.initialState?.pagination?.rowCount != null;
|
|
56
|
+
if (!shouldExportRowCount) {
|
|
57
|
+
return prevState;
|
|
58
|
+
}
|
|
59
|
+
return _extends({}, prevState, {
|
|
60
|
+
pagination: _extends({}, prevState.pagination, {
|
|
61
|
+
rowCount: exportedRowCount
|
|
62
|
+
})
|
|
63
|
+
});
|
|
64
|
+
}, [apiRef, props.rowCount, props.initialState?.pagination?.rowCount]);
|
|
65
|
+
const stateRestorePreProcessing = React.useCallback((params, context) => {
|
|
66
|
+
const restoredRowCount = context.stateToRestore.pagination?.rowCount ? context.stateToRestore.pagination.rowCount : gridPaginationRowCountSelector(apiRef);
|
|
67
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
68
|
+
pagination: _extends({}, state.pagination, {
|
|
69
|
+
rowCount: restoredRowCount
|
|
70
|
+
})
|
|
71
|
+
}));
|
|
72
|
+
return params;
|
|
73
|
+
}, [apiRef]);
|
|
74
|
+
useGridRegisterPipeProcessor(apiRef, 'exportState', stateExportPreProcessing);
|
|
75
|
+
useGridRegisterPipeProcessor(apiRef, 'restoreState', stateRestorePreProcessing);
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* EFFECTS
|
|
79
|
+
*/
|
|
80
|
+
React.useEffect(() => {
|
|
81
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
82
|
+
if (props.paginationMode === 'server' && props.rowCount == null) {
|
|
83
|
+
noRowCountInServerMode();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}, [props.rowCount, props.paginationMode]);
|
|
87
|
+
React.useEffect(() => {
|
|
88
|
+
if (props.paginationMode === 'client') {
|
|
89
|
+
apiRef.current.setRowCount(visibleTopLevelRowCount);
|
|
90
|
+
} else if (props.rowCount != null) {
|
|
91
|
+
apiRef.current.setRowCount(props.rowCount);
|
|
92
|
+
}
|
|
93
|
+
}, [apiRef, visibleTopLevelRowCount, props.paginationMode, props.rowCount]);
|
|
94
|
+
};
|
|
@@ -45,7 +45,7 @@ function scrollIntoView(dimensions) {
|
|
|
45
45
|
export const useGridScroll = (apiRef, props) => {
|
|
46
46
|
const theme = useTheme();
|
|
47
47
|
const logger = useGridLogger(apiRef, 'useGridScroll');
|
|
48
|
-
const colRef = apiRef.current.
|
|
48
|
+
const colRef = apiRef.current.columnHeadersContainerRef;
|
|
49
49
|
const virtualScrollerRef = apiRef.current.virtualScrollerRef;
|
|
50
50
|
const visibleSortedRows = useGridSelector(apiRef, gridExpandedSortedRowEntriesSelector);
|
|
51
51
|
const scrollToIndexes = React.useCallback(params => {
|
|
@@ -31,8 +31,6 @@ export const gridRenderContextSelector = createSelector(gridVirtualizationSelect
|
|
|
31
31
|
* @ignore - do not document.
|
|
32
32
|
*/
|
|
33
33
|
export const gridRenderContextColumnsSelector = createSelectorMemoized(state => state.virtualization.renderContext.firstColumnIndex, state => state.virtualization.renderContext.lastColumnIndex, (firstColumnIndex, lastColumnIndex) => ({
|
|
34
|
-
firstRowIndex: -1,
|
|
35
|
-
lastRowIndex: -1,
|
|
36
34
|
firstColumnIndex,
|
|
37
35
|
lastColumnIndex
|
|
38
36
|
}));
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const UNINITIALIZED = {};
|
|
3
|
-
|
|
4
|
-
// See https://github.com/facebook/react/issues/14490 for when to use this.
|
|
5
|
-
export function useLazyRef(init, initArg) {
|
|
6
|
-
const ref = React.useRef(UNINITIALIZED);
|
|
7
|
-
if (ref.current === UNINITIALIZED) {
|
|
8
|
-
ref.current = init(initArg);
|
|
9
|
-
}
|
|
10
|
-
return ref;
|
|
11
|
-
}
|
|
1
|
+
export { default as useLazyRef } from '@mui/utils/useLazyRef';
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const EMPTY = [];
|
|
3
|
-
export function useOnMount(fn) {
|
|
4
|
-
/* eslint-disable react-hooks/exhaustive-deps */
|
|
5
|
-
React.useEffect(fn, EMPTY);
|
|
6
|
-
/* eslint-enable react-hooks/exhaustive-deps */
|
|
7
|
-
}
|
|
1
|
+
export { default as useOnMount } from '@mui/utils/useOnMount';
|
|
@@ -1,36 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { useLazyRef } from './useLazyRef';
|
|
4
|
-
import { useOnMount } from './useOnMount';
|
|
5
|
-
export class Timeout {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.currentId = null;
|
|
8
|
-
this.clear = () => {
|
|
9
|
-
if (this.currentId !== null) {
|
|
10
|
-
clearTimeout(this.currentId);
|
|
11
|
-
this.currentId = null;
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
this.disposeEffect = () => {
|
|
15
|
-
return this.clear;
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
static create() {
|
|
19
|
-
return new Timeout();
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Executes `fn` after `delay`, clearing any previously scheduled call.
|
|
23
|
-
*/
|
|
24
|
-
start(delay, fn) {
|
|
25
|
-
this.clear();
|
|
26
|
-
this.currentId = setTimeout(() => {
|
|
27
|
-
this.currentId = null;
|
|
28
|
-
fn();
|
|
29
|
-
}, delay);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
export function useTimeout() {
|
|
33
|
-
const timeout = useLazyRef(Timeout.create).current;
|
|
34
|
-
useOnMount(timeout.disposeEffect);
|
|
35
|
-
return timeout;
|
|
36
|
-
}
|
|
1
|
+
export { default as useTimeout } from '@mui/utils/useTimeout';
|
package/modern/index.js
CHANGED
|
@@ -3,7 +3,6 @@ export { GridVirtualScrollerContent } from '../components/virtualization/GridVir
|
|
|
3
3
|
export { GridVirtualScrollerRenderZone } from '../components/virtualization/GridVirtualScrollerRenderZone';
|
|
4
4
|
export { GridHeaders } from '../components/GridHeaders';
|
|
5
5
|
export { GridBaseColumnHeaders } from '../components/columnHeaders/GridBaseColumnHeaders';
|
|
6
|
-
export { GridColumnHeadersInner } from '../components/columnHeaders/GridColumnHeadersInner';
|
|
7
6
|
export { DATA_GRID_DEFAULT_SLOTS_COMPONENTS } from '../constants/defaultGridSlotsComponents';
|
|
8
7
|
export { getGridFilter } from '../components/panel/filterPanel/GridFilterPanel';
|
|
9
8
|
export { useGridRegisterPipeProcessor } from '../hooks/core/pipeProcessing';
|
|
@@ -49,6 +48,7 @@ export { dimensionsStateInitializer, useGridDimensions } from '../hooks/features
|
|
|
49
48
|
export { useGridStatePersistence } from '../hooks/features/statePersistence/useGridStatePersistence';
|
|
50
49
|
export { useGridVirtualScroller, EMPTY_DETAIL_PANELS } from '../hooks/features/virtualization/useGridVirtualScroller';
|
|
51
50
|
export * from '../hooks/features/virtualization';
|
|
51
|
+
export { useGridColumnResize, columnResizeStateInitializer } from '../hooks/features/columnResize/useGridColumnResize';
|
|
52
52
|
export { useTimeout } from '../hooks/utils/useTimeout';
|
|
53
53
|
export { useGridVisibleRows, getVisibleRows } from '../hooks/utils/useGridVisibleRows';
|
|
54
54
|
export { useGridInitializeState } from '../hooks/utils/useGridInitializeState';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { GridPinnedColumnPosition } from '../../hooks/features/columns';
|
|
2
|
+
export const getPinnedCellOffset = (pinnedPosition, computedWidth, columnIndex, columnPositions, dimensions) => {
|
|
3
|
+
const scrollbarWidth = dimensions.hasScrollY ? dimensions.scrollbarSize : 0;
|
|
4
|
+
let pinnedOffset;
|
|
5
|
+
switch (pinnedPosition) {
|
|
6
|
+
case GridPinnedColumnPosition.LEFT:
|
|
7
|
+
pinnedOffset = columnPositions[columnIndex];
|
|
8
|
+
break;
|
|
9
|
+
case GridPinnedColumnPosition.RIGHT:
|
|
10
|
+
pinnedOffset = dimensions.columnsTotalWidth - columnPositions[columnIndex] - computedWidth + scrollbarWidth;
|
|
11
|
+
break;
|
|
12
|
+
default:
|
|
13
|
+
pinnedOffset = 0;
|
|
14
|
+
break;
|
|
15
|
+
}
|
|
16
|
+
return pinnedOffset;
|
|
17
|
+
};
|