@mui/x-data-grid 5.6.0 → 5.6.1
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 +43 -0
- package/DataGrid/DataGrid.js +18 -3
- package/DataGrid/useDataGridComponent.js +19 -15
- package/DataGrid/useDataGridProps.js +3 -2
- package/colDef/gridNumericOperators.d.ts +1 -1
- package/colDef/gridNumericOperators.js +1 -1
- package/components/ErrorBoundary.d.ts +2 -2
- package/components/GridRow.js +29 -3
- package/components/base/GridErrorHandler.d.ts +8 -2
- package/components/base/GridErrorHandler.js +13 -2
- package/components/cell/GridBooleanCell.d.ts +2 -1
- package/components/cell/GridCell.js +4 -2
- package/components/cell/GridEditBooleanCell.d.ts +2 -1
- package/components/cell/GridEditDateCell.d.ts +2 -1
- package/components/cell/GridEditInputCell.d.ts +2 -1
- package/components/cell/GridEditSingleSelectCell.d.ts +2 -1
- package/components/cell/GridEditSingleSelectCell.js +2 -1
- package/components/columnHeaders/GridColumnHeaderItem.js +5 -3
- package/components/containers/GridRootStyles.js +1 -1
- package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.d.ts +2 -1
- package/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +27 -23
- package/components/panel/filterPanel/filterPanelUtils.d.ts +2 -2
- package/components/virtualization/GridVirtualScrollerRenderZone.js +4 -1
- package/constants/gridClasses.d.ts +5 -1
- package/constants/gridClasses.js +1 -1
- package/context/GridContextProvider.d.ts +9 -6
- package/hooks/features/columnMenu/useGridColumnMenu.d.ts +2 -0
- package/hooks/features/columnMenu/useGridColumnMenu.js +6 -7
- package/hooks/features/columns/gridColumnsSelector.d.ts +8 -8
- package/hooks/features/columns/gridColumnsSelector.js +11 -10
- package/hooks/features/columns/gridColumnsUtils.js +7 -5
- package/hooks/features/density/useGridDensity.d.ts +2 -0
- package/hooks/features/density/useGridDensity.js +3 -4
- package/hooks/features/dimensions/useGridDimensions.js +2 -2
- package/hooks/features/editRows/useGridEditing.d.ts +2 -0
- package/hooks/features/editRows/useGridEditing.js +3 -4
- package/hooks/features/export/serializers/csvSerializer.js +4 -4
- package/hooks/features/filter/gridFilterSelector.d.ts +1 -0
- package/hooks/features/filter/gridFilterSelector.js +1 -0
- package/hooks/features/focus/useGridFocus.d.ts +2 -0
- package/hooks/features/focus/useGridFocus.js +10 -11
- package/hooks/features/keyboard/useGridKeyboardNavigation.js +2 -2
- package/hooks/features/pagination/useGridPage.d.ts +1 -2
- package/hooks/features/pagination/useGridPage.js +5 -17
- package/hooks/features/pagination/useGridPageSize.d.ts +1 -2
- package/hooks/features/pagination/useGridPageSize.js +5 -26
- package/hooks/features/pagination/useGridPagination.d.ts +2 -0
- package/hooks/features/pagination/useGridPagination.js +25 -2
- package/hooks/features/preferencesPanel/useGridPreferencesPanel.d.ts +3 -1
- package/hooks/features/preferencesPanel/useGridPreferencesPanel.js +10 -11
- package/hooks/features/rows/useGridParamsApi.js +3 -10
- package/hooks/features/rows/useGridRows.js +14 -6
- package/hooks/features/rows/useGridRowsMeta.d.ts +3 -1
- package/hooks/features/rows/useGridRowsMeta.js +42 -24
- package/hooks/features/selection/gridSelectionSelector.d.ts +1 -1
- package/hooks/features/selection/useGridSelection.d.ts +2 -0
- package/hooks/features/selection/useGridSelection.js +28 -16
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +8 -3
- package/hooks/features/virtualization/useGridVirtualScroller.js +4 -4
- package/hooks/utils/useGridApi.js +10 -1
- package/hooks/utils/useGridInitializeState.d.ts +2 -1
- package/hooks/utils/useGridSelector.js +4 -4
- package/hooks/utils/useGridState.js +10 -1
- package/hooks/utils/{useCurrentPageRows.d.ts → useGridVisibleRows.d.ts} +7 -6
- package/hooks/utils/{useCurrentPageRows.js → useGridVisibleRows.js} +8 -7
- package/index.js +1 -1
- package/internals/index.d.ts +9 -12
- package/internals/index.js +9 -12
- package/legacy/DataGrid/DataGrid.js +18 -3
- package/legacy/DataGrid/useDataGridComponent.js +19 -15
- package/legacy/DataGrid/useDataGridProps.js +8 -2
- package/legacy/colDef/gridNumericOperators.js +1 -1
- package/legacy/components/GridRow.js +30 -3
- package/legacy/components/base/GridErrorHandler.js +13 -2
- package/legacy/components/cell/GridCell.js +4 -2
- package/legacy/components/cell/GridEditSingleSelectCell.js +10 -9
- package/legacy/components/columnHeaders/GridColumnHeaderItem.js +5 -3
- package/legacy/components/containers/GridRootStyles.js +1 -1
- package/legacy/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +29 -26
- package/legacy/components/virtualization/GridVirtualScrollerRenderZone.js +4 -1
- package/legacy/constants/gridClasses.js +1 -1
- package/legacy/hooks/features/columnMenu/useGridColumnMenu.js +8 -9
- package/legacy/hooks/features/columns/gridColumnsSelector.js +13 -12
- package/legacy/hooks/features/columns/gridColumnsUtils.js +7 -5
- package/legacy/hooks/features/density/useGridDensity.js +5 -6
- package/legacy/hooks/features/dimensions/useGridDimensions.js +2 -2
- package/legacy/hooks/features/editRows/useGridEditing.js +5 -6
- package/legacy/hooks/features/export/serializers/csvSerializer.js +4 -4
- package/legacy/hooks/features/filter/gridFilterSelector.js +1 -0
- package/legacy/hooks/features/focus/useGridFocus.js +12 -13
- package/legacy/hooks/features/keyboard/useGridKeyboardNavigation.js +2 -2
- package/legacy/hooks/features/pagination/useGridPage.js +5 -17
- package/legacy/hooks/features/pagination/useGridPageSize.js +5 -26
- package/legacy/hooks/features/pagination/useGridPagination.js +25 -2
- package/legacy/hooks/features/preferencesPanel/useGridPreferencesPanel.js +10 -11
- package/legacy/hooks/features/rows/useGridParamsApi.js +3 -10
- package/legacy/hooks/features/rows/useGridRows.js +17 -6
- package/legacy/hooks/features/rows/useGridRowsMeta.js +44 -26
- package/legacy/hooks/features/selection/useGridSelection.js +29 -19
- package/legacy/hooks/features/virtualization/useGridVirtualScroller.js +4 -4
- package/legacy/hooks/utils/useGridApi.js +7 -0
- package/legacy/hooks/utils/useGridSelector.js +4 -4
- package/legacy/hooks/utils/useGridState.js +7 -0
- package/legacy/hooks/utils/{useCurrentPageRows.js → useGridVisibleRows.js} +8 -7
- package/legacy/index.js +1 -1
- package/legacy/internals/index.js +9 -12
- package/legacy/models/colDef/gridDefaultColumnTypes.js +4 -4
- package/legacy/utils/createSelector.js +4 -4
- package/legacy/utils/getGridLocalization.js +2 -2
- package/lib/lodash/_baseGetAllKeys.d.ts +1 -1
- package/lib/lodash/_baseIsEqual.d.ts +1 -1
- package/lib/lodash/_baseIsEqualDeep.d.ts +1 -1
- package/lib/lodash/_baseKeys.d.ts +1 -1
- package/lib/lodash/_cacheHas.d.ts +1 -1
- package/lib/lodash/_equalArrays.d.ts +1 -1
- package/lib/lodash/_equalByTag.d.ts +1 -1
- package/lib/lodash/_equalObjects.d.ts +1 -1
- package/lib/lodash/_getAllKeys.d.ts +1 -1
- package/lib/lodash/_getMapData.d.ts +1 -1
- package/lib/lodash/_getNative.d.ts +1 -1
- package/lib/lodash/_getValue.d.ts +1 -1
- package/lib/lodash/_hashSet.d.ts +1 -1
- package/lib/lodash/_listCacheSet.d.ts +1 -1
- package/lib/lodash/_mapCacheSet.d.ts +1 -1
- package/lib/lodash/_mapToArray.d.ts +1 -1
- package/lib/lodash/_setCacheAdd.d.ts +1 -1
- package/lib/lodash/_setToArray.d.ts +1 -1
- package/lib/lodash/_stackSet.d.ts +1 -1
- package/lib/lodash/keys.d.ts +1 -1
- package/models/api/gridRowApi.d.ts +6 -0
- package/models/api/gridRowsMetaApi.d.ts +7 -0
- package/models/api/gridSortApi.d.ts +1 -0
- package/models/colDef/gridColDef.d.ts +1 -2
- package/models/colDef/gridDefaultColumnTypes.js +2 -2
- package/models/gridRows.d.ts +8 -2
- package/models/params/gridRowParams.d.ts +29 -1
- package/models/props/DataGridProps.d.ts +20 -4
- package/modern/DataGrid/DataGrid.js +18 -3
- package/modern/DataGrid/useDataGridComponent.js +19 -15
- package/modern/DataGrid/useDataGridProps.js +3 -2
- package/modern/colDef/gridNumericOperators.js +1 -1
- package/modern/components/GridRow.js +29 -3
- package/modern/components/base/GridErrorHandler.js +13 -2
- package/modern/components/cell/GridCell.js +2 -2
- package/modern/components/cell/GridEditSingleSelectCell.js +2 -1
- package/modern/components/columnHeaders/GridColumnHeaderItem.js +5 -3
- package/modern/components/containers/GridRootStyles.js +1 -1
- package/modern/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +27 -23
- package/modern/components/virtualization/GridVirtualScrollerRenderZone.js +4 -1
- package/modern/constants/gridClasses.js +1 -1
- package/modern/hooks/features/columnMenu/useGridColumnMenu.js +6 -7
- package/modern/hooks/features/columns/gridColumnsSelector.js +11 -10
- package/modern/hooks/features/columns/gridColumnsUtils.js +7 -5
- package/modern/hooks/features/density/useGridDensity.js +3 -4
- package/modern/hooks/features/dimensions/useGridDimensions.js +2 -2
- package/modern/hooks/features/editRows/useGridEditing.js +3 -4
- package/modern/hooks/features/export/serializers/csvSerializer.js +4 -4
- package/modern/hooks/features/filter/gridFilterSelector.js +1 -0
- package/modern/hooks/features/focus/useGridFocus.js +10 -11
- package/modern/hooks/features/keyboard/useGridKeyboardNavigation.js +2 -2
- package/modern/hooks/features/pagination/useGridPage.js +1 -9
- package/modern/hooks/features/pagination/useGridPageSize.js +1 -20
- package/modern/hooks/features/pagination/useGridPagination.js +23 -2
- package/modern/hooks/features/preferencesPanel/useGridPreferencesPanel.js +6 -7
- package/modern/hooks/features/rows/useGridParamsApi.js +3 -10
- package/modern/hooks/features/rows/useGridRows.js +14 -6
- package/modern/hooks/features/rows/useGridRowsMeta.js +36 -24
- package/modern/hooks/features/selection/useGridSelection.js +24 -16
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +4 -4
- package/modern/hooks/utils/useGridApi.js +10 -1
- package/modern/hooks/utils/useGridSelector.js +4 -4
- package/modern/hooks/utils/useGridState.js +10 -1
- package/modern/hooks/utils/{useCurrentPageRows.js → useGridVisibleRows.js} +8 -7
- package/modern/index.js +1 -1
- package/modern/internals/index.js +9 -12
- package/modern/models/colDef/gridDefaultColumnTypes.js +2 -2
- package/modern/utils/createSelector.js +4 -4
- package/modern/utils/getGridLocalization.js +1 -1
- package/node/DataGrid/DataGrid.js +18 -3
- package/node/DataGrid/useDataGridComponent.js +11 -9
- package/node/DataGrid/useDataGridProps.js +3 -2
- package/node/colDef/gridNumericOperators.js +1 -1
- package/node/components/GridRow.js +28 -3
- package/node/components/base/GridErrorHandler.js +11 -1
- package/node/components/cell/GridCell.js +4 -2
- package/node/components/cell/GridEditSingleSelectCell.js +2 -1
- package/node/components/columnHeaders/GridColumnHeaderItem.js +5 -3
- package/node/components/containers/GridRootStyles.js +1 -1
- package/node/components/panel/filterPanel/GridFilterInputMultipleSingleSelect.js +27 -23
- package/node/components/virtualization/GridVirtualScrollerRenderZone.js +4 -1
- package/node/constants/gridClasses.js +1 -1
- package/node/hooks/features/columnMenu/useGridColumnMenu.js +10 -8
- package/node/hooks/features/columns/gridColumnsSelector.js +11 -9
- package/node/hooks/features/columns/gridColumnsUtils.js +7 -5
- package/node/hooks/features/density/useGridDensity.js +7 -6
- package/node/hooks/features/dimensions/useGridDimensions.js +2 -2
- package/node/hooks/features/editRows/useGridEditing.js +8 -5
- package/node/hooks/features/export/serializers/csvSerializer.js +5 -4
- package/node/hooks/features/filter/gridFilterSelector.js +1 -0
- package/node/hooks/features/focus/useGridFocus.js +15 -13
- package/node/hooks/features/keyboard/useGridKeyboardNavigation.js +2 -2
- package/node/hooks/features/pagination/useGridPage.js +7 -20
- package/node/hooks/features/pagination/useGridPageSize.js +6 -26
- package/node/hooks/features/pagination/useGridPagination.js +31 -1
- package/node/hooks/features/preferencesPanel/useGridPreferencesPanel.js +15 -13
- package/node/hooks/features/rows/useGridParamsApi.js +4 -10
- package/node/hooks/features/rows/useGridRows.js +15 -6
- package/node/hooks/features/rows/useGridRowsMeta.js +47 -26
- package/node/hooks/features/selection/useGridSelection.js +32 -18
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +4 -4
- package/node/hooks/utils/useGridApi.js +11 -1
- package/node/hooks/utils/useGridSelector.js +6 -4
- package/node/hooks/utils/useGridState.js +11 -1
- package/node/hooks/utils/{useCurrentPageRows.js → useGridVisibleRows.js} +11 -10
- package/node/index.js +1 -1
- package/node/internals/index.js +45 -21
- package/node/models/colDef/gridDefaultColumnTypes.js +2 -2
- package/node/utils/createSelector.js +5 -4
- package/node/utils/getGridLocalization.js +2 -2
- package/package.json +2 -2
- package/utils/createSelector.js +4 -4
- package/utils/getGridLocalization.d.ts +2 -1
- package/utils/getGridLocalization.js +2 -2
- package/utils/keyboardUtils.d.ts +1 -1
- package/utils/warning.d.ts +1 -1
- package/hooks/utils/useGridStateInit.d.ts +0 -7
- package/hooks/utils/useGridStateInit.js +0 -9
- package/legacy/hooks/utils/useGridStateInit.js +0 -9
- package/modern/hooks/utils/useGridStateInit.js +0 -9
- package/node/hooks/utils/useGridStateInit.js +0 -23
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { createSelector } from '../../../utils/createSelector';
|
|
2
|
-
|
|
2
|
+
import { wrapWithWarningOnCall } from '../../../utils/warning';
|
|
3
3
|
/**
|
|
4
4
|
* @category Columns
|
|
5
5
|
* @deprecated Use the selector returning exactly the value you are looking for.
|
|
6
6
|
* @ignore - do not document.
|
|
7
7
|
* TODO v6: Rename `gridColumnsStateSelector`
|
|
8
8
|
*/
|
|
9
|
+
|
|
9
10
|
export const gridColumnsSelector = state => state.columns;
|
|
10
11
|
/**
|
|
11
12
|
* Get the field of each column.
|
|
@@ -98,50 +99,50 @@ export const gridFilterableColumnLookupSelector = createSelector(gridColumnDefin
|
|
|
98
99
|
* @ignore - do not document.
|
|
99
100
|
*/
|
|
100
101
|
|
|
101
|
-
export const allGridColumnsFieldsSelector = gridColumnFieldsSelector;
|
|
102
|
+
export const allGridColumnsFieldsSelector = wrapWithWarningOnCall(gridColumnFieldsSelector, ['MUI: The method allGridColumnsFieldsSelector is deprecated and will be removed in the next major version.', 'Use gridColumnFieldsSelector instead']);
|
|
102
103
|
/**
|
|
103
104
|
* @category Columns
|
|
104
105
|
* @deprecated Use `gridColumnDefinitionsSelector` instead.
|
|
105
106
|
* @ignore - do not document.
|
|
106
107
|
*/
|
|
107
108
|
|
|
108
|
-
export const allGridColumnsSelector = gridColumnDefinitionsSelector;
|
|
109
|
+
export const allGridColumnsSelector = wrapWithWarningOnCall(gridColumnDefinitionsSelector, ['MUI: The method allGridColumnsSelector is deprecated and will be removed in the next major version.', 'Use gridColumnDefinitionsSelector instead']);
|
|
109
110
|
/**
|
|
110
111
|
* @category Visible Columns
|
|
111
112
|
* @deprecated Use `gridVisibleColumnDefinitionsSelector` instead.
|
|
112
113
|
* @ignore - do not document.
|
|
113
114
|
*/
|
|
114
115
|
|
|
115
|
-
export const visibleGridColumnsSelector = gridVisibleColumnDefinitionsSelector;
|
|
116
|
+
export const visibleGridColumnsSelector = wrapWithWarningOnCall(gridVisibleColumnDefinitionsSelector, ['MUI: The method visibleGridColumnsSelector is deprecated and will be removed in the next major version.', 'Use gridVisibleColumnDefinitionsSelector instead']);
|
|
116
117
|
/**
|
|
117
118
|
* @category Columns
|
|
118
119
|
* @deprecated Use `gridFilterableColumnDefinitionsSelector` instead.
|
|
119
120
|
* @ignore - do not document.
|
|
120
121
|
*/
|
|
121
122
|
|
|
122
|
-
export const filterableGridColumnsSelector = gridFilterableColumnDefinitionsSelector;
|
|
123
|
+
export const filterableGridColumnsSelector = wrapWithWarningOnCall(gridFilterableColumnDefinitionsSelector, ['MUI: The method filterableGridColumnsSelector is deprecated and will be removed in the next major version.', 'Use gridFilterableColumnDefinitionsSelector instead']);
|
|
123
124
|
/**
|
|
124
125
|
* @category Columns
|
|
125
126
|
* @deprecated Use `gridFilterableColumnLookupSelector` instead (not the same return format).
|
|
126
127
|
* @ignore - do not document.
|
|
127
128
|
*/
|
|
128
129
|
|
|
129
|
-
export const filterableGridColumnsIdsSelector = createSelector(gridFilterableColumnDefinitionsSelector, columns => columns.map(col => col.field));
|
|
130
|
+
export const filterableGridColumnsIdsSelector = wrapWithWarningOnCall(createSelector(gridFilterableColumnDefinitionsSelector, columns => columns.map(col => col.field)), ['MUI: The method filterableGridColumnsIdsSelector is deprecated and will be removed in the next major version.', 'Use gridFilterableColumnDefinitionsSelector instead.', 'The return format is now a lookup, if you want to get the same output as before, use the following code:', '', 'const lookup = gridFilterableColumnLookupSelector(apiRef);', 'const fields = gridColumnFieldsSelector(apiRef).filter(field => lookup[field]);']);
|
|
130
131
|
/**
|
|
131
132
|
* Get the amount of visible columns.
|
|
132
133
|
* @category Visible Columns
|
|
133
|
-
* @deprecated Use the length of `gridVisibleColumnDefinitionsSelector` instead.
|
|
134
|
+
* @deprecated Use the length of the array returned by `gridVisibleColumnDefinitionsSelector` instead.
|
|
134
135
|
* @ignore - do not document.
|
|
135
136
|
*/
|
|
136
137
|
|
|
137
|
-
export const visibleGridColumnsLengthSelector = createSelector(gridVisibleColumnDefinitionsSelector, visibleColumns => visibleColumns.length);
|
|
138
|
+
export const visibleGridColumnsLengthSelector = wrapWithWarningOnCall(createSelector(gridVisibleColumnDefinitionsSelector, visibleColumns => visibleColumns.length), ['MUI: The method visibleGridColumnsLengthSelector is deprecated and will be removed in the next major version.', 'Use the length of the array returned by gridVisibleColumnDefinitionsSelector instead.']);
|
|
138
139
|
/**
|
|
139
140
|
* @category Visible Columns
|
|
140
141
|
* @deprecated Use `gridColumnsTotalWidthSelector` or `gridColumnPositionsSelector` instead.
|
|
141
142
|
* @ignore - do not document.
|
|
142
143
|
*/
|
|
143
144
|
|
|
144
|
-
export const gridColumnsMetaSelector = createSelector(gridColumnPositionsSelector, gridColumnsTotalWidthSelector, (positions, totalWidth) => ({
|
|
145
|
+
export const gridColumnsMetaSelector = wrapWithWarningOnCall(createSelector(gridColumnPositionsSelector, gridColumnsTotalWidthSelector, (positions, totalWidth) => ({
|
|
145
146
|
totalWidth,
|
|
146
147
|
positions
|
|
147
|
-
}));
|
|
148
|
+
})), ['MUI: The method gridColumnsMetaSelector is deprecated and will be removed in the next major version.', 'Use gridColumnsTotalWidthSelector or gridColumnPositionsSelector instead']);
|
|
@@ -3,12 +3,14 @@ import { DEFAULT_GRID_COL_TYPE_KEY, getGridDefaultColumnTypes } from '../../../m
|
|
|
3
3
|
import { gridColumnsSelector, gridColumnVisibilityModelSelector } from './gridColumnsSelector';
|
|
4
4
|
import { clamp } from '../../../utils/utils';
|
|
5
5
|
export const computeColumnTypes = (customColumnTypes = {}) => {
|
|
6
|
-
const
|
|
6
|
+
const mergedColumnTypes = _extends({}, getGridDefaultColumnTypes());
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
Object.entries(customColumnTypes).forEach(([colType, colTypeDef]) => {
|
|
9
|
+
if (mergedColumnTypes[colType]) {
|
|
10
|
+
mergedColumnTypes[colType] = _extends({}, mergedColumnTypes[colType], colTypeDef);
|
|
11
|
+
} else {
|
|
12
|
+
mergedColumnTypes[colType] = _extends({}, mergedColumnTypes[colTypeDef.extendType || DEFAULT_GRID_COL_TYPE_KEY], colTypeDef);
|
|
13
|
+
}
|
|
12
14
|
});
|
|
13
15
|
return mergedColumnTypes;
|
|
14
16
|
};
|
|
@@ -3,7 +3,6 @@ import * as React from 'react';
|
|
|
3
3
|
import { GridDensityTypes } from '../../../models/gridDensity';
|
|
4
4
|
import { useGridLogger } from '../../utils/useGridLogger';
|
|
5
5
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
6
|
-
import { useGridStateInit } from '../../utils/useGridStateInit';
|
|
7
6
|
import { gridDensitySelector } from './densitySelector';
|
|
8
7
|
import { isDeepEqual } from '../../../utils/utils';
|
|
9
8
|
export const COMPACT_DENSITY_FACTOR = 0.7;
|
|
@@ -37,11 +36,11 @@ const getUpdatedDensityState = (newDensity, newHeaderHeight, newRowHeight) => {
|
|
|
37
36
|
}
|
|
38
37
|
};
|
|
39
38
|
|
|
39
|
+
export const densityStateInitializer = (state, props) => _extends({}, state, {
|
|
40
|
+
density: getUpdatedDensityState(props.density, props.headerHeight, props.rowHeight)
|
|
41
|
+
});
|
|
40
42
|
export const useGridDensity = (apiRef, props) => {
|
|
41
43
|
const logger = useGridLogger(apiRef, 'useDensity');
|
|
42
|
-
useGridStateInit(apiRef, state => _extends({}, state, {
|
|
43
|
-
density: getUpdatedDensityState(props.density, props.headerHeight, props.rowHeight)
|
|
44
|
-
}));
|
|
45
44
|
const setDensity = React.useCallback((newDensity, newHeaderHeight = props.headerHeight, newRowHeight = props.rowHeight) => {
|
|
46
45
|
logger.debug(`Set grid density to ${newDensity}`);
|
|
47
46
|
apiRef.current.setState(state => {
|
|
@@ -7,7 +7,7 @@ import { useGridLogger } from '../../utils/useGridLogger';
|
|
|
7
7
|
import { gridColumnsTotalWidthSelector } from '../columns';
|
|
8
8
|
import { gridDensityHeaderHeightSelector, gridDensityRowHeightSelector } from '../density';
|
|
9
9
|
import { useGridSelector } from '../../utils';
|
|
10
|
-
import {
|
|
10
|
+
import { getVisibleRows } from '../../utils/useGridVisibleRows';
|
|
11
11
|
import { gridRowsMetaSelector } from '../rows/gridRowsMetaSelector';
|
|
12
12
|
const isTestEnvironment = process.env.NODE_ENV === 'test';
|
|
13
13
|
|
|
@@ -114,7 +114,7 @@ export function useGridDimensions(apiRef, props) {
|
|
|
114
114
|
return 0;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
const currentPage =
|
|
117
|
+
const currentPage = getVisibleRows(apiRef, {
|
|
118
118
|
pagination: props.pagination,
|
|
119
119
|
paginationMode: props.paginationMode
|
|
120
120
|
}); // TODO: Use a combination of scrollTop, dimensions.viewportInnerSize.height and rowsMeta.possitions
|
|
@@ -5,10 +5,12 @@ import { GridCellModes } from '../../../models/gridEditRowModel';
|
|
|
5
5
|
import { useGridApiEventHandler, useGridApiOptionHandler } from '../../utils/useGridApiEventHandler';
|
|
6
6
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
7
7
|
import { useGridLogger } from '../../utils/useGridLogger';
|
|
8
|
-
import { useGridStateInit } from '../../utils/useGridStateInit';
|
|
9
8
|
import { gridEditRowsStateSelector } from './gridEditRowsSelector';
|
|
10
9
|
import { useCellEditing } from './useGridCellEditing';
|
|
11
10
|
import { useGridRowEditing } from './useGridRowEditing';
|
|
11
|
+
export const editingStateInitializer = state => _extends({}, state, {
|
|
12
|
+
editRows: {}
|
|
13
|
+
});
|
|
12
14
|
/**
|
|
13
15
|
* @requires useGridFocus - can be after, async only
|
|
14
16
|
* @requires useGridParamsApi (method)
|
|
@@ -19,9 +21,6 @@ export function useGridEditing(apiRef, props) {
|
|
|
19
21
|
const logger = useGridLogger(apiRef, 'useGridEditRows');
|
|
20
22
|
useCellEditing(apiRef, props);
|
|
21
23
|
useGridRowEditing(apiRef, props);
|
|
22
|
-
useGridStateInit(apiRef, state => _extends({}, state, {
|
|
23
|
-
editRows: {}
|
|
24
|
-
}));
|
|
25
24
|
const debounceMap = React.useRef({});
|
|
26
25
|
apiRef.current.unstable_updateControlState({
|
|
27
26
|
stateId: 'editRows',
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { GRID_CHECKBOX_SELECTION_COL_DEF } from '../../../../colDef';
|
|
2
|
+
import { buildWarning } from '../../../../utils/warning';
|
|
2
3
|
|
|
3
4
|
const serialiseCellValue = (value, delimiterCharacter) => {
|
|
4
5
|
if (typeof value === 'string') {
|
|
@@ -14,15 +15,14 @@ const serialiseCellValue = (value, delimiterCharacter) => {
|
|
|
14
15
|
return value;
|
|
15
16
|
};
|
|
16
17
|
|
|
17
|
-
|
|
18
|
+
const objectFormattedValueWarning = buildWarning(['MUI: 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.']);
|
|
18
19
|
|
|
19
20
|
const serialiseRow = (id, columns, getCellParams, delimiterCharacter) => columns.map(column => {
|
|
20
21
|
const cellParams = getCellParams(id, column.field);
|
|
21
22
|
|
|
22
23
|
if (process.env.NODE_ENV !== 'production') {
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
warnedOnce = true;
|
|
24
|
+
if (String(cellParams.formattedValue) === '[object Object]') {
|
|
25
|
+
objectFormattedValueWarning();
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -63,6 +63,7 @@ export const gridFilteredSortedRowIdsSelector = createSelector(gridFilteredSorte
|
|
|
63
63
|
* @category Filtering
|
|
64
64
|
* @deprecated Use `gridVisibleSortedRowIdsSelector` instead
|
|
65
65
|
* @ignore - do not document.
|
|
66
|
+
* TODO: Add deprecation warning once we have the new selectors without the "visible" keyword.
|
|
66
67
|
*/
|
|
67
68
|
|
|
68
69
|
export const gridVisibleRowsSelector = gridVisibleSortedRowIdsSelector;
|
|
@@ -6,8 +6,17 @@ import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
|
6
6
|
import { useGridLogger } from '../../utils/useGridLogger';
|
|
7
7
|
import { useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
|
|
8
8
|
import { isNavigationKey } from '../../../utils/keyboardUtils';
|
|
9
|
-
import { useGridStateInit } from '../../utils/useGridStateInit';
|
|
10
9
|
import { gridFocusCellSelector } from './gridFocusStateSelector';
|
|
10
|
+
export const focusStateInitializer = state => _extends({}, state, {
|
|
11
|
+
focus: {
|
|
12
|
+
cell: null,
|
|
13
|
+
columnHeader: null
|
|
14
|
+
},
|
|
15
|
+
tabIndex: {
|
|
16
|
+
cell: null,
|
|
17
|
+
columnHeader: null
|
|
18
|
+
}
|
|
19
|
+
});
|
|
11
20
|
/**
|
|
12
21
|
* @requires useGridParamsApi (method)
|
|
13
22
|
* @requires useGridRows (method)
|
|
@@ -16,16 +25,6 @@ import { gridFocusCellSelector } from './gridFocusStateSelector';
|
|
|
16
25
|
|
|
17
26
|
export const useGridFocus = (apiRef, props) => {
|
|
18
27
|
const logger = useGridLogger(apiRef, 'useGridFocus');
|
|
19
|
-
useGridStateInit(apiRef, state => _extends({}, state, {
|
|
20
|
-
focus: {
|
|
21
|
-
cell: null,
|
|
22
|
-
columnHeader: null
|
|
23
|
-
},
|
|
24
|
-
tabIndex: {
|
|
25
|
-
cell: null,
|
|
26
|
-
columnHeader: null
|
|
27
|
-
}
|
|
28
|
-
}));
|
|
29
28
|
const lastClickedCell = React.useRef(null);
|
|
30
29
|
const setCellFocus = React.useCallback((id, field) => {
|
|
31
30
|
// The row might have been deleted
|
|
@@ -4,7 +4,7 @@ import { gridVisibleColumnDefinitionsSelector } from '../columns/gridColumnsSele
|
|
|
4
4
|
import { useGridLogger } from '../../utils/useGridLogger';
|
|
5
5
|
import { useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
|
|
6
6
|
import { gridVisibleSortedRowEntriesSelector } from '../filter/gridFilterSelector';
|
|
7
|
-
import {
|
|
7
|
+
import { useGridVisibleRows } from '../../utils/useGridVisibleRows';
|
|
8
8
|
import { GRID_CHECKBOX_SELECTION_COL_DEF } from '../../../colDef/gridCheckboxSelectionColDef';
|
|
9
9
|
import { gridClasses } from '../../../constants/gridClasses';
|
|
10
10
|
/**
|
|
@@ -21,7 +21,7 @@ import { gridClasses } from '../../../constants/gridClasses';
|
|
|
21
21
|
|
|
22
22
|
export const useGridKeyboardNavigation = (apiRef, props) => {
|
|
23
23
|
const logger = useGridLogger(apiRef, 'useGridKeyboardNavigation');
|
|
24
|
-
const currentPage =
|
|
24
|
+
const currentPage = useGridVisibleRows(apiRef, props);
|
|
25
25
|
const goToCell = React.useCallback((colIndex, rowIndex) => {
|
|
26
26
|
logger.debug(`Navigating to cell row ${rowIndex}, col ${colIndex}`);
|
|
27
27
|
apiRef.current.scrollToIndexes({
|
|
@@ -6,8 +6,7 @@ import { gridVisibleTopLevelRowCountSelector } from '../filter';
|
|
|
6
6
|
import { gridPageSelector } from './gridPaginationSelector';
|
|
7
7
|
import { useGridRegisterPreProcessor } from '../../core/preProcessing';
|
|
8
8
|
import { buildWarning } from '../../../utils/warning';
|
|
9
|
-
|
|
10
|
-
const getPageCount = (rowCount, pageSize) => {
|
|
9
|
+
export const getPageCount = (rowCount, pageSize) => {
|
|
11
10
|
if (pageSize > 0 && rowCount > 0) {
|
|
12
11
|
return Math.ceil(rowCount / pageSize);
|
|
13
12
|
}
|
|
@@ -32,13 +31,6 @@ const mergeStateWithPage = page => state => _extends({}, state, {
|
|
|
32
31
|
});
|
|
33
32
|
|
|
34
33
|
const noRowCountInServerMode = buildWarning(["MUI: the 'rowCount' prop is undefined while using paginationMode='server'", 'For more detail, see http://mui.com/components/data-grid/pagination/#basic-implementation'], 'error');
|
|
35
|
-
export const pageStateInitializer = (state, props) => _extends({}, state, {
|
|
36
|
-
pagination: _extends({}, state.pagination, {
|
|
37
|
-
page: props.page ?? props.initialState?.pagination?.page ?? 0,
|
|
38
|
-
pageCount: getPageCount(props.rowCount ?? 0, state.pagination.pageSize),
|
|
39
|
-
rowCount: props.rowCount ?? 0
|
|
40
|
-
})
|
|
41
|
-
});
|
|
42
34
|
/**
|
|
43
35
|
* @requires useGridPageSize (event)
|
|
44
36
|
*/
|
|
@@ -5,26 +5,7 @@ import { useGridLogger, useGridApiMethod, useGridApiEventHandler, useGridSelecto
|
|
|
5
5
|
import { gridPageSizeSelector } from './gridPaginationSelector';
|
|
6
6
|
import { gridDensityRowHeightSelector } from '../density';
|
|
7
7
|
import { useGridRegisterPreProcessor } from '../../core/preProcessing';
|
|
8
|
-
|
|
9
|
-
const defaultPageSize = autoPageSize => autoPageSize ? 0 : 100;
|
|
10
|
-
|
|
11
|
-
export const pageSizeStateInitializer = (state, props) => {
|
|
12
|
-
let pageSize;
|
|
13
|
-
|
|
14
|
-
if (props.pageSize != null) {
|
|
15
|
-
pageSize = props.pageSize;
|
|
16
|
-
} else if (props.initialState?.pagination?.pageSize != null) {
|
|
17
|
-
pageSize = props.initialState.pagination.pageSize;
|
|
18
|
-
} else {
|
|
19
|
-
pageSize = defaultPageSize(props.autoPageSize);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return _extends({}, state, {
|
|
23
|
-
pagination: {
|
|
24
|
-
pageSize
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
};
|
|
8
|
+
export const defaultPageSize = autoPageSize => autoPageSize ? 0 : 100;
|
|
28
9
|
|
|
29
10
|
const mergeStateWithPageSize = pageSize => state => _extends({}, state, {
|
|
30
11
|
pagination: _extends({}, state.pagination, {
|
|
@@ -1,5 +1,26 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { useGridPageSize, defaultPageSize } from './useGridPageSize';
|
|
3
|
+
import { useGridPage, getPageCount } from './useGridPage';
|
|
4
|
+
export const paginationStateInitializer = (state, props) => {
|
|
5
|
+
let pageSize;
|
|
6
|
+
|
|
7
|
+
if (props.pageSize != null) {
|
|
8
|
+
pageSize = props.pageSize;
|
|
9
|
+
} else if (props.initialState?.pagination?.pageSize != null) {
|
|
10
|
+
pageSize = props.initialState.pagination.pageSize;
|
|
11
|
+
} else {
|
|
12
|
+
pageSize = defaultPageSize(props.autoPageSize);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return _extends({}, state, {
|
|
16
|
+
pagination: {
|
|
17
|
+
pageSize,
|
|
18
|
+
page: props.page ?? props.initialState?.pagination?.page ?? 0,
|
|
19
|
+
pageCount: getPageCount(props.rowCount ?? 0, pageSize),
|
|
20
|
+
rowCount: props.rowCount ?? 0
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
};
|
|
3
24
|
/**
|
|
4
25
|
* @requires useGridFilter (state)
|
|
5
26
|
* @requires useGridDimensions (event) - can be after
|
|
@@ -2,20 +2,19 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
4
4
|
import { useGridLogger } from '../../utils/useGridLogger';
|
|
5
|
-
import { useGridStateInit } from '../../utils/useGridStateInit';
|
|
6
5
|
import { useGridRegisterPreProcessor } from '../../core/preProcessing';
|
|
7
6
|
import { gridPreferencePanelStateSelector } from './gridPreferencePanelSelector';
|
|
7
|
+
export const preferencePanelStateInitializer = (state, props) => _extends({}, state, {
|
|
8
|
+
preferencePanel: props.initialState?.preferencePanel ?? {
|
|
9
|
+
open: false
|
|
10
|
+
}
|
|
11
|
+
});
|
|
8
12
|
/**
|
|
9
13
|
* TODO: Add a single `setPreferencePanel` method to avoid multiple `setState`
|
|
10
14
|
*/
|
|
11
15
|
|
|
12
|
-
export const useGridPreferencesPanel =
|
|
16
|
+
export const useGridPreferencesPanel = apiRef => {
|
|
13
17
|
const logger = useGridLogger(apiRef, 'useGridPreferencesPanel');
|
|
14
|
-
useGridStateInit(apiRef, state => _extends({}, state, {
|
|
15
|
-
preferencePanel: props.initialState?.preferencePanel ?? {
|
|
16
|
-
open: false
|
|
17
|
-
}
|
|
18
|
-
}));
|
|
19
18
|
const hideTimeout = React.useRef();
|
|
20
19
|
const immediateTimeout = React.useRef();
|
|
21
20
|
/**
|
|
@@ -2,6 +2,7 @@ import * as React from 'react';
|
|
|
2
2
|
import { getGridCellElement, getGridColumnHeaderElement, getGridRowElement } from '../../../utils/domUtils';
|
|
3
3
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
4
4
|
import { gridFocusCellSelector, gridTabIndexCellSelector } from '../focus/gridFocusStateSelector';
|
|
5
|
+
import { buildWarning } from '../../../utils/warning';
|
|
5
6
|
let warnedOnceMissingColumn = false;
|
|
6
7
|
|
|
7
8
|
function warnMissingColumn(field) {
|
|
@@ -9,12 +10,7 @@ function warnMissingColumn(field) {
|
|
|
9
10
|
warnedOnceMissingColumn = true;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function warnGetValue() {
|
|
15
|
-
console.warn([`MUI: You are calling getValue. This method is deprecated and will be removed in the next major version.`, `Instead, you can access the data from \`params.row}\`.`].join('\n'));
|
|
16
|
-
warnedOnceGetValue = true;
|
|
17
|
-
}
|
|
13
|
+
const getCellValueWarning = buildWarning([`MUI: You are calling getValue. This method is deprecated and will be removed in the next major version.`, 'Instead, you can access the data from `params.row`.']);
|
|
18
14
|
/**
|
|
19
15
|
* @requires useGridColumns (method)
|
|
20
16
|
* @requires useGridRows (method)
|
|
@@ -24,7 +20,6 @@ function warnGetValue() {
|
|
|
24
20
|
* TODO: Impossible priority - useGridFocus also needs to be after useGridParamsApi
|
|
25
21
|
*/
|
|
26
22
|
|
|
27
|
-
|
|
28
23
|
export function useGridParamsApi(apiRef) {
|
|
29
24
|
const getColumnHeaderParams = React.useCallback(field => ({
|
|
30
25
|
field,
|
|
@@ -36,9 +31,7 @@ export function useGridParamsApi(apiRef) {
|
|
|
36
31
|
|
|
37
32
|
const getCellValueWithDeprecationWarning = React.useCallback((...args) => {
|
|
38
33
|
if (process.env.NODE_ENV !== 'production') {
|
|
39
|
-
|
|
40
|
-
warnGetValue();
|
|
41
|
-
}
|
|
34
|
+
getCellValueWarning();
|
|
42
35
|
}
|
|
43
36
|
|
|
44
37
|
return apiRef.current.getCellValue(...args);
|
|
@@ -6,6 +6,7 @@ import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
|
6
6
|
import { useGridLogger } from '../../utils/useGridLogger';
|
|
7
7
|
import { gridRowCountSelector, gridRowsLookupSelector, gridRowTreeSelector, gridRowIdsSelector } from './gridRowsSelector';
|
|
8
8
|
import { GridSignature, useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
|
|
9
|
+
import { useGridVisibleRows } from '../../utils/useGridVisibleRows';
|
|
9
10
|
|
|
10
11
|
function getGridRowId(rowModel, getRowId, detailErrorMessage) {
|
|
11
12
|
const id = getRowId ? getRowId(rowModel) : rowModel.id;
|
|
@@ -50,12 +51,10 @@ const getRowsStateFromCache = (rowsCache, previousTree, apiRef, rowCountProp) =>
|
|
|
50
51
|
const groupingResponse = apiRef.current.unstable_groupRows(_extends({}, value, {
|
|
51
52
|
previousTree
|
|
52
53
|
}));
|
|
53
|
-
const dataTopLevelRowCount = Object.values(groupingResponse.tree).filter(node => node.parent == null).length;
|
|
54
|
-
const totalRowCount = rowCount > groupingResponse.ids.length ? rowCount : groupingResponse.ids.length;
|
|
55
|
-
const totalTopLevelRowCount = rowCount > dataTopLevelRowCount ? rowCount : dataTopLevelRowCount;
|
|
54
|
+
const dataTopLevelRowCount = groupingResponse.treeDepth === 1 ? groupingResponse.ids.length : Object.values(groupingResponse.tree).filter(node => node.parent == null).length;
|
|
56
55
|
return _extends({}, groupingResponse, {
|
|
57
|
-
totalRowCount,
|
|
58
|
-
totalTopLevelRowCount
|
|
56
|
+
totalRowCount: Math.max(rowCount, groupingResponse.ids.length),
|
|
57
|
+
totalTopLevelRowCount: Math.max(rowCount, dataTopLevelRowCount)
|
|
59
58
|
});
|
|
60
59
|
};
|
|
61
60
|
|
|
@@ -94,7 +93,15 @@ export const useGridRows = (apiRef, props) => {
|
|
|
94
93
|
const logger = useGridLogger(apiRef, 'useGridRows');
|
|
95
94
|
const rowsCache = React.useRef(apiRef.current.state.rowsCache); // To avoid listing rowsCache as useEffect dep
|
|
96
95
|
|
|
96
|
+
const currentPage = useGridVisibleRows(apiRef, props);
|
|
97
97
|
const getRow = React.useCallback(id => gridRowsLookupSelector(apiRef)[id] ?? null, [apiRef]);
|
|
98
|
+
const lookup = React.useMemo(() => currentPage.rows.reduce((acc, {
|
|
99
|
+
id
|
|
100
|
+
}, index) => {
|
|
101
|
+
acc[id] = index;
|
|
102
|
+
return acc;
|
|
103
|
+
}, {}), [currentPage.rows]);
|
|
104
|
+
const getRowIndexRelativeToVisibleRows = React.useCallback(id => lookup[id], [lookup]);
|
|
98
105
|
const throttledRowsChange = React.useCallback((newState, throttle) => {
|
|
99
106
|
const run = () => {
|
|
100
107
|
rowsCache.current.timeout = null;
|
|
@@ -276,7 +283,8 @@ export const useGridRows = (apiRef, props) => {
|
|
|
276
283
|
setRows,
|
|
277
284
|
updateRows,
|
|
278
285
|
setRowChildrenExpansion,
|
|
279
|
-
getRowNode
|
|
286
|
+
getRowNode,
|
|
287
|
+
getRowIndexRelativeToVisibleRows
|
|
280
288
|
};
|
|
281
289
|
useGridApiMethod(apiRef, rowApi, 'GridRowApi');
|
|
282
290
|
};
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { useGridVisibleRows } from '../../utils/useGridVisibleRows';
|
|
4
4
|
import { useGridApiMethod } from '../../utils/useGridApiMethod';
|
|
5
5
|
import { useGridSelector } from '../../utils/useGridSelector';
|
|
6
6
|
import { gridDensityRowHeightSelector, gridDensityFactorSelector } from '../density/densitySelector';
|
|
7
7
|
import { gridFilterStateSelector } from '../filter/gridFilterSelector';
|
|
8
8
|
import { gridPaginationSelector } from '../pagination/gridPaginationSelector';
|
|
9
9
|
import { gridSortingStateSelector } from '../sorting/gridSortingSelector';
|
|
10
|
-
import { useGridStateInit } from '../../utils/useGridStateInit';
|
|
11
10
|
import { GridEvents } from '../../../models/events/gridEvents';
|
|
12
11
|
import { useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
|
|
12
|
+
export const rowsMetaStateInitializer = state => _extends({}, state, {
|
|
13
|
+
rowsMeta: {
|
|
14
|
+
currentPageTotalHeight: 0,
|
|
15
|
+
positions: []
|
|
16
|
+
}
|
|
17
|
+
});
|
|
13
18
|
/**
|
|
14
19
|
* @requires useGridPageSize (method)
|
|
15
20
|
* @requires useGridPage (method)
|
|
@@ -18,32 +23,20 @@ import { useGridApiEventHandler } from '../../utils/useGridApiEventHandler';
|
|
|
18
23
|
export const useGridRowsMeta = (apiRef, props) => {
|
|
19
24
|
const {
|
|
20
25
|
getRowHeight,
|
|
21
|
-
|
|
22
|
-
paginationMode
|
|
26
|
+
getRowSpacing
|
|
23
27
|
} = props;
|
|
24
28
|
const rowsHeightLookup = React.useRef({});
|
|
25
29
|
const rowHeight = useGridSelector(apiRef, gridDensityRowHeightSelector);
|
|
26
30
|
const filterState = useGridSelector(apiRef, gridFilterStateSelector);
|
|
27
31
|
const paginationState = useGridSelector(apiRef, gridPaginationSelector);
|
|
28
32
|
const sortingState = useGridSelector(apiRef, gridSortingStateSelector);
|
|
29
|
-
|
|
30
|
-
rowsMeta: {
|
|
31
|
-
currentPageTotalHeight: 0,
|
|
32
|
-
positions: []
|
|
33
|
-
}
|
|
34
|
-
}));
|
|
33
|
+
const currentPage = useGridVisibleRows(apiRef, props);
|
|
35
34
|
const hydrateRowsMeta = React.useCallback(() => {
|
|
36
|
-
const {
|
|
37
|
-
rows
|
|
38
|
-
} = getCurrentPageRows(apiRef, {
|
|
39
|
-
pagination,
|
|
40
|
-
paginationMode
|
|
41
|
-
});
|
|
42
35
|
apiRef.current.setState(state => {
|
|
43
36
|
const positions = [];
|
|
44
37
|
const densityFactor = gridDensityFactorSelector(state, apiRef.current.instanceId);
|
|
45
38
|
const currentRowHeight = gridDensityRowHeightSelector(state, apiRef.current.instanceId);
|
|
46
|
-
const currentPageTotalHeight = rows.reduce((acc, row) => {
|
|
39
|
+
const currentPageTotalHeight = currentPage.rows.reduce((acc, row) => {
|
|
47
40
|
positions.push(acc);
|
|
48
41
|
let baseRowHeight;
|
|
49
42
|
const isResized = rowsHeightLookup.current[row.id] && rowsHeightLookup.current[row.id].isResized || false;
|
|
@@ -60,15 +53,28 @@ export const useGridRowsMeta = (apiRef, props) => {
|
|
|
60
53
|
densityFactor
|
|
61
54
|
})) ?? currentRowHeight;
|
|
62
55
|
}
|
|
63
|
-
}
|
|
56
|
+
} // We use an object to make simple to check if a height is already added or not
|
|
64
57
|
|
|
65
|
-
|
|
58
|
+
|
|
59
|
+
const initialHeights = {
|
|
66
60
|
base: baseRowHeight
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
if (getRowSpacing) {
|
|
64
|
+
const index = apiRef.current.getRowIndexRelativeToVisibleRows(row.id);
|
|
65
|
+
const spacing = getRowSpacing(_extends({}, row, {
|
|
66
|
+
isFirstVisible: index === 0,
|
|
67
|
+
isLastVisible: index === currentPage.rows.length - 1
|
|
68
|
+
}));
|
|
69
|
+
initialHeights.spacingTop = spacing.top ?? 0;
|
|
70
|
+
initialHeights.spacingBottom = spacing.bottom ?? 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const sizes = apiRef.current.unstable_applyPreProcessors('rowHeight', initialHeights, row);
|
|
74
|
+
const finalRowHeight = Object.values(sizes).reduce((acc2, value) => acc2 + value, 0);
|
|
70
75
|
rowsHeightLookup.current[row.id] = {
|
|
71
76
|
value: baseRowHeight,
|
|
77
|
+
sizes,
|
|
72
78
|
isResized
|
|
73
79
|
};
|
|
74
80
|
return acc + finalRowHeight;
|
|
@@ -81,14 +87,19 @@ export const useGridRowsMeta = (apiRef, props) => {
|
|
|
81
87
|
});
|
|
82
88
|
});
|
|
83
89
|
apiRef.current.forceUpdate();
|
|
84
|
-
}, [apiRef,
|
|
90
|
+
}, [apiRef, currentPage.rows, getRowSpacing, getRowHeight]);
|
|
85
91
|
|
|
86
92
|
const getTargetRowHeight = rowId => rowsHeightLookup.current[rowId]?.value || rowHeight;
|
|
87
93
|
|
|
94
|
+
const getRowInternalSizes = rowId => rowsHeightLookup.current[rowId]?.sizes;
|
|
95
|
+
|
|
88
96
|
const setRowHeight = React.useCallback((id, height) => {
|
|
89
97
|
rowsHeightLookup.current[id] = {
|
|
90
98
|
value: height,
|
|
91
|
-
isResized: true
|
|
99
|
+
isResized: true,
|
|
100
|
+
sizes: _extends({}, rowsHeightLookup.current[id].sizes, {
|
|
101
|
+
base: height
|
|
102
|
+
})
|
|
92
103
|
};
|
|
93
104
|
hydrateRowsMeta();
|
|
94
105
|
}, [hydrateRowsMeta]); // The effect is used to build the rows meta data - currentPageTotalHeight and positions.
|
|
@@ -107,6 +118,7 @@ export const useGridRowsMeta = (apiRef, props) => {
|
|
|
107
118
|
useGridApiEventHandler(apiRef, GridEvents.preProcessorRegister, handlePreProcessorRegister);
|
|
108
119
|
const rowsMetaApi = {
|
|
109
120
|
unstable_getRowHeight: getTargetRowHeight,
|
|
121
|
+
unstable_getRowInternalSizes: getRowInternalSizes,
|
|
110
122
|
unstable_setRowHeight: setRowHeight
|
|
111
123
|
};
|
|
112
124
|
useGridApiMethod(apiRef, rowsMetaApi, 'GridRowsMetaApi');
|
|
@@ -10,10 +10,29 @@ import { gridSelectionStateSelector, selectedGridRowsSelector, selectedIdsLookup
|
|
|
10
10
|
import { gridPaginatedVisibleSortedGridRowIdsSelector } from '../pagination';
|
|
11
11
|
import { gridVisibleSortedRowIdsSelector } from '../filter/gridFilterSelector';
|
|
12
12
|
import { GRID_CHECKBOX_SELECTION_COL_DEF, GRID_ACTIONS_COLUMN_TYPE } from '../../../colDef';
|
|
13
|
-
import { useGridStateInit } from '../../utils/useGridStateInit';
|
|
14
13
|
import { GridCellModes } from '../../../models/gridEditRowModel';
|
|
15
14
|
import { isKeyboardEvent } from '../../../utils/keyboardUtils';
|
|
16
|
-
import {
|
|
15
|
+
import { getVisibleRows } from '../../utils/useGridVisibleRows';
|
|
16
|
+
|
|
17
|
+
const getSelectionModelPropValue = (selectionModelProp, prevSelectionModel) => {
|
|
18
|
+
if (selectionModelProp == null) {
|
|
19
|
+
return selectionModelProp;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (Array.isArray(selectionModelProp)) {
|
|
23
|
+
return selectionModelProp;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (prevSelectionModel && prevSelectionModel[0] === selectionModelProp) {
|
|
27
|
+
return prevSelectionModel;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return [selectionModelProp];
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const selectionStateInitializer = (state, props) => _extends({}, state, {
|
|
34
|
+
selection: getSelectionModelPropValue(props.selectionModel) ?? []
|
|
35
|
+
});
|
|
17
36
|
/**
|
|
18
37
|
* @requires useGridRows (state, method)
|
|
19
38
|
* @requires useGridParamsApi (method)
|
|
@@ -22,19 +41,8 @@ import { getCurrentPageRows } from '../../utils/useCurrentPageRows';
|
|
|
22
41
|
export const useGridSelection = (apiRef, props) => {
|
|
23
42
|
const logger = useGridLogger(apiRef, 'useGridSelection');
|
|
24
43
|
const propSelectionModel = React.useMemo(() => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (Array.isArray(props.selectionModel)) {
|
|
30
|
-
return props.selectionModel;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return [props.selectionModel];
|
|
34
|
-
}, [props.selectionModel]);
|
|
35
|
-
useGridStateInit(apiRef, state => _extends({}, state, {
|
|
36
|
-
selection: propSelectionModel ?? []
|
|
37
|
-
}));
|
|
44
|
+
return getSelectionModelPropValue(props.selectionModel, gridSelectionStateSelector(apiRef.current.state));
|
|
45
|
+
}, [apiRef, props.selectionModel]);
|
|
38
46
|
const lastRowToggled = React.useRef(null);
|
|
39
47
|
apiRef.current.unstable_updateControlState({
|
|
40
48
|
stateId: 'selection',
|
|
@@ -319,7 +327,7 @@ export const useGridSelection = (apiRef, props) => {
|
|
|
319
327
|
if (!canHaveMultipleSelection && currentSelection.length > 1) {
|
|
320
328
|
const {
|
|
321
329
|
rows: currentPageRows
|
|
322
|
-
} =
|
|
330
|
+
} = getVisibleRows(apiRef, {
|
|
323
331
|
pagination,
|
|
324
332
|
paginationMode
|
|
325
333
|
});
|