@mui/x-data-grid 7.0.0-beta.6 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +311 -12
- package/DataGrid/DataGrid.js +57 -17
- package/DataGrid/useDataGridComponent.js +3 -0
- package/DataGrid/useDataGridProps.js +6 -7
- package/README.md +1 -1
- package/components/GridColumnHeaders.d.ts +1 -2
- package/components/GridColumnHeaders.js +6 -17
- package/components/GridFooter.js +2 -3
- package/components/GridHeader.js +1 -2
- package/components/GridHeaders.js +1 -4
- package/components/GridPagination.d.ts +6 -5
- package/components/GridPagination.js +14 -11
- package/components/GridRow.d.ts +1 -1
- package/components/GridRow.js +17 -36
- package/components/GridScrollArea.d.ts +10 -0
- package/components/GridScrollArea.js +150 -0
- package/components/base/GridFooterPlaceholder.js +1 -2
- package/components/base/GridOverlays.js +3 -6
- package/components/cell/GridActionsCell.js +4 -6
- package/components/cell/GridActionsCellItem.d.ts +8 -25
- package/components/cell/GridActionsCellItem.js +8 -5
- package/components/cell/GridBooleanCell.d.ts +1 -0
- package/components/cell/GridBooleanCell.js +3 -2
- package/components/cell/GridCell.d.ts +7 -0
- package/components/cell/GridCell.js +18 -11
- package/components/cell/GridEditBooleanCell.js +1 -2
- package/components/cell/GridEditDateCell.js +2 -3
- package/components/cell/GridEditInputCell.js +2 -2
- package/components/cell/GridEditSingleSelectCell.js +5 -8
- package/components/columnHeaders/ColumnHeaderMenuIcon.js +2 -3
- package/components/columnHeaders/GridBaseColumnHeaders.js +1 -0
- package/components/columnHeaders/GridColumnGroupHeader.d.ts +5 -0
- package/components/columnHeaders/GridColumnGroupHeader.js +22 -13
- package/components/columnHeaders/GridColumnHeaderFilterIconButton.js +2 -3
- package/components/columnHeaders/GridColumnHeaderItem.d.ts +5 -0
- package/components/columnHeaders/GridColumnHeaderItem.js +26 -12
- package/components/columnHeaders/GridColumnHeaderSortIcon.js +1 -2
- package/components/columnHeaders/GridColumnHeaderTitle.js +2 -3
- package/components/columnHeaders/GridGenericColumnHeaderItem.d.ts +1 -0
- package/components/columnHeaders/GridGenericColumnHeaderItem.js +7 -6
- package/components/columnSelection/GridCellCheckboxRenderer.js +3 -5
- package/components/columnSelection/GridHeaderCheckbox.js +1 -2
- package/components/columnsManagement/GridColumnsManagement.js +17 -21
- package/components/containers/GridRoot.js +3 -3
- package/components/containers/GridRootStyles.js +12 -20
- package/components/menu/GridMenu.js +4 -6
- package/components/menu/columnMenu/GridColumnHeaderMenu.js +1 -1
- package/components/menu/columnMenu/menuItems/GridColumnMenuSortItem.js +2 -3
- package/components/panel/GridColumnsPanel.js +1 -2
- package/components/panel/GridPanel.d.ts +1 -10
- package/components/panel/GridPanel.js +1 -2
- package/components/panel/GridPreferencesPanel.js +2 -3
- package/components/panel/filterPanel/GridFilterForm.js +24 -27
- package/components/panel/filterPanel/GridFilterInputBoolean.d.ts +1 -1
- package/components/panel/filterPanel/GridFilterInputBoolean.js +6 -7
- package/components/panel/filterPanel/GridFilterInputDate.d.ts +1 -1
- package/components/panel/filterPanel/GridFilterInputDate.js +3 -4
- package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +11 -15
- package/components/panel/filterPanel/GridFilterInputMultipleValue.js +10 -14
- package/components/panel/filterPanel/GridFilterInputSingleSelect.d.ts +1 -1
- package/components/panel/filterPanel/GridFilterInputSingleSelect.js +10 -11
- package/components/panel/filterPanel/GridFilterInputValue.d.ts +1 -1
- package/components/panel/filterPanel/GridFilterInputValue.js +5 -7
- package/components/panel/filterPanel/GridFilterPanel.js +5 -9
- package/components/panel/filterPanel/filterPanelUtils.js +1 -1
- package/components/toolbar/GridToolbarColumnsButton.js +3 -5
- package/components/toolbar/GridToolbarDensitySelector.js +8 -10
- package/components/toolbar/GridToolbarExport.js +2 -2
- package/components/toolbar/GridToolbarExportContainer.js +3 -5
- package/components/toolbar/GridToolbarFilterButton.js +3 -5
- package/components/toolbar/GridToolbarQuickFilter.js +4 -5
- package/components/virtualization/GridVirtualScrollbar.js +4 -0
- package/components/virtualization/GridVirtualScroller.js +6 -1
- package/components/virtualization/GridVirtualScrollerContent.js +1 -2
- package/components/virtualization/GridVirtualScrollerFiller.js +2 -1
- package/components/virtualization/GridVirtualScrollerRenderZone.js +1 -2
- package/constants/gridClasses.d.ts +6 -32
- package/constants/gridClasses.js +1 -1
- package/hooks/core/pipeProcessing/gridPipeProcessingApi.d.ts +5 -1
- package/hooks/core/strategyProcessing/useGridStrategyProcessing.js +1 -2
- package/hooks/core/useGridApiInitialization.js +4 -6
- package/hooks/features/clipboard/useGridClipboard.js +6 -5
- package/hooks/features/columnGrouping/gridColumnGroupsSelector.js +4 -16
- package/hooks/features/columnGrouping/gridColumnGroupsUtils.js +4 -8
- package/hooks/features/columnGrouping/useGridColumnGrouping.js +12 -23
- package/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +23 -7
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +186 -101
- package/hooks/features/columnMenu/useGridColumnMenuSlots.js +2 -2
- 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 +553 -0
- package/hooks/features/columns/gridColumnsSelector.js +1 -2
- package/hooks/features/columns/gridColumnsUtils.d.ts +0 -9
- package/hooks/features/columns/gridColumnsUtils.js +5 -22
- package/hooks/features/columns/useGridColumnSpanning.js +1 -2
- package/hooks/features/columns/useGridColumns.js +11 -19
- package/hooks/features/density/densitySelector.d.ts +4 -2
- package/hooks/features/density/densitySelector.js +8 -2
- package/hooks/features/density/densityState.d.ts +1 -4
- package/hooks/features/density/useGridDensity.d.ts +2 -4
- package/hooks/features/density/useGridDensity.js +21 -29
- package/hooks/features/dimensions/useGridDimensions.js +7 -10
- package/hooks/features/editing/useGridCellEditing.js +25 -8
- package/hooks/features/editing/useGridEditing.js +1 -2
- package/hooks/features/editing/useGridRowEditing.js +4 -6
- package/hooks/features/export/serializers/csvSerializer.d.ts +2 -0
- package/hooks/features/export/serializers/csvSerializer.js +25 -16
- package/hooks/features/export/useGridCsvExport.js +9 -10
- package/hooks/features/export/useGridPrintExport.js +17 -22
- package/hooks/features/export/utils.js +2 -3
- package/hooks/features/filter/gridFilterSelector.js +15 -22
- package/hooks/features/filter/gridFilterUtils.js +10 -16
- package/hooks/features/filter/useGridFilter.js +9 -15
- package/hooks/features/focus/useGridFocus.js +5 -6
- package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.d.ts +1 -0
- package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +3 -0
- package/hooks/features/headerFiltering/useGridHeaderFiltering.js +23 -5
- package/hooks/features/index.d.ts +1 -0
- package/hooks/features/index.js +1 -0
- package/hooks/features/keyboardNavigation/useGridKeyboardNavigation.js +1 -2
- package/hooks/features/pagination/gridPaginationInterfaces.d.ts +19 -2
- package/hooks/features/pagination/gridPaginationSelector.d.ts +5 -0
- package/hooks/features/pagination/gridPaginationSelector.js +9 -4
- package/hooks/features/pagination/useGridPagination.d.ts +1 -6
- package/hooks/features/pagination/useGridPagination.js +9 -158
- package/hooks/features/pagination/useGridPaginationModel.d.ts +11 -0
- package/hooks/features/pagination/useGridPaginationModel.js +165 -0
- package/hooks/features/pagination/useGridRowCount.d.ts +8 -0
- package/hooks/features/pagination/useGridRowCount.js +94 -0
- package/hooks/features/preferencesPanel/useGridPreferencesPanel.js +7 -12
- package/hooks/features/rowSelection/useGridRowSelection.js +11 -16
- package/hooks/features/rows/gridRowsSelector.js +11 -19
- package/hooks/features/rows/gridRowsUtils.js +7 -9
- package/hooks/features/rows/useGridParamsApi.js +1 -1
- package/hooks/features/rows/useGridRows.js +4 -13
- package/hooks/features/rows/useGridRowsMeta.js +7 -13
- package/hooks/features/scroll/useGridScroll.js +3 -4
- package/hooks/features/sorting/gridSortingSelector.js +4 -7
- package/hooks/features/sorting/useGridSorting.js +8 -14
- package/hooks/features/virtualization/gridVirtualizationSelectors.d.ts +4 -4
- package/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +3 -3
- package/hooks/features/virtualization/useGridVirtualScroller.js +220 -71
- package/hooks/utils/useGridApiEventHandler.js +5 -10
- package/hooks/utils/useGridNativeEventListener.js +1 -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 +3 -1
- package/internals/index.js +2 -1
- package/internals/utils/getPinnedCellOffset.d.ts +3 -0
- package/internals/utils/getPinnedCellOffset.js +17 -0
- package/internals/utils/useProps.js +1 -2
- package/joy/joySlots.js +18 -63
- 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/api/gridRowsMetaApi.d.ts +1 -1
- package/models/api/index.d.ts +1 -1
- package/models/api/index.js +0 -1
- package/models/events/gridEventLookup.d.ts +13 -0
- package/models/gridExport.d.ts +6 -0
- package/models/gridHeaderFilteringModel.d.ts +1 -0
- package/models/gridSlotsComponent.d.ts +0 -5
- package/models/gridStateCommunity.d.ts +3 -0
- package/models/params/gridScrollParams.d.ts +5 -3
- package/models/props/DataGridProps.d.ts +58 -28
- package/modern/DataGrid/DataGrid.js +57 -17
- package/modern/DataGrid/useDataGridComponent.js +3 -0
- package/modern/DataGrid/useDataGridProps.js +6 -7
- package/modern/components/GridColumnHeaders.js +6 -17
- package/modern/components/GridHeaders.js +1 -4
- package/modern/components/GridPagination.js +13 -6
- package/modern/components/GridRow.js +4 -19
- package/modern/components/GridScrollArea.js +150 -0
- package/modern/components/cell/GridActionsCell.js +1 -1
- package/modern/components/cell/GridActionsCellItem.js +4 -0
- package/modern/components/cell/GridBooleanCell.js +3 -2
- 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/GridRoot.js +3 -3
- package/modern/components/containers/GridRootStyles.js +12 -20
- package/modern/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
- package/modern/components/panel/filterPanel/GridFilterInputDate.js +1 -1
- package/modern/components/panel/filterPanel/GridFilterInputSingleSelect.js +1 -1
- package/modern/components/panel/filterPanel/GridFilterInputValue.js +1 -1
- package/modern/components/toolbar/GridToolbarDensitySelector.js +5 -5
- 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/clipboard/useGridClipboard.js +4 -2
- 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 -20
- package/modern/hooks/features/density/densitySelector.js +8 -2
- package/modern/hooks/features/density/useGridDensity.js +21 -29
- package/modern/hooks/features/dimensions/useGridDimensions.js +4 -5
- package/modern/hooks/features/editing/useGridCellEditing.js +22 -3
- package/modern/hooks/features/editing/useGridRowEditing.js +1 -1
- package/modern/hooks/features/export/serializers/csvSerializer.js +23 -12
- package/modern/hooks/features/export/useGridCsvExport.js +2 -1
- package/modern/hooks/features/export/useGridPrintExport.js +8 -7
- package/modern/hooks/features/filter/gridFilterUtils.js +1 -1
- 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/rowSelection/useGridRowSelection.js +3 -2
- package/modern/hooks/features/scroll/useGridScroll.js +1 -1
- package/modern/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +211 -57
- 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 +2 -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/models/api/index.js +0 -1
- package/modern/utils/cellBorderUtils.js +8 -0
- package/modern/utils/createSelector.js +1 -1
- package/modern/utils/domUtils.js +144 -0
- package/modern/utils/keyboardUtils.js +1 -1
- package/node/DataGrid/DataGrid.js +57 -17
- package/node/DataGrid/useDataGridComponent.js +3 -0
- package/node/DataGrid/useDataGridProps.js +6 -7
- package/node/components/GridColumnHeaders.js +6 -16
- package/node/components/GridHeaders.js +1 -4
- package/node/components/GridPagination.js +10 -4
- package/node/components/GridRow.js +3 -18
- package/node/components/GridScrollArea.js +158 -0
- package/node/components/cell/GridActionsCell.js +1 -1
- package/node/components/cell/GridActionsCellItem.js +4 -0
- package/node/components/cell/GridBooleanCell.js +3 -2
- 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/GridRoot.js +2 -2
- package/node/components/containers/GridRootStyles.js +12 -20
- package/node/components/panel/filterPanel/GridFilterInputBoolean.js +1 -1
- package/node/components/panel/filterPanel/GridFilterInputDate.js +1 -1
- package/node/components/panel/filterPanel/GridFilterInputSingleSelect.js +1 -1
- package/node/components/panel/filterPanel/GridFilterInputValue.js +1 -1
- package/node/components/toolbar/GridToolbarDensitySelector.js +4 -4
- 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/clipboard/useGridClipboard.js +4 -2
- 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 -21
- package/node/hooks/features/density/densitySelector.js +9 -3
- package/node/hooks/features/density/useGridDensity.js +22 -30
- package/node/hooks/features/dimensions/useGridDimensions.js +4 -5
- package/node/hooks/features/editing/useGridCellEditing.js +22 -3
- package/node/hooks/features/editing/useGridRowEditing.js +1 -1
- package/node/hooks/features/export/serializers/csvSerializer.js +23 -12
- package/node/hooks/features/export/useGridCsvExport.js +2 -1
- package/node/hooks/features/export/useGridPrintExport.js +8 -7
- package/node/hooks/features/filter/gridFilterUtils.js +1 -1
- 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/rowSelection/useGridRowSelection.js +2 -1
- package/node/hooks/features/scroll/useGridScroll.js +1 -1
- package/node/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +211 -57
- 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 +27 -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/models/api/index.js +0 -11
- package/node/utils/cellBorderUtils.js +16 -0
- package/node/utils/createSelector.js +1 -1
- package/node/utils/domUtils.js +155 -0
- package/node/utils/keyboardUtils.js +1 -1
- package/package.json +4 -4
- package/utils/cellBorderUtils.d.ts +3 -0
- package/utils/cellBorderUtils.js +8 -0
- package/utils/createSelector.js +9 -9
- package/utils/domUtils.d.ts +14 -1
- package/utils/domUtils.js +144 -0
- package/utils/getGridLocalization.js +9 -12
- package/utils/keyboardUtils.js +1 -1
- 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,173 +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
|
-
|
|
11
|
-
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);
|
|
6
|
+
const paginationModel = _extends({}, getDefaultGridPaginationModel(props.autoPageSize), props.paginationModel ?? props.initialState?.pagination?.paginationModel);
|
|
12
7
|
throwIfPageSizeExceedsTheLimit(paginationModel.pageSize, props.signature);
|
|
8
|
+
const rowCount = props.rowCount ?? props.initialState?.pagination?.rowCount;
|
|
13
9
|
return _extends({}, state, {
|
|
14
10
|
pagination: {
|
|
15
|
-
paginationModel
|
|
11
|
+
paginationModel,
|
|
12
|
+
rowCount
|
|
16
13
|
}
|
|
17
14
|
});
|
|
18
15
|
};
|
|
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
16
|
|
|
39
17
|
/**
|
|
40
18
|
* @requires useGridFilter (state)
|
|
41
19
|
* @requires useGridDimensions (event) - can be after
|
|
42
20
|
*/
|
|
43
21
|
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]);
|
|
22
|
+
useGridPaginationModel(apiRef, props);
|
|
23
|
+
useGridRowCount(apiRef, props);
|
|
173
24
|
};
|
|
@@ -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,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,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;
|
|
@@ -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
|
+
};
|
|
@@ -4,20 +4,16 @@ import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
|
4
4
|
import { useGridLogger } from '../../utils/useGridLogger';
|
|
5
5
|
import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
|
|
6
6
|
import { gridPreferencePanelStateSelector } from './gridPreferencePanelSelector';
|
|
7
|
-
export const preferencePanelStateInitializer = (state, props) => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
});
|
|
14
|
-
};
|
|
7
|
+
export const preferencePanelStateInitializer = (state, props) => _extends({}, state, {
|
|
8
|
+
preferencePanel: props.initialState?.preferencePanel ?? {
|
|
9
|
+
open: false
|
|
10
|
+
}
|
|
11
|
+
});
|
|
15
12
|
|
|
16
13
|
/**
|
|
17
14
|
* TODO: Add a single `setPreferencePanel` method to avoid multiple `setState`
|
|
18
15
|
*/
|
|
19
16
|
export const useGridPreferencesPanel = (apiRef, props) => {
|
|
20
|
-
var _props$initialState3;
|
|
21
17
|
const logger = useGridLogger(apiRef, 'useGridPreferencesPanel');
|
|
22
18
|
const hideTimeout = React.useRef();
|
|
23
19
|
const immediateTimeout = React.useRef();
|
|
@@ -77,13 +73,12 @@ export const useGridPreferencesPanel = (apiRef, props) => {
|
|
|
77
73
|
* PRE-PROCESSING
|
|
78
74
|
*/
|
|
79
75
|
const stateExportPreProcessing = React.useCallback((prevState, context) => {
|
|
80
|
-
var _props$initialState2;
|
|
81
76
|
const preferencePanelToExport = gridPreferencePanelStateSelector(apiRef.current.state);
|
|
82
77
|
const shouldExportPreferencePanel =
|
|
83
78
|
// Always export if the `exportOnlyDirtyModels` property is not activated
|
|
84
79
|
!context.exportOnlyDirtyModels ||
|
|
85
80
|
// Always export if the panel was initialized
|
|
86
|
-
|
|
81
|
+
props.initialState?.preferencePanel != null ||
|
|
87
82
|
// Always export if the panel is opened
|
|
88
83
|
preferencePanelToExport.open;
|
|
89
84
|
if (!shouldExportPreferencePanel) {
|
|
@@ -92,7 +87,7 @@ export const useGridPreferencesPanel = (apiRef, props) => {
|
|
|
92
87
|
return _extends({}, prevState, {
|
|
93
88
|
preferencePanel: preferencePanelToExport
|
|
94
89
|
});
|
|
95
|
-
}, [apiRef,
|
|
90
|
+
}, [apiRef, props.initialState?.preferencePanel]);
|
|
96
91
|
const stateRestorePreProcessing = React.useCallback((params, context) => {
|
|
97
92
|
const preferencePanel = context.stateToRestore.preferencePanel;
|
|
98
93
|
if (preferencePanel != null) {
|
|
@@ -7,7 +7,7 @@ import { gridRowsLookupSelector } from '../rows/gridRowsSelector';
|
|
|
7
7
|
import { gridRowSelectionStateSelector, selectedGridRowsSelector, selectedIdsLookupSelector } from './gridRowSelectionSelector';
|
|
8
8
|
import { gridPaginatedVisibleSortedGridRowIdsSelector } from '../pagination';
|
|
9
9
|
import { gridFocusCellSelector } from '../focus/gridFocusStateSelector';
|
|
10
|
-
import { gridExpandedSortedRowIdsSelector } from '../filter/gridFilterSelector';
|
|
10
|
+
import { gridExpandedSortedRowIdsSelector, gridFilterModelSelector } from '../filter/gridFilterSelector';
|
|
11
11
|
import { GRID_CHECKBOX_SELECTION_COL_DEF, GRID_ACTIONS_COLUMN_TYPE } from '../../../colDef';
|
|
12
12
|
import { GridCellModes } from '../../../models/gridEditRowModel';
|
|
13
13
|
import { isKeyboardEvent, isNavigationKey } from '../../../utils/keyboardUtils';
|
|
@@ -28,12 +28,9 @@ const getSelectionModelPropValue = (selectionModelProp, prevSelectionModel) => {
|
|
|
28
28
|
}
|
|
29
29
|
return [selectionModelProp];
|
|
30
30
|
};
|
|
31
|
-
export const rowSelectionStateInitializer = (state, props) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
rowSelection: props.rowSelection ? (_getSelectionModelPro = getSelectionModelPropValue(props.rowSelectionModel)) != null ? _getSelectionModelPro : [] : []
|
|
35
|
-
});
|
|
36
|
-
};
|
|
31
|
+
export const rowSelectionStateInitializer = (state, props) => _extends({}, state, {
|
|
32
|
+
rowSelection: props.rowSelection ? getSelectionModelPropValue(props.rowSelectionModel) ?? [] : []
|
|
33
|
+
});
|
|
37
34
|
|
|
38
35
|
/**
|
|
39
36
|
* @requires useGridRows (state, method) - can be after
|
|
@@ -67,9 +64,8 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
67
64
|
const canHaveMultipleSelection = isMultipleRowSelectionEnabled(props);
|
|
68
65
|
const visibleRows = useGridVisibleRows(apiRef, props);
|
|
69
66
|
const expandMouseRowRangeSelection = React.useCallback(id => {
|
|
70
|
-
var _lastRowToggled$curre;
|
|
71
67
|
let endId = id;
|
|
72
|
-
const startId =
|
|
68
|
+
const startId = lastRowToggled.current ?? id;
|
|
73
69
|
const isSelected = apiRef.current.isRowSelected(id);
|
|
74
70
|
if (isSelected) {
|
|
75
71
|
const visibleRowIds = gridExpandedSortedRowIdsSelector(apiRef);
|
|
@@ -113,7 +109,7 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
113
109
|
return false;
|
|
114
110
|
}
|
|
115
111
|
const rowNode = apiRef.current.getRowNode(id);
|
|
116
|
-
if (
|
|
112
|
+
if (rowNode?.type === 'footer' || rowNode?.type === 'pinnedRow') {
|
|
117
113
|
return false;
|
|
118
114
|
}
|
|
119
115
|
return true;
|
|
@@ -235,11 +231,10 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
235
231
|
}
|
|
236
232
|
}, [apiRef, canHaveMultipleSelection, checkboxSelection]);
|
|
237
233
|
const handleRowClick = React.useCallback((params, event) => {
|
|
238
|
-
var _closest;
|
|
239
234
|
if (disableRowSelectionOnClick) {
|
|
240
235
|
return;
|
|
241
236
|
}
|
|
242
|
-
const field =
|
|
237
|
+
const field = event.target.closest(`.${gridClasses.cell}`)?.getAttribute('data-field');
|
|
243
238
|
if (field === GRID_CHECKBOX_SELECTION_COL_DEF.field) {
|
|
244
239
|
// click on checkbox should not trigger row selection
|
|
245
240
|
return;
|
|
@@ -250,7 +245,7 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
250
245
|
}
|
|
251
246
|
if (field) {
|
|
252
247
|
const column = apiRef.current.getColumn(field);
|
|
253
|
-
if (
|
|
248
|
+
if (column?.type === GRID_ACTIONS_COLUMN_TYPE) {
|
|
254
249
|
return;
|
|
255
250
|
}
|
|
256
251
|
}
|
|
@@ -266,8 +261,7 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
266
261
|
}, [disableRowSelectionOnClick, canHaveMultipleSelection, apiRef, expandMouseRowRangeSelection, handleSingleRowSelection]);
|
|
267
262
|
const preventSelectionOnShift = React.useCallback((params, event) => {
|
|
268
263
|
if (canHaveMultipleSelection && event.shiftKey) {
|
|
269
|
-
|
|
270
|
-
(_window$getSelection = window.getSelection()) == null || _window$getSelection.removeAllRanges();
|
|
264
|
+
window.getSelection()?.removeAllRanges();
|
|
271
265
|
}
|
|
272
266
|
}, [canHaveMultipleSelection]);
|
|
273
267
|
const handleRowSelectionCheckboxChange = React.useCallback((params, event) => {
|
|
@@ -280,7 +274,8 @@ export const useGridRowSelection = (apiRef, props) => {
|
|
|
280
274
|
const handleHeaderSelectionCheckboxChange = React.useCallback(params => {
|
|
281
275
|
const shouldLimitSelectionToCurrentPage = props.checkboxSelectionVisibleOnly && props.pagination;
|
|
282
276
|
const rowsToBeSelected = shouldLimitSelectionToCurrentPage ? gridPaginatedVisibleSortedGridRowIdsSelector(apiRef) : gridExpandedSortedRowIdsSelector(apiRef);
|
|
283
|
-
apiRef
|
|
277
|
+
const filterModel = gridFilterModelSelector(apiRef);
|
|
278
|
+
apiRef.current.selectRows(rowsToBeSelected, params.value, filterModel?.items.length > 0);
|
|
284
279
|
}, [apiRef, props.checkboxSelectionVisibleOnly, props.pagination]);
|
|
285
280
|
const handleCellKeyDown = React.useCallback((params, event) => {
|
|
286
281
|
// Get the most recent cell mode because it may have been changed by another listener
|
|
@@ -22,29 +22,22 @@ export const gridDataRowIdsSelector = createSelector(gridRowsStateSelector, rows
|
|
|
22
22
|
/**
|
|
23
23
|
* @ignore - do not document.
|
|
24
24
|
*/
|
|
25
|
-
export const gridAdditionalRowGroupsSelector = createSelector(gridRowsStateSelector, rows => rows
|
|
25
|
+
export const gridAdditionalRowGroupsSelector = createSelector(gridRowsStateSelector, rows => rows?.additionalRowGroups);
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
28
|
* @ignore - do not document.
|
|
29
29
|
*/
|
|
30
30
|
export const gridPinnedRowsSelector = createSelectorMemoized(gridAdditionalRowGroupsSelector, additionalRowGroups => {
|
|
31
|
-
|
|
32
|
-
const rawPinnedRows = additionalRowGroups == null ? void 0 : additionalRowGroups.pinnedRows;
|
|
31
|
+
const rawPinnedRows = additionalRowGroups?.pinnedRows;
|
|
33
32
|
return {
|
|
34
|
-
bottom:
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
var _rowEntry$model2;
|
|
43
|
-
return {
|
|
44
|
-
id: rowEntry.id,
|
|
45
|
-
model: (_rowEntry$model2 = rowEntry.model) != null ? _rowEntry$model2 : {}
|
|
46
|
-
};
|
|
47
|
-
})) != null ? _rawPinnedRows$top$ma : []
|
|
33
|
+
bottom: rawPinnedRows?.bottom?.map(rowEntry => ({
|
|
34
|
+
id: rowEntry.id,
|
|
35
|
+
model: rowEntry.model ?? {}
|
|
36
|
+
})) ?? [],
|
|
37
|
+
top: rawPinnedRows?.top?.map(rowEntry => ({
|
|
38
|
+
id: rowEntry.id,
|
|
39
|
+
model: rowEntry.model ?? {}
|
|
40
|
+
})) ?? []
|
|
48
41
|
};
|
|
49
42
|
});
|
|
50
43
|
|
|
@@ -52,6 +45,5 @@ export const gridPinnedRowsSelector = createSelectorMemoized(gridAdditionalRowGr
|
|
|
52
45
|
* @ignore - do not document.
|
|
53
46
|
*/
|
|
54
47
|
export const gridPinnedRowsCountSelector = createSelector(gridPinnedRowsSelector, pinnedRows => {
|
|
55
|
-
|
|
56
|
-
return ((pinnedRows == null || (_pinnedRows$top = pinnedRows.top) == null ? void 0 : _pinnedRows$top.length) || 0) + ((pinnedRows == null || (_pinnedRows$bottom = pinnedRows.bottom) == null ? void 0 : _pinnedRows$bottom.length) || 0);
|
|
48
|
+
return (pinnedRows?.top?.length || 0) + (pinnedRows?.bottom?.length || 0);
|
|
57
49
|
});
|