@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
|
@@ -53,9 +53,7 @@ export function useGridDimensions(apiRef, props) {
|
|
|
53
53
|
const rowHeight = Math.floor(props.rowHeight * densityFactor);
|
|
54
54
|
const headerHeight = Math.floor(props.columnHeaderHeight * densityFactor);
|
|
55
55
|
const columnsTotalWidth = roundToDecimalPlaces(gridColumnsTotalWidthSelector(apiRef), 6);
|
|
56
|
-
|
|
57
|
-
const hasHeaderFilters = Boolean(props.headerFilters);
|
|
58
|
-
const headersTotalHeight = getTotalHeaderHeight(apiRef, props.columnHeaderHeight) + Number(hasHeaderFilters) * headerHeight;
|
|
56
|
+
const headersTotalHeight = getTotalHeaderHeight(apiRef, props.columnHeaderHeight);
|
|
59
57
|
const leftPinnedWidth = pinnedColumns.left.reduce((w, col) => w + col.computedWidth, 0);
|
|
60
58
|
const rightPinnedWidth = pinnedColumns.right.reduce((w, col) => w + col.computedWidth, 0);
|
|
61
59
|
const [savedSize, setSavedSize] = React.useState();
|
|
@@ -112,8 +110,9 @@ export function useGridDimensions(apiRef, props) {
|
|
|
112
110
|
const scrollbarSize = measureScrollbarSize(rootElement, columnsTotalWidth, props.scrollbarSize);
|
|
113
111
|
const topContainerHeight = headersTotalHeight + pinnedRowsHeight.top;
|
|
114
112
|
const bottomContainerHeight = pinnedRowsHeight.bottom;
|
|
113
|
+
const nonPinnedColumnsTotalWidth = columnsTotalWidth - leftPinnedWidth - rightPinnedWidth;
|
|
115
114
|
const contentSize = {
|
|
116
|
-
width:
|
|
115
|
+
width: nonPinnedColumnsTotalWidth,
|
|
117
116
|
height: rowsMeta.currentPageTotalHeight
|
|
118
117
|
};
|
|
119
118
|
let viewportOuterSize;
|
|
@@ -162,7 +161,7 @@ export function useGridDimensions(apiRef, props) {
|
|
|
162
161
|
}
|
|
163
162
|
const rowWidth = Math.max(viewportOuterSize.width, columnsTotalWidth + (hasScrollY ? scrollbarSize : 0));
|
|
164
163
|
const minimumSize = {
|
|
165
|
-
width:
|
|
164
|
+
width: columnsTotalWidth,
|
|
166
165
|
height: topContainerHeight + contentSize.height + bottomContainerHeight
|
|
167
166
|
};
|
|
168
167
|
const newDimensions = {
|
|
@@ -14,7 +14,7 @@ import { buildWarning } from '../../../utils/warning';
|
|
|
14
14
|
import { gridRowsDataRowIdToIdLookupSelector } from '../rows/gridRowsSelector';
|
|
15
15
|
import { deepClone } from '../../../utils/utils';
|
|
16
16
|
import { GridCellEditStartReasons, GridCellEditStopReasons } from '../../../models/params/gridEditCellParams';
|
|
17
|
-
const missingOnProcessRowUpdateErrorWarning = buildWarning(['MUI X: A call to `processRowUpdate` threw an error which was not handled because `onProcessRowUpdateError` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError` prop,
|
|
17
|
+
const missingOnProcessRowUpdateErrorWarning = buildWarning(['MUI X: A call to `processRowUpdate` threw an error which was not handled because `onProcessRowUpdateError` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError` prop, for example `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/#server-side-persistence.'], 'error');
|
|
18
18
|
export const useGridCellEditing = (apiRef, props) => {
|
|
19
19
|
const [cellModesModel, setCellModesModel] = React.useState({});
|
|
20
20
|
const cellModesModelRef = React.useRef(cellModesModel);
|
|
@@ -234,8 +234,27 @@ export const useGridCellEditing = (apiRef, props) => {
|
|
|
234
234
|
initialValue
|
|
235
235
|
} = params;
|
|
236
236
|
let newValue = apiRef.current.getCellValue(id, field);
|
|
237
|
-
if (deleteValue
|
|
238
|
-
|
|
237
|
+
if (deleteValue) {
|
|
238
|
+
const fieldType = apiRef.current.getColumn(field).type;
|
|
239
|
+
switch (fieldType) {
|
|
240
|
+
case 'boolean':
|
|
241
|
+
newValue = false;
|
|
242
|
+
break;
|
|
243
|
+
case 'date':
|
|
244
|
+
case 'dateTime':
|
|
245
|
+
case 'number':
|
|
246
|
+
newValue = undefined;
|
|
247
|
+
break;
|
|
248
|
+
case 'singleSelect':
|
|
249
|
+
newValue = null;
|
|
250
|
+
break;
|
|
251
|
+
case 'string':
|
|
252
|
+
default:
|
|
253
|
+
newValue = '';
|
|
254
|
+
break;
|
|
255
|
+
}
|
|
256
|
+
} else if (initialValue) {
|
|
257
|
+
newValue = initialValue;
|
|
239
258
|
}
|
|
240
259
|
const newProps = {
|
|
241
260
|
value: newValue,
|
|
@@ -16,7 +16,7 @@ import { gridRowsDataRowIdToIdLookupSelector } from '../rows/gridRowsSelector';
|
|
|
16
16
|
import { deepClone } from '../../../utils/utils';
|
|
17
17
|
import { GridRowEditStopReasons, GridRowEditStartReasons } from '../../../models/params/gridRowParams';
|
|
18
18
|
import { GRID_ACTIONS_COLUMN_TYPE } from '../../../colDef';
|
|
19
|
-
const missingOnProcessRowUpdateErrorWarning = buildWarning(['MUI X: A call to `processRowUpdate` threw an error which was not handled because `onProcessRowUpdateError` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError` prop,
|
|
19
|
+
const missingOnProcessRowUpdateErrorWarning = buildWarning(['MUI X: A call to `processRowUpdate` threw an error which was not handled because `onProcessRowUpdateError` is missing.', 'To handle the error pass a callback to the `onProcessRowUpdateError` prop, for example `<DataGrid onProcessRowUpdateError={(error) => ...} />`.', 'For more detail, see https://mui.com/x/react-data-grid/editing/#server-side-persistence.'], 'error');
|
|
20
20
|
export const useGridRowEditing = (apiRef, props) => {
|
|
21
21
|
const [rowModesModel, setRowModesModel] = React.useState({});
|
|
22
22
|
const rowModesModelRef = React.useRef(rowModesModel);
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { GRID_CHECKBOX_SELECTION_COL_DEF } from '../../../../colDef';
|
|
2
2
|
import { buildWarning } from '../../../../utils/warning';
|
|
3
|
-
function sanitizeCellValue(value, delimiterCharacter) {
|
|
3
|
+
function sanitizeCellValue(value, delimiterCharacter, shouldAppendQuotes) {
|
|
4
4
|
if (typeof value === 'string') {
|
|
5
5
|
// Make sure value containing delimiter or line break won't be split into multiple rows
|
|
6
6
|
if ([delimiterCharacter, '\n', '\r', '"'].some(delimiter => value.includes(delimiter))) {
|
|
7
|
-
|
|
7
|
+
if (shouldAppendQuotes) {
|
|
8
|
+
return `"${value.replace(/"/g, '""')}"`;
|
|
9
|
+
}
|
|
10
|
+
return `${value.replace(/"/g, '""')}`;
|
|
8
11
|
}
|
|
9
12
|
return value;
|
|
10
13
|
}
|
|
@@ -13,7 +16,8 @@ function sanitizeCellValue(value, delimiterCharacter) {
|
|
|
13
16
|
export const serializeCellValue = (cellParams, options) => {
|
|
14
17
|
const {
|
|
15
18
|
delimiterCharacter,
|
|
16
|
-
ignoreValueFormatter
|
|
19
|
+
ignoreValueFormatter,
|
|
20
|
+
shouldAppendQuotes
|
|
17
21
|
} = options;
|
|
18
22
|
let value;
|
|
19
23
|
if (ignoreValueFormatter) {
|
|
@@ -30,7 +34,7 @@ export const serializeCellValue = (cellParams, options) => {
|
|
|
30
34
|
} else {
|
|
31
35
|
value = cellParams.formattedValue;
|
|
32
36
|
}
|
|
33
|
-
return sanitizeCellValue(value, delimiterCharacter);
|
|
37
|
+
return sanitizeCellValue(value, delimiterCharacter, shouldAppendQuotes);
|
|
34
38
|
};
|
|
35
39
|
const objectFormattedValueWarning = buildWarning(['MUI X: When the value of a field is an object or a `renderCell` is provided, the CSV export might not display the value correctly.', 'You can provide a `valueFormatter` with a string representation to be used.']);
|
|
36
40
|
class CSVRow {
|
|
@@ -47,7 +51,7 @@ class CSVRow {
|
|
|
47
51
|
if (value === null || value === undefined) {
|
|
48
52
|
this.rowString += '';
|
|
49
53
|
} else if (typeof this.options.sanitizeCellValue === 'function') {
|
|
50
|
-
this.rowString += this.options.sanitizeCellValue(value, this.options.delimiterCharacter);
|
|
54
|
+
this.rowString += this.options.sanitizeCellValue(value, this.options.delimiterCharacter, this.options.shouldAppendQuotes);
|
|
51
55
|
} else {
|
|
52
56
|
this.rowString += value;
|
|
53
57
|
}
|
|
@@ -62,10 +66,12 @@ const serializeRow = ({
|
|
|
62
66
|
columns,
|
|
63
67
|
getCellParams,
|
|
64
68
|
delimiterCharacter,
|
|
65
|
-
ignoreValueFormatter
|
|
69
|
+
ignoreValueFormatter,
|
|
70
|
+
shouldAppendQuotes
|
|
66
71
|
}) => {
|
|
67
72
|
const row = new CSVRow({
|
|
68
|
-
delimiterCharacter
|
|
73
|
+
delimiterCharacter,
|
|
74
|
+
shouldAppendQuotes
|
|
69
75
|
});
|
|
70
76
|
columns.forEach(column => {
|
|
71
77
|
const cellParams = getCellParams(id, column.field);
|
|
@@ -76,7 +82,8 @@ const serializeRow = ({
|
|
|
76
82
|
}
|
|
77
83
|
row.addValue(serializeCellValue(cellParams, {
|
|
78
84
|
delimiterCharacter,
|
|
79
|
-
ignoreValueFormatter
|
|
85
|
+
ignoreValueFormatter,
|
|
86
|
+
shouldAppendQuotes
|
|
80
87
|
}));
|
|
81
88
|
});
|
|
82
89
|
return row.getRowString();
|
|
@@ -89,14 +96,16 @@ export function buildCSV(options) {
|
|
|
89
96
|
includeHeaders,
|
|
90
97
|
includeColumnGroupsHeaders,
|
|
91
98
|
ignoreValueFormatter,
|
|
92
|
-
apiRef
|
|
99
|
+
apiRef,
|
|
100
|
+
shouldAppendQuotes
|
|
93
101
|
} = options;
|
|
94
102
|
const CSVBody = rowIds.reduce((acc, id) => `${acc}${serializeRow({
|
|
95
103
|
id,
|
|
96
104
|
columns,
|
|
97
105
|
getCellParams: apiRef.current.getCellParams,
|
|
98
106
|
delimiterCharacter,
|
|
99
|
-
ignoreValueFormatter
|
|
107
|
+
ignoreValueFormatter,
|
|
108
|
+
shouldAppendQuotes
|
|
100
109
|
})}\r\n`, '').trim();
|
|
101
110
|
if (!includeHeaders) {
|
|
102
111
|
return CSVBody;
|
|
@@ -115,7 +124,8 @@ export function buildCSV(options) {
|
|
|
115
124
|
for (let i = 0; i < maxColumnGroupsDepth; i += 1) {
|
|
116
125
|
const headerGroupRow = new CSVRow({
|
|
117
126
|
delimiterCharacter,
|
|
118
|
-
sanitizeCellValue
|
|
127
|
+
sanitizeCellValue,
|
|
128
|
+
shouldAppendQuotes
|
|
119
129
|
});
|
|
120
130
|
headerRows.push(headerGroupRow);
|
|
121
131
|
filteredColumns.forEach(column => {
|
|
@@ -127,7 +137,8 @@ export function buildCSV(options) {
|
|
|
127
137
|
}
|
|
128
138
|
const mainHeaderRow = new CSVRow({
|
|
129
139
|
delimiterCharacter,
|
|
130
|
-
sanitizeCellValue
|
|
140
|
+
sanitizeCellValue,
|
|
141
|
+
shouldAppendQuotes
|
|
131
142
|
});
|
|
132
143
|
filteredColumns.forEach(column => {
|
|
133
144
|
mainHeaderRow.addValue(column.headerName || column.field);
|
|
@@ -35,7 +35,8 @@ export const useGridCsvExport = (apiRef, props) => {
|
|
|
35
35
|
includeHeaders: options.includeHeaders ?? true,
|
|
36
36
|
includeColumnGroupsHeaders: options.includeColumnGroupsHeaders ?? true,
|
|
37
37
|
ignoreValueFormatter,
|
|
38
|
-
apiRef
|
|
38
|
+
apiRef,
|
|
39
|
+
shouldAppendQuotes: options.shouldAppendQuotes ?? true
|
|
39
40
|
});
|
|
40
41
|
}, [logger, apiRef, ignoreValueFormatter]);
|
|
41
42
|
const exportDataAsCsv = React.useCallback(options => {
|
|
@@ -8,7 +8,7 @@ import { gridClasses } from '../../../constants/gridClasses';
|
|
|
8
8
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
9
9
|
import { gridRowsMetaSelector } from '../rows/gridRowsMetaSelector';
|
|
10
10
|
import { defaultGetRowsToExport, getColumnsToExport } from './utils';
|
|
11
|
-
import {
|
|
11
|
+
import { getDerivedPaginationModel } from '../pagination/useGridPaginationModel';
|
|
12
12
|
import { useGridRegisterPipeProcessor } from '../../core/pipeProcessing';
|
|
13
13
|
import { GridPrintExportMenuItem } from '../../../components/toolbar/GridToolbarExport';
|
|
14
14
|
import { getTotalHeaderHeight } from '../columns/gridColumnsUtils';
|
|
@@ -95,9 +95,6 @@ export const useGridPrintExport = (apiRef, props) => {
|
|
|
95
95
|
|
|
96
96
|
// See https://support.google.com/chrome/thread/191619088?hl=en&msgid=193009642
|
|
97
97
|
gridClone.style.contain = 'size';
|
|
98
|
-
const columnHeaders = gridClone.querySelector(`.${gridClasses.columnHeaders}`);
|
|
99
|
-
const columnHeadersInner = columnHeaders.querySelector(`.${gridClasses.columnHeadersInner}`);
|
|
100
|
-
columnHeadersInner.style.width = '100%';
|
|
101
98
|
let gridToolbarElementHeight = gridRootElement.querySelector(`.${gridClasses.toolbarContainer}`)?.offsetHeight || 0;
|
|
102
99
|
let gridFooterElementHeight = gridRootElement.querySelector(`.${gridClasses.footerContainer}`)?.offsetHeight || 0;
|
|
103
100
|
if (normalizeOptions.hideToolbar) {
|
|
@@ -218,9 +215,13 @@ export const useGridPrintExport = (apiRef, props) => {
|
|
|
218
215
|
page: 0,
|
|
219
216
|
pageSize: visibleRowCount
|
|
220
217
|
};
|
|
221
|
-
apiRef.current.
|
|
222
|
-
|
|
223
|
-
|
|
218
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
219
|
+
pagination: _extends({}, state.pagination, {
|
|
220
|
+
paginationModel: getDerivedPaginationModel(state.pagination,
|
|
221
|
+
// Using signature `DataGridPro` to allow more than 100 rows in the print export
|
|
222
|
+
'DataGridPro', paginationModel)
|
|
223
|
+
})
|
|
224
|
+
}));
|
|
224
225
|
apiRef.current.forceUpdate();
|
|
225
226
|
}
|
|
226
227
|
await updateGridColumnsForPrint(options?.fields, options?.allColumns, options?.includeCheckboxes);
|
|
@@ -156,7 +156,7 @@ const buildAggregatedFilterItemsApplier = (filterModel, apiRef, disableEval) =>
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
// We generate a new function with `new Function()` to avoid expensive patterns for JS engines
|
|
159
|
-
// such as a dynamic object assignment,
|
|
159
|
+
// such as a dynamic object assignment, for example `{ [dynamicKey]: value }`.
|
|
160
160
|
const filterItemCore = new Function('appliers', 'row', 'shouldApplyFilter', `"use strict";
|
|
161
161
|
${appliers.map((applier, i) => `const shouldApply${i} = !shouldApplyFilter || shouldApplyFilter(${JSON.stringify(applier.item.field)});`).join('\n')}
|
|
162
162
|
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { createSelector } from '../../../utils/createSelector';
|
|
2
2
|
export const gridHeaderFilteringStateSelector = state => state.headerFiltering;
|
|
3
|
+
export const gridHeaderFilteringEnabledSelector = createSelector(gridHeaderFilteringStateSelector,
|
|
4
|
+
// No initialization in MIT, so we need to default to false to be used by `getTotalHeaderHeight`
|
|
5
|
+
headerFilteringState => headerFilteringState?.enabled ?? false);
|
|
3
6
|
export const gridHeaderFilteringEditFieldSelector = createSelector(gridHeaderFilteringStateSelector, headerFilteringState => headerFilteringState.editing);
|
|
4
7
|
export const gridHeaderFilteringMenuSelector = createSelector(gridHeaderFilteringStateSelector, headerFilteringState => headerFilteringState.menuOpen);
|
|
@@ -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
|
};
|