@mui/x-data-grid 7.0.0-beta.6 → 7.0.0-beta.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +117 -1
- package/DataGrid/DataGrid.js +44 -0
- package/DataGrid/useDataGridComponent.js +3 -0
- package/DataGrid/useDataGridProps.js +3 -2
- package/components/GridColumnHeaders.d.ts +1 -2
- package/components/GridColumnHeaders.js +6 -17
- package/components/GridHeaders.js +1 -4
- package/components/GridPagination.js +2 -7
- package/components/GridRow.d.ts +1 -1
- package/components/GridRow.js +4 -19
- package/components/GridScrollArea.d.ts +10 -0
- package/components/GridScrollArea.js +150 -0
- package/components/cell/GridCell.d.ts +7 -0
- package/components/cell/GridCell.js +11 -3
- package/components/columnHeaders/GridBaseColumnHeaders.js +1 -0
- package/components/columnHeaders/GridColumnGroupHeader.d.ts +5 -0
- package/components/columnHeaders/GridColumnGroupHeader.js +18 -8
- package/components/columnHeaders/GridColumnHeaderItem.d.ts +5 -0
- package/components/columnHeaders/GridColumnHeaderItem.js +21 -6
- package/components/columnHeaders/GridGenericColumnHeaderItem.d.ts +1 -0
- package/components/columnHeaders/GridGenericColumnHeaderItem.js +6 -5
- package/components/containers/GridRootStyles.js +12 -20
- package/components/virtualization/GridVirtualScrollbar.js +4 -0
- package/components/virtualization/GridVirtualScroller.js +6 -1
- package/components/virtualization/GridVirtualScrollerFiller.js +2 -1
- package/constants/gridClasses.d.ts +6 -32
- package/constants/gridClasses.js +1 -1
- package/hooks/core/pipeProcessing/gridPipeProcessingApi.d.ts +5 -1
- package/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +23 -7
- package/hooks/features/columnHeaders/useGridColumnHeaders.js +186 -99
- package/hooks/features/columnResize/columnResizeSelector.d.ts +3 -0
- package/hooks/features/columnResize/columnResizeSelector.js +3 -0
- package/hooks/features/columnResize/columnResizeState.d.ts +3 -0
- package/hooks/features/columnResize/columnResizeState.js +1 -0
- package/hooks/features/columnResize/gridColumnResizeApi.d.ts +44 -0
- package/hooks/features/columnResize/gridColumnResizeApi.js +10 -0
- package/hooks/features/columnResize/index.d.ts +3 -0
- package/hooks/features/columnResize/index.js +3 -0
- package/hooks/features/columnResize/useGridColumnResize.d.ts +10 -0
- package/hooks/features/columnResize/useGridColumnResize.js +563 -0
- package/hooks/features/columns/gridColumnsUtils.js +4 -1
- package/hooks/features/dimensions/useGridDimensions.js +4 -5
- package/hooks/features/editing/useGridCellEditing.js +21 -2
- package/hooks/features/export/useGridPrintExport.js +8 -7
- package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.d.ts +1 -0
- package/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +6 -0
- package/hooks/features/headerFiltering/useGridHeaderFiltering.js +30 -7
- package/hooks/features/index.d.ts +1 -0
- package/hooks/features/index.js +1 -0
- package/hooks/features/pagination/gridPaginationInterfaces.d.ts +19 -2
- package/hooks/features/pagination/gridPaginationSelector.d.ts +5 -0
- package/hooks/features/pagination/gridPaginationSelector.js +8 -2
- package/hooks/features/pagination/useGridPagination.d.ts +1 -6
- package/hooks/features/pagination/useGridPagination.js +9 -157
- package/hooks/features/pagination/useGridPaginationModel.d.ts +11 -0
- package/hooks/features/pagination/useGridPaginationModel.js +170 -0
- package/hooks/features/pagination/useGridRowCount.d.ts +8 -0
- package/hooks/features/pagination/useGridRowCount.js +97 -0
- package/hooks/features/scroll/useGridScroll.js +1 -1
- package/hooks/features/virtualization/gridVirtualizationSelectors.d.ts +4 -4
- package/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +2 -2
- package/hooks/utils/useLazyRef.d.ts +1 -2
- package/hooks/utils/useLazyRef.js +1 -11
- package/hooks/utils/useOnMount.d.ts +1 -2
- package/hooks/utils/useOnMount.js +1 -7
- package/hooks/utils/useTimeout.d.ts +1 -11
- package/hooks/utils/useTimeout.js +1 -36
- package/index.js +1 -1
- package/internals/index.d.ts +1 -1
- package/internals/index.js +1 -1
- package/internals/utils/getPinnedCellOffset.d.ts +3 -0
- package/internals/utils/getPinnedCellOffset.js +17 -0
- package/joy/joySlots.js +13 -52
- package/locales/jaJP.js +3 -4
- package/material/index.js +0 -2
- package/models/api/gridApiCommon.d.ts +3 -3
- package/models/api/gridCoreApi.d.ts +1 -5
- package/models/events/gridEventLookup.d.ts +6 -0
- package/models/gridHeaderFilteringModel.d.ts +1 -0
- package/models/gridSlotsComponent.d.ts +0 -5
- package/models/gridStateCommunity.d.ts +2 -0
- package/models/params/gridScrollParams.d.ts +5 -3
- package/models/props/DataGridProps.d.ts +35 -1
- package/modern/DataGrid/DataGrid.js +44 -0
- package/modern/DataGrid/useDataGridComponent.js +3 -0
- package/modern/DataGrid/useDataGridProps.js +3 -2
- package/modern/components/GridColumnHeaders.js +6 -17
- package/modern/components/GridHeaders.js +1 -4
- package/modern/components/GridPagination.js +2 -4
- package/modern/components/GridRow.js +4 -19
- package/modern/components/GridScrollArea.js +150 -0
- package/modern/components/cell/GridCell.js +11 -3
- package/modern/components/columnHeaders/GridBaseColumnHeaders.js +1 -0
- package/modern/components/columnHeaders/GridColumnGroupHeader.js +18 -8
- package/modern/components/columnHeaders/GridColumnHeaderItem.js +21 -6
- package/modern/components/columnHeaders/GridGenericColumnHeaderItem.js +6 -5
- package/modern/components/containers/GridRootStyles.js +12 -20
- package/modern/components/virtualization/GridVirtualScrollbar.js +4 -0
- package/modern/components/virtualization/GridVirtualScroller.js +6 -1
- package/modern/components/virtualization/GridVirtualScrollerFiller.js +2 -1
- package/modern/constants/gridClasses.js +1 -1
- package/modern/hooks/features/columnHeaders/useGridColumnHeaders.js +184 -97
- package/modern/hooks/features/columnResize/columnResizeSelector.js +3 -0
- package/modern/hooks/features/columnResize/columnResizeState.js +1 -0
- package/modern/hooks/features/columnResize/gridColumnResizeApi.js +10 -0
- package/modern/hooks/features/columnResize/index.js +3 -0
- package/modern/hooks/features/columnResize/useGridColumnResize.js +553 -0
- package/modern/hooks/features/columns/gridColumnsUtils.js +4 -1
- package/modern/hooks/features/dimensions/useGridDimensions.js +4 -5
- package/modern/hooks/features/editing/useGridCellEditing.js +21 -2
- package/modern/hooks/features/export/useGridPrintExport.js +8 -7
- package/modern/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +3 -0
- package/modern/hooks/features/headerFiltering/useGridHeaderFiltering.js +21 -2
- package/modern/hooks/features/index.js +1 -0
- package/modern/hooks/features/pagination/gridPaginationSelector.js +8 -2
- package/modern/hooks/features/pagination/useGridPagination.js +8 -149
- package/modern/hooks/features/pagination/useGridPaginationModel.js +165 -0
- package/modern/hooks/features/pagination/useGridRowCount.js +94 -0
- package/modern/hooks/features/scroll/useGridScroll.js +1 -1
- package/modern/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
- package/modern/hooks/utils/useLazyRef.js +1 -11
- package/modern/hooks/utils/useOnMount.js +1 -7
- package/modern/hooks/utils/useTimeout.js +1 -36
- package/modern/index.js +1 -1
- package/modern/internals/index.js +1 -1
- package/modern/internals/utils/getPinnedCellOffset.js +17 -0
- package/modern/joy/joySlots.js +11 -50
- package/modern/locales/jaJP.js +3 -4
- package/modern/material/index.js +0 -2
- package/modern/utils/cellBorderUtils.js +8 -0
- package/modern/utils/domUtils.js +144 -0
- package/node/DataGrid/DataGrid.js +44 -0
- package/node/DataGrid/useDataGridComponent.js +3 -0
- package/node/DataGrid/useDataGridProps.js +3 -2
- package/node/components/GridColumnHeaders.js +6 -16
- package/node/components/GridHeaders.js +1 -4
- package/node/components/GridPagination.js +1 -3
- package/node/components/GridRow.js +3 -18
- package/node/components/GridScrollArea.js +158 -0
- package/node/components/cell/GridCell.js +12 -4
- package/node/components/columnHeaders/GridBaseColumnHeaders.js +1 -0
- package/node/components/columnHeaders/GridColumnGroupHeader.js +18 -8
- package/node/components/columnHeaders/GridColumnHeaderItem.js +21 -6
- package/node/components/columnHeaders/GridGenericColumnHeaderItem.js +6 -5
- package/node/components/containers/GridRootStyles.js +12 -20
- package/node/components/virtualization/GridVirtualScrollbar.js +4 -0
- package/node/components/virtualization/GridVirtualScroller.js +6 -1
- package/node/components/virtualization/GridVirtualScrollerFiller.js +2 -1
- package/node/constants/gridClasses.js +1 -1
- package/node/hooks/features/columnHeaders/useGridColumnHeaders.js +190 -103
- package/node/hooks/features/columnResize/columnResizeSelector.js +10 -0
- package/node/hooks/features/columnResize/columnResizeState.js +5 -0
- package/node/hooks/features/columnResize/gridColumnResizeApi.js +16 -0
- package/node/hooks/features/columnResize/index.js +38 -0
- package/node/hooks/features/columnResize/useGridColumnResize.js +564 -0
- package/node/hooks/features/columns/gridColumnsUtils.js +4 -1
- package/node/hooks/features/dimensions/useGridDimensions.js +4 -5
- package/node/hooks/features/editing/useGridCellEditing.js +21 -2
- package/node/hooks/features/export/useGridPrintExport.js +8 -7
- package/node/hooks/features/headerFiltering/gridHeaderFilteringSelectors.js +4 -1
- package/node/hooks/features/headerFiltering/useGridHeaderFiltering.js +21 -2
- package/node/hooks/features/index.js +11 -0
- package/node/hooks/features/pagination/gridPaginationSelector.js +8 -2
- package/node/hooks/features/pagination/useGridPagination.js +9 -153
- package/node/hooks/features/pagination/useGridPaginationModel.js +176 -0
- package/node/hooks/features/pagination/useGridRowCount.js +103 -0
- package/node/hooks/features/scroll/useGridScroll.js +1 -1
- package/node/hooks/features/virtualization/gridVirtualizationSelectors.js +0 -2
- package/node/hooks/utils/useLazyRef.js +7 -13
- package/node/hooks/utils/useOnMount.js +8 -10
- package/node/hooks/utils/useTimeout.js +7 -37
- package/node/index.js +1 -1
- package/node/internals/index.js +15 -8
- package/node/internals/utils/getPinnedCellOffset.js +24 -0
- package/node/joy/joySlots.js +11 -50
- package/node/locales/jaJP.js +3 -4
- package/node/material/index.js +0 -2
- package/node/utils/cellBorderUtils.js +16 -0
- package/node/utils/domUtils.js +155 -0
- package/package.json +1 -1
- package/utils/cellBorderUtils.d.ts +3 -0
- package/utils/cellBorderUtils.js +8 -0
- package/utils/domUtils.d.ts +14 -1
- package/utils/domUtils.js +147 -0
- package/components/columnHeaders/GridColumnHeadersInner.d.ts +0 -8
- package/components/columnHeaders/GridColumnHeadersInner.js +0 -58
- package/modern/components/columnHeaders/GridColumnHeadersInner.js +0 -58
- package/node/components/columnHeaders/GridColumnHeadersInner.js +0 -67
|
@@ -0,0 +1,563 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { unstable_ownerDocument as ownerDocument, unstable_useEventCallback as useEventCallback } from '@mui/utils';
|
|
4
|
+
import { useTheme } from '@mui/material/styles';
|
|
5
|
+
import { findGridCellElementsFromCol, findGridElement, findLeftPinnedCellsAfterCol, findRightPinnedCellsBeforeCol, getFieldFromHeaderElem, findHeaderElementFromField, findGroupHeaderElementsFromField, findGridHeader, findGridCells, findParentElementFromClassName, findLeftPinnedHeadersAfterCol, findRightPinnedHeadersBeforeCol } from '../../../utils/domUtils';
|
|
6
|
+
import { DEFAULT_GRID_AUTOSIZE_OPTIONS } from './gridColumnResizeApi';
|
|
7
|
+
import { gridClasses } from '../../../constants/gridClasses';
|
|
8
|
+
import { useGridApiEventHandler, useGridApiMethod, useGridApiOptionHandler, useGridLogger, useGridNativeEventListener, useGridSelector, useOnMount } from '../../utils';
|
|
9
|
+
import { gridVirtualizationColumnEnabledSelector } from '../virtualization';
|
|
10
|
+
import { createControllablePromise } from '../../../utils/createControllablePromise';
|
|
11
|
+
import { clamp } from '../../../utils/utils';
|
|
12
|
+
import { useTimeout } from '../../utils/useTimeout';
|
|
13
|
+
import { GridPinnedColumnPosition } from '../columns/gridColumnsInterfaces';
|
|
14
|
+
import { gridColumnsStateSelector } from '../columns';
|
|
15
|
+
// TODO: remove support for Safari < 13.
|
|
16
|
+
// https://caniuse.com/#search=touch-action
|
|
17
|
+
//
|
|
18
|
+
// Safari, on iOS, supports touch action since v13.
|
|
19
|
+
// Over 80% of the iOS phones are compatible
|
|
20
|
+
// in August 2020.
|
|
21
|
+
// Utilizing the CSS.supports method to check if touch-action is supported.
|
|
22
|
+
// Since CSS.supports is supported on all but Edge@12 and IE and touch-action
|
|
23
|
+
// is supported on both Edge@12 and IE if CSS.supports is not available that means that
|
|
24
|
+
// touch-action will be supported
|
|
25
|
+
let cachedSupportsTouchActionNone = false;
|
|
26
|
+
function doesSupportTouchActionNone() {
|
|
27
|
+
if (cachedSupportsTouchActionNone === undefined) {
|
|
28
|
+
if (typeof CSS !== 'undefined' && typeof CSS.supports === 'function') {
|
|
29
|
+
cachedSupportsTouchActionNone = CSS.supports('touch-action', 'none');
|
|
30
|
+
} else {
|
|
31
|
+
cachedSupportsTouchActionNone = true;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return cachedSupportsTouchActionNone;
|
|
35
|
+
}
|
|
36
|
+
function trackFinger(event, currentTouchId) {
|
|
37
|
+
if (currentTouchId !== undefined && event.changedTouches) {
|
|
38
|
+
for (let i = 0; i < event.changedTouches.length; i += 1) {
|
|
39
|
+
const touch = event.changedTouches[i];
|
|
40
|
+
if (touch.identifier === currentTouchId) {
|
|
41
|
+
return {
|
|
42
|
+
x: touch.clientX,
|
|
43
|
+
y: touch.clientY
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
x: event.clientX,
|
|
51
|
+
y: event.clientY
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
function computeNewWidth(initialOffsetToSeparator, clickX, columnBounds, resizeDirection) {
|
|
55
|
+
let newWidth = initialOffsetToSeparator;
|
|
56
|
+
if (resizeDirection === 'Right') {
|
|
57
|
+
newWidth += clickX - columnBounds.left;
|
|
58
|
+
} else {
|
|
59
|
+
newWidth += columnBounds.right - clickX;
|
|
60
|
+
}
|
|
61
|
+
return newWidth;
|
|
62
|
+
}
|
|
63
|
+
function computeOffsetToSeparator(clickX, columnBounds, resizeDirection) {
|
|
64
|
+
if (resizeDirection === 'Left') {
|
|
65
|
+
return clickX - columnBounds.left;
|
|
66
|
+
}
|
|
67
|
+
return columnBounds.right - clickX;
|
|
68
|
+
}
|
|
69
|
+
function flipResizeDirection(side) {
|
|
70
|
+
if (side === 'Right') {
|
|
71
|
+
return 'Left';
|
|
72
|
+
}
|
|
73
|
+
return 'Right';
|
|
74
|
+
}
|
|
75
|
+
function getResizeDirection(separator, direction) {
|
|
76
|
+
const side = separator.classList.contains(gridClasses['columnSeparator--sideRight']) ? 'Right' : 'Left';
|
|
77
|
+
if (direction === 'rtl') {
|
|
78
|
+
// Resizing logic should be mirrored in the RTL case
|
|
79
|
+
return flipResizeDirection(side);
|
|
80
|
+
}
|
|
81
|
+
return side;
|
|
82
|
+
}
|
|
83
|
+
function preventClick(event) {
|
|
84
|
+
event.preventDefault();
|
|
85
|
+
event.stopImmediatePropagation();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Checker that returns a promise that resolves when the column virtualization
|
|
90
|
+
* is disabled.
|
|
91
|
+
*/
|
|
92
|
+
function useColumnVirtualizationDisabled(apiRef) {
|
|
93
|
+
const promise = React.useRef();
|
|
94
|
+
const selector = () => gridVirtualizationColumnEnabledSelector(apiRef);
|
|
95
|
+
const value = useGridSelector(apiRef, selector);
|
|
96
|
+
React.useEffect(() => {
|
|
97
|
+
if (promise.current && value === false) {
|
|
98
|
+
promise.current.resolve();
|
|
99
|
+
promise.current = undefined;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
const asyncCheck = () => {
|
|
103
|
+
if (!promise.current) {
|
|
104
|
+
if (selector() === false) {
|
|
105
|
+
return Promise.resolve();
|
|
106
|
+
}
|
|
107
|
+
promise.current = createControllablePromise();
|
|
108
|
+
}
|
|
109
|
+
return promise.current;
|
|
110
|
+
};
|
|
111
|
+
return asyncCheck;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Basic statistical outlier detection, checks if the value is `F * IQR` away from
|
|
116
|
+
* the Q1 and Q3 boundaries. IQR: interquartile range.
|
|
117
|
+
*/
|
|
118
|
+
function excludeOutliers(inputValues, factor) {
|
|
119
|
+
if (inputValues.length < 4) {
|
|
120
|
+
return inputValues;
|
|
121
|
+
}
|
|
122
|
+
const values = inputValues.slice();
|
|
123
|
+
values.sort((a, b) => a - b);
|
|
124
|
+
const q1 = values[Math.floor(values.length * 0.25)];
|
|
125
|
+
const q3 = values[Math.floor(values.length * 0.75) - 1];
|
|
126
|
+
const iqr = q3 - q1;
|
|
127
|
+
|
|
128
|
+
// We make a small adjustment if `iqr < 5` for the cases where the IQR is
|
|
129
|
+
// very small (e.g. zero) due to very close by values in the input data.
|
|
130
|
+
// Otherwise, with an IQR of `0`, anything outside that would be considered
|
|
131
|
+
// an outlier, but it makes more sense visually to allow for this 5px variance
|
|
132
|
+
// rather than showing a cropped cell.
|
|
133
|
+
const deviation = iqr < 5 ? 5 : iqr * factor;
|
|
134
|
+
return values.filter(v => v > q1 - deviation && v < q3 + deviation);
|
|
135
|
+
}
|
|
136
|
+
function extractColumnWidths(apiRef, options, columns) {
|
|
137
|
+
const widthByField = {};
|
|
138
|
+
const root = apiRef.current.rootElementRef.current;
|
|
139
|
+
root.classList.add(gridClasses.autosizing);
|
|
140
|
+
columns.forEach(column => {
|
|
141
|
+
const cells = findGridCells(apiRef.current, column.field);
|
|
142
|
+
const widths = cells.map(cell => {
|
|
143
|
+
var _cell$getBoundingClie;
|
|
144
|
+
return (_cell$getBoundingClie = cell.getBoundingClientRect().width) != null ? _cell$getBoundingClie : 0;
|
|
145
|
+
});
|
|
146
|
+
const filteredWidths = options.includeOutliers ? widths : excludeOutliers(widths, options.outliersFactor);
|
|
147
|
+
if (options.includeHeaders) {
|
|
148
|
+
const header = findGridHeader(apiRef.current, column.field);
|
|
149
|
+
if (header) {
|
|
150
|
+
var _iconContainer$client, _menuContainer$client;
|
|
151
|
+
const title = header.querySelector(`.${gridClasses.columnHeaderTitle}`);
|
|
152
|
+
const content = header.querySelector(`.${gridClasses.columnHeaderTitleContainerContent}`);
|
|
153
|
+
const iconContainer = header.querySelector(`.${gridClasses.iconButtonContainer}`);
|
|
154
|
+
const menuContainer = header.querySelector(`.${gridClasses.menuIcon}`);
|
|
155
|
+
const element = title != null ? title : content;
|
|
156
|
+
const style = window.getComputedStyle(header, null);
|
|
157
|
+
const paddingWidth = parseInt(style.paddingLeft, 10) + parseInt(style.paddingRight, 10);
|
|
158
|
+
const contentWidth = element.scrollWidth + 1;
|
|
159
|
+
const width = contentWidth + paddingWidth + ((_iconContainer$client = iconContainer == null ? void 0 : iconContainer.clientWidth) != null ? _iconContainer$client : 0) + ((_menuContainer$client = menuContainer == null ? void 0 : menuContainer.clientWidth) != null ? _menuContainer$client : 0);
|
|
160
|
+
filteredWidths.push(width);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const hasColumnMin = column.minWidth !== -Infinity && column.minWidth !== undefined;
|
|
164
|
+
const hasColumnMax = column.maxWidth !== Infinity && column.maxWidth !== undefined;
|
|
165
|
+
const min = hasColumnMin ? column.minWidth : 0;
|
|
166
|
+
const max = hasColumnMax ? column.maxWidth : Infinity;
|
|
167
|
+
const maxContent = filteredWidths.length === 0 ? 0 : Math.max(...filteredWidths);
|
|
168
|
+
widthByField[column.field] = clamp(maxContent, min, max);
|
|
169
|
+
});
|
|
170
|
+
root.classList.remove(gridClasses.autosizing);
|
|
171
|
+
return widthByField;
|
|
172
|
+
}
|
|
173
|
+
export const columnResizeStateInitializer = state => _extends({}, state, {
|
|
174
|
+
columnResize: {
|
|
175
|
+
resizingColumnField: ''
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
/**
|
|
179
|
+
* @requires useGridColumns (method, event)
|
|
180
|
+
* TODO: improve experience for last column
|
|
181
|
+
*/
|
|
182
|
+
export const useGridColumnResize = (apiRef, props) => {
|
|
183
|
+
const theme = useTheme();
|
|
184
|
+
const logger = useGridLogger(apiRef, 'useGridColumnResize');
|
|
185
|
+
const colDefRef = React.useRef();
|
|
186
|
+
const previousMouseClickEvent = React.useRef();
|
|
187
|
+
const columnHeaderElementRef = React.useRef();
|
|
188
|
+
const headerFilterElementRef = React.useRef();
|
|
189
|
+
const groupHeaderElementsRef = React.useRef([]);
|
|
190
|
+
const cellElementsRef = React.useRef([]);
|
|
191
|
+
const leftPinnedCellsAfterRef = React.useRef([]);
|
|
192
|
+
const rightPinnedCellsBeforeRef = React.useRef([]);
|
|
193
|
+
const fillerLeftRef = React.useRef();
|
|
194
|
+
const fillerRightRef = React.useRef();
|
|
195
|
+
const leftPinnedHeadersAfterRef = React.useRef([]);
|
|
196
|
+
const rightPinnedHeadersBeforeRef = React.useRef([]);
|
|
197
|
+
|
|
198
|
+
// To improve accessibility, the separator has padding on both sides.
|
|
199
|
+
// Clicking inside the padding area should be treated as a click in the separator.
|
|
200
|
+
// This ref stores the offset between the click and the separator.
|
|
201
|
+
const initialOffsetToSeparator = React.useRef();
|
|
202
|
+
const resizeDirection = React.useRef();
|
|
203
|
+
const stopResizeEventTimeout = useTimeout();
|
|
204
|
+
const touchId = React.useRef();
|
|
205
|
+
const updateWidth = newWidth => {
|
|
206
|
+
logger.debug(`Updating width to ${newWidth} for col ${colDefRef.current.field}`);
|
|
207
|
+
const prevWidth = columnHeaderElementRef.current.offsetWidth;
|
|
208
|
+
const widthDiff = newWidth - prevWidth;
|
|
209
|
+
colDefRef.current.computedWidth = newWidth;
|
|
210
|
+
colDefRef.current.width = newWidth;
|
|
211
|
+
colDefRef.current.flex = 0;
|
|
212
|
+
columnHeaderElementRef.current.style.width = `${newWidth}px`;
|
|
213
|
+
columnHeaderElementRef.current.style.minWidth = `${newWidth}px`;
|
|
214
|
+
columnHeaderElementRef.current.style.maxWidth = `${newWidth}px`;
|
|
215
|
+
const headerFilterElement = headerFilterElementRef.current;
|
|
216
|
+
if (headerFilterElement) {
|
|
217
|
+
headerFilterElement.style.width = `${newWidth}px`;
|
|
218
|
+
headerFilterElement.style.minWidth = `${newWidth}px`;
|
|
219
|
+
headerFilterElement.style.maxWidth = `${newWidth}px`;
|
|
220
|
+
}
|
|
221
|
+
groupHeaderElementsRef.current.forEach(element => {
|
|
222
|
+
const div = element;
|
|
223
|
+
let finalWidth;
|
|
224
|
+
if (div.getAttribute('aria-colspan') === '1') {
|
|
225
|
+
finalWidth = `${newWidth}px`;
|
|
226
|
+
} else {
|
|
227
|
+
// Cell with colspan > 1 cannot be just updated width new width.
|
|
228
|
+
// Instead, we add width diff to the current width.
|
|
229
|
+
finalWidth = `${div.offsetWidth + widthDiff}px`;
|
|
230
|
+
}
|
|
231
|
+
div.style.width = finalWidth;
|
|
232
|
+
div.style.minWidth = finalWidth;
|
|
233
|
+
div.style.maxWidth = finalWidth;
|
|
234
|
+
});
|
|
235
|
+
cellElementsRef.current.forEach(element => {
|
|
236
|
+
const div = element;
|
|
237
|
+
let finalWidth;
|
|
238
|
+
if (div.getAttribute('aria-colspan') === '1') {
|
|
239
|
+
finalWidth = `${newWidth}px`;
|
|
240
|
+
} else {
|
|
241
|
+
// Cell with colspan > 1 cannot be just updated width new width.
|
|
242
|
+
// Instead, we add width diff to the current width.
|
|
243
|
+
finalWidth = `${div.offsetWidth + widthDiff}px`;
|
|
244
|
+
}
|
|
245
|
+
div.style.setProperty('--width', finalWidth);
|
|
246
|
+
});
|
|
247
|
+
const pinnedPosition = apiRef.current.unstable_applyPipeProcessors('isColumnPinned', false, colDefRef.current.field);
|
|
248
|
+
if (pinnedPosition === GridPinnedColumnPosition.LEFT) {
|
|
249
|
+
updateProperty(fillerLeftRef.current, 'width', widthDiff);
|
|
250
|
+
leftPinnedCellsAfterRef.current.forEach(cell => {
|
|
251
|
+
updateProperty(cell, 'left', widthDiff);
|
|
252
|
+
});
|
|
253
|
+
leftPinnedHeadersAfterRef.current.forEach(header => {
|
|
254
|
+
updateProperty(header, 'left', widthDiff);
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
if (pinnedPosition === GridPinnedColumnPosition.RIGHT) {
|
|
258
|
+
updateProperty(fillerRightRef.current, 'width', widthDiff);
|
|
259
|
+
rightPinnedCellsBeforeRef.current.forEach(cell => {
|
|
260
|
+
updateProperty(cell, 'right', widthDiff);
|
|
261
|
+
});
|
|
262
|
+
rightPinnedHeadersBeforeRef.current.forEach(header => {
|
|
263
|
+
updateProperty(header, 'right', widthDiff);
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
const finishResize = nativeEvent => {
|
|
268
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
269
|
+
stopListening();
|
|
270
|
+
|
|
271
|
+
// Prevent double-clicks from being interpreted as two separate clicks
|
|
272
|
+
if (previousMouseClickEvent.current) {
|
|
273
|
+
const prevEvent = previousMouseClickEvent.current;
|
|
274
|
+
const prevTimeStamp = prevEvent.timeStamp;
|
|
275
|
+
const prevClientX = prevEvent.clientX;
|
|
276
|
+
const prevClientY = prevEvent.clientY;
|
|
277
|
+
|
|
278
|
+
// Check if the current event is part of a double-click
|
|
279
|
+
if (nativeEvent.timeStamp - prevTimeStamp < 300 && nativeEvent.clientX === prevClientX && nativeEvent.clientY === prevClientY) {
|
|
280
|
+
previousMouseClickEvent.current = undefined;
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
if (colDefRef.current) {
|
|
285
|
+
apiRef.current.setColumnWidth(colDefRef.current.field, colDefRef.current.width);
|
|
286
|
+
logger.debug(`Updating col ${colDefRef.current.field} with new width: ${colDefRef.current.width}`);
|
|
287
|
+
}
|
|
288
|
+
stopResizeEventTimeout.start(0, () => {
|
|
289
|
+
apiRef.current.publishEvent('columnResizeStop', null, nativeEvent);
|
|
290
|
+
});
|
|
291
|
+
};
|
|
292
|
+
const storeReferences = (colDef, separator, xStart) => {
|
|
293
|
+
var _apiRef$current$colum;
|
|
294
|
+
const root = apiRef.current.rootElementRef.current;
|
|
295
|
+
colDefRef.current = colDef;
|
|
296
|
+
columnHeaderElementRef.current = findHeaderElementFromField(apiRef.current.columnHeadersContainerRef.current, colDef.field);
|
|
297
|
+
const headerFilterElement = root.querySelector(`.${gridClasses.headerFilterRow} [data-field="${colDef.field}"]`);
|
|
298
|
+
if (headerFilterElement) {
|
|
299
|
+
headerFilterElementRef.current = headerFilterElement;
|
|
300
|
+
}
|
|
301
|
+
groupHeaderElementsRef.current = findGroupHeaderElementsFromField((_apiRef$current$colum = apiRef.current.columnHeadersContainerRef) == null ? void 0 : _apiRef$current$colum.current, colDef.field);
|
|
302
|
+
cellElementsRef.current = findGridCellElementsFromCol(columnHeaderElementRef.current, apiRef.current);
|
|
303
|
+
fillerLeftRef.current = findGridElement(apiRef.current, 'filler--pinnedLeft');
|
|
304
|
+
fillerRightRef.current = findGridElement(apiRef.current, 'filler--pinnedRight');
|
|
305
|
+
const pinnedPosition = apiRef.current.unstable_applyPipeProcessors('isColumnPinned', false, colDefRef.current.field);
|
|
306
|
+
leftPinnedCellsAfterRef.current = pinnedPosition !== GridPinnedColumnPosition.LEFT ? [] : findLeftPinnedCellsAfterCol(apiRef.current, columnHeaderElementRef.current);
|
|
307
|
+
rightPinnedCellsBeforeRef.current = pinnedPosition !== GridPinnedColumnPosition.RIGHT ? [] : findRightPinnedCellsBeforeCol(apiRef.current, columnHeaderElementRef.current);
|
|
308
|
+
leftPinnedHeadersAfterRef.current = pinnedPosition !== GridPinnedColumnPosition.LEFT ? [] : findLeftPinnedHeadersAfterCol(apiRef.current, columnHeaderElementRef.current);
|
|
309
|
+
rightPinnedHeadersBeforeRef.current = pinnedPosition !== GridPinnedColumnPosition.RIGHT ? [] : findRightPinnedHeadersBeforeCol(apiRef.current, columnHeaderElementRef.current);
|
|
310
|
+
resizeDirection.current = getResizeDirection(separator, theme.direction);
|
|
311
|
+
initialOffsetToSeparator.current = computeOffsetToSeparator(xStart, columnHeaderElementRef.current.getBoundingClientRect(), resizeDirection.current);
|
|
312
|
+
};
|
|
313
|
+
const handleResizeMouseUp = useEventCallback(finishResize);
|
|
314
|
+
const handleResizeMouseMove = useEventCallback(nativeEvent => {
|
|
315
|
+
// Cancel move in case some other element consumed a mouseup event and it was not fired.
|
|
316
|
+
if (nativeEvent.buttons === 0) {
|
|
317
|
+
handleResizeMouseUp(nativeEvent);
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
let newWidth = computeNewWidth(initialOffsetToSeparator.current, nativeEvent.clientX, columnHeaderElementRef.current.getBoundingClientRect(), resizeDirection.current);
|
|
321
|
+
newWidth = clamp(newWidth, colDefRef.current.minWidth, colDefRef.current.maxWidth);
|
|
322
|
+
updateWidth(newWidth);
|
|
323
|
+
const params = {
|
|
324
|
+
element: columnHeaderElementRef.current,
|
|
325
|
+
colDef: colDefRef.current,
|
|
326
|
+
width: newWidth
|
|
327
|
+
};
|
|
328
|
+
apiRef.current.publishEvent('columnResize', params, nativeEvent);
|
|
329
|
+
});
|
|
330
|
+
const handleTouchEnd = useEventCallback(nativeEvent => {
|
|
331
|
+
const finger = trackFinger(nativeEvent, touchId.current);
|
|
332
|
+
if (!finger) {
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
finishResize(nativeEvent);
|
|
336
|
+
});
|
|
337
|
+
const handleTouchMove = useEventCallback(nativeEvent => {
|
|
338
|
+
const finger = trackFinger(nativeEvent, touchId.current);
|
|
339
|
+
if (!finger) {
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
// Cancel move in case some other element consumed a touchmove event and it was not fired.
|
|
344
|
+
if (nativeEvent.type === 'mousemove' && nativeEvent.buttons === 0) {
|
|
345
|
+
handleTouchEnd(nativeEvent);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
let newWidth = computeNewWidth(initialOffsetToSeparator.current, finger.x, columnHeaderElementRef.current.getBoundingClientRect(), resizeDirection.current);
|
|
349
|
+
newWidth = clamp(newWidth, colDefRef.current.minWidth, colDefRef.current.maxWidth);
|
|
350
|
+
updateWidth(newWidth);
|
|
351
|
+
const params = {
|
|
352
|
+
element: columnHeaderElementRef.current,
|
|
353
|
+
colDef: colDefRef.current,
|
|
354
|
+
width: newWidth
|
|
355
|
+
};
|
|
356
|
+
apiRef.current.publishEvent('columnResize', params, nativeEvent);
|
|
357
|
+
});
|
|
358
|
+
const handleTouchStart = useEventCallback(event => {
|
|
359
|
+
const cellSeparator = findParentElementFromClassName(event.target, gridClasses['columnSeparator--resizable']);
|
|
360
|
+
// Let the event bubble if the target is not a col separator
|
|
361
|
+
if (!cellSeparator) {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
// If touch-action: none; is not supported we need to prevent the scroll manually.
|
|
365
|
+
if (!doesSupportTouchActionNone()) {
|
|
366
|
+
event.preventDefault();
|
|
367
|
+
}
|
|
368
|
+
const touch = event.changedTouches[0];
|
|
369
|
+
if (touch != null) {
|
|
370
|
+
// A number that uniquely identifies the current finger in the touch session.
|
|
371
|
+
touchId.current = touch.identifier;
|
|
372
|
+
}
|
|
373
|
+
const columnHeaderElement = findParentElementFromClassName(event.target, gridClasses.columnHeader);
|
|
374
|
+
const field = getFieldFromHeaderElem(columnHeaderElement);
|
|
375
|
+
const colDef = apiRef.current.getColumn(field);
|
|
376
|
+
logger.debug(`Start Resize on col ${colDef.field}`);
|
|
377
|
+
apiRef.current.publishEvent('columnResizeStart', {
|
|
378
|
+
field
|
|
379
|
+
}, event);
|
|
380
|
+
storeReferences(colDef, cellSeparator, touch.clientX);
|
|
381
|
+
const doc = ownerDocument(event.currentTarget);
|
|
382
|
+
doc.addEventListener('touchmove', handleTouchMove);
|
|
383
|
+
doc.addEventListener('touchend', handleTouchEnd);
|
|
384
|
+
});
|
|
385
|
+
const stopListening = React.useCallback(() => {
|
|
386
|
+
const doc = ownerDocument(apiRef.current.rootElementRef.current);
|
|
387
|
+
doc.body.style.removeProperty('cursor');
|
|
388
|
+
doc.removeEventListener('mousemove', handleResizeMouseMove);
|
|
389
|
+
doc.removeEventListener('mouseup', handleResizeMouseUp);
|
|
390
|
+
doc.removeEventListener('touchmove', handleTouchMove);
|
|
391
|
+
doc.removeEventListener('touchend', handleTouchEnd);
|
|
392
|
+
// The click event runs right after the mouseup event, we want to wait until it
|
|
393
|
+
// has been canceled before removing our handler.
|
|
394
|
+
setTimeout(() => {
|
|
395
|
+
doc.removeEventListener('click', preventClick, true);
|
|
396
|
+
}, 100);
|
|
397
|
+
if (columnHeaderElementRef.current) {
|
|
398
|
+
columnHeaderElementRef.current.style.pointerEvents = 'unset';
|
|
399
|
+
}
|
|
400
|
+
}, [apiRef, columnHeaderElementRef, handleResizeMouseMove, handleResizeMouseUp, handleTouchMove, handleTouchEnd]);
|
|
401
|
+
const handleResizeStart = React.useCallback(({
|
|
402
|
+
field
|
|
403
|
+
}) => {
|
|
404
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
405
|
+
columnResize: _extends({}, state.columnResize, {
|
|
406
|
+
resizingColumnField: field
|
|
407
|
+
})
|
|
408
|
+
}));
|
|
409
|
+
apiRef.current.forceUpdate();
|
|
410
|
+
}, [apiRef]);
|
|
411
|
+
const handleResizeStop = React.useCallback(() => {
|
|
412
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
413
|
+
columnResize: _extends({}, state.columnResize, {
|
|
414
|
+
resizingColumnField: ''
|
|
415
|
+
})
|
|
416
|
+
}));
|
|
417
|
+
apiRef.current.forceUpdate();
|
|
418
|
+
}, [apiRef]);
|
|
419
|
+
const handleColumnResizeMouseDown = useEventCallback(({
|
|
420
|
+
colDef
|
|
421
|
+
}, event) => {
|
|
422
|
+
// Only handle left clicks
|
|
423
|
+
if (event.button !== 0) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
// Skip if the column isn't resizable
|
|
428
|
+
if (!event.currentTarget.classList.contains(gridClasses['columnSeparator--resizable'])) {
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// Avoid text selection
|
|
433
|
+
event.preventDefault();
|
|
434
|
+
logger.debug(`Start Resize on col ${colDef.field}`);
|
|
435
|
+
apiRef.current.publishEvent('columnResizeStart', {
|
|
436
|
+
field: colDef.field
|
|
437
|
+
}, event);
|
|
438
|
+
storeReferences(colDef, event.currentTarget, event.clientX);
|
|
439
|
+
const doc = ownerDocument(apiRef.current.rootElementRef.current);
|
|
440
|
+
doc.body.style.cursor = 'col-resize';
|
|
441
|
+
previousMouseClickEvent.current = event.nativeEvent;
|
|
442
|
+
doc.addEventListener('mousemove', handleResizeMouseMove);
|
|
443
|
+
doc.addEventListener('mouseup', handleResizeMouseUp);
|
|
444
|
+
|
|
445
|
+
// Prevent the click event if we have resized the column.
|
|
446
|
+
// Fixes https://github.com/mui/mui-x/issues/4777
|
|
447
|
+
doc.addEventListener('click', preventClick, true);
|
|
448
|
+
});
|
|
449
|
+
const handleColumnSeparatorDoubleClick = useEventCallback((params, event) => {
|
|
450
|
+
if (props.disableAutosize) {
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
// Only handle left clicks
|
|
455
|
+
if (event.button !== 0) {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
const column = apiRef.current.state.columns.lookup[params.field];
|
|
459
|
+
if (column.resizable === false) {
|
|
460
|
+
return;
|
|
461
|
+
}
|
|
462
|
+
apiRef.current.autosizeColumns(_extends({}, props.autosizeOptions, {
|
|
463
|
+
columns: [column.field]
|
|
464
|
+
}));
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* API METHODS
|
|
469
|
+
*/
|
|
470
|
+
|
|
471
|
+
const columnVirtualizationDisabled = useColumnVirtualizationDisabled(apiRef);
|
|
472
|
+
const isAutosizingRef = React.useRef(false);
|
|
473
|
+
const autosizeColumns = React.useCallback(async userOptions => {
|
|
474
|
+
var _apiRef$current$rootE, _userOptions$columns;
|
|
475
|
+
const root = (_apiRef$current$rootE = apiRef.current.rootElementRef) == null ? void 0 : _apiRef$current$rootE.current;
|
|
476
|
+
if (!root) {
|
|
477
|
+
return;
|
|
478
|
+
}
|
|
479
|
+
if (isAutosizingRef.current) {
|
|
480
|
+
return;
|
|
481
|
+
}
|
|
482
|
+
isAutosizingRef.current = true;
|
|
483
|
+
const state = gridColumnsStateSelector(apiRef.current.state);
|
|
484
|
+
const options = _extends({}, DEFAULT_GRID_AUTOSIZE_OPTIONS, userOptions, {
|
|
485
|
+
columns: (_userOptions$columns = userOptions == null ? void 0 : userOptions.columns) != null ? _userOptions$columns : state.orderedFields
|
|
486
|
+
});
|
|
487
|
+
options.columns = options.columns.filter(c => state.columnVisibilityModel[c] !== false);
|
|
488
|
+
const columns = options.columns.map(c => apiRef.current.state.columns.lookup[c]);
|
|
489
|
+
try {
|
|
490
|
+
apiRef.current.unstable_setColumnVirtualization(false);
|
|
491
|
+
await columnVirtualizationDisabled();
|
|
492
|
+
const widthByField = extractColumnWidths(apiRef, options, columns);
|
|
493
|
+
const newColumns = columns.map(column => _extends({}, column, {
|
|
494
|
+
width: widthByField[column.field],
|
|
495
|
+
computedWidth: widthByField[column.field]
|
|
496
|
+
}));
|
|
497
|
+
if (options.expand) {
|
|
498
|
+
const visibleColumns = state.orderedFields.map(field => state.lookup[field]).filter(c => state.columnVisibilityModel[c.field] !== false);
|
|
499
|
+
const totalWidth = visibleColumns.reduce((total, column) => {
|
|
500
|
+
var _ref, _widthByField$column$;
|
|
501
|
+
return total + ((_ref = (_widthByField$column$ = widthByField[column.field]) != null ? _widthByField$column$ : column.computedWidth) != null ? _ref : column.width);
|
|
502
|
+
}, 0);
|
|
503
|
+
const availableWidth = apiRef.current.getRootDimensions().viewportInnerSize.width;
|
|
504
|
+
const remainingWidth = availableWidth - totalWidth;
|
|
505
|
+
if (remainingWidth > 0) {
|
|
506
|
+
const widthPerColumn = remainingWidth / (newColumns.length || 1);
|
|
507
|
+
newColumns.forEach(column => {
|
|
508
|
+
column.width += widthPerColumn;
|
|
509
|
+
column.computedWidth += widthPerColumn;
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
apiRef.current.updateColumns(newColumns);
|
|
514
|
+
newColumns.forEach((newColumn, index) => {
|
|
515
|
+
if (newColumn.width !== columns[index].width) {
|
|
516
|
+
const width = newColumn.width;
|
|
517
|
+
apiRef.current.publishEvent('columnWidthChange', {
|
|
518
|
+
element: apiRef.current.getColumnHeaderElement(newColumn.field),
|
|
519
|
+
colDef: newColumn,
|
|
520
|
+
width
|
|
521
|
+
});
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
} finally {
|
|
525
|
+
apiRef.current.unstable_setColumnVirtualization(true);
|
|
526
|
+
isAutosizingRef.current = false;
|
|
527
|
+
}
|
|
528
|
+
}, [apiRef, columnVirtualizationDisabled]);
|
|
529
|
+
|
|
530
|
+
/**
|
|
531
|
+
* EFFECTS
|
|
532
|
+
*/
|
|
533
|
+
|
|
534
|
+
React.useEffect(() => stopListening, [stopListening]);
|
|
535
|
+
useOnMount(() => {
|
|
536
|
+
if (props.autosizeOnMount) {
|
|
537
|
+
Promise.resolve().then(() => {
|
|
538
|
+
apiRef.current.autosizeColumns(props.autosizeOptions);
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
useGridNativeEventListener(apiRef, () => {
|
|
543
|
+
var _apiRef$current$colum2;
|
|
544
|
+
return (_apiRef$current$colum2 = apiRef.current.columnHeadersContainerRef) == null ? void 0 : _apiRef$current$colum2.current;
|
|
545
|
+
}, 'touchstart', handleTouchStart, {
|
|
546
|
+
passive: doesSupportTouchActionNone()
|
|
547
|
+
});
|
|
548
|
+
useGridApiMethod(apiRef, {
|
|
549
|
+
autosizeColumns
|
|
550
|
+
}, 'public');
|
|
551
|
+
useGridApiEventHandler(apiRef, 'columnResizeStop', handleResizeStop);
|
|
552
|
+
useGridApiEventHandler(apiRef, 'columnResizeStart', handleResizeStart);
|
|
553
|
+
useGridApiEventHandler(apiRef, 'columnSeparatorMouseDown', handleColumnResizeMouseDown);
|
|
554
|
+
useGridApiEventHandler(apiRef, 'columnSeparatorDoubleClick', handleColumnSeparatorDoubleClick);
|
|
555
|
+
useGridApiOptionHandler(apiRef, 'columnResize', props.onColumnResize);
|
|
556
|
+
useGridApiOptionHandler(apiRef, 'columnWidthChange', props.onColumnWidthChange);
|
|
557
|
+
};
|
|
558
|
+
function updateProperty(element, property, delta) {
|
|
559
|
+
if (!element) {
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
element.style[property] = `${parseInt(element.style[property], 10) + delta}px`;
|
|
563
|
+
}
|
|
@@ -3,6 +3,7 @@ import { DEFAULT_GRID_COL_TYPE_KEY, GRID_STRING_COL_DEF, getGridDefaultColumnTyp
|
|
|
3
3
|
import { gridColumnsStateSelector, gridColumnVisibilityModelSelector } from './gridColumnsSelector';
|
|
4
4
|
import { clamp } from '../../../utils/utils';
|
|
5
5
|
import { gridDensityFactorSelector } from '../density/densitySelector';
|
|
6
|
+
import { gridHeaderFilteringEnabledSelector } from '../headerFiltering/gridHeaderFilteringSelectors';
|
|
6
7
|
import { gridColumnGroupsHeaderMaxDepthSelector } from '../columnGrouping/gridColumnGroupsSelector';
|
|
7
8
|
export const COLUMNS_DIMENSION_PROPERTIES = ['maxWidth', 'minWidth', 'width', 'flex'];
|
|
8
9
|
const COLUMN_TYPES = getGridDefaultColumnTypes();
|
|
@@ -326,5 +327,7 @@ export function getFirstColumnIndexToRender({
|
|
|
326
327
|
export function getTotalHeaderHeight(apiRef, headerHeight) {
|
|
327
328
|
const densityFactor = gridDensityFactorSelector(apiRef);
|
|
328
329
|
const maxDepth = gridColumnGroupsHeaderMaxDepthSelector(apiRef);
|
|
329
|
-
|
|
330
|
+
const isHeaderFilteringEnabled = gridHeaderFilteringEnabledSelector(apiRef);
|
|
331
|
+
const multiplicationFactor = isHeaderFilteringEnabled ? 2 : 1;
|
|
332
|
+
return Math.floor(headerHeight * densityFactor) * ((maxDepth != null ? maxDepth : 0) + multiplicationFactor);
|
|
330
333
|
}
|
|
@@ -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();
|
|
@@ -114,8 +112,9 @@ export function useGridDimensions(apiRef, props) {
|
|
|
114
112
|
const scrollbarSize = measureScrollbarSize(rootElement, columnsTotalWidth, props.scrollbarSize);
|
|
115
113
|
const topContainerHeight = headersTotalHeight + pinnedRowsHeight.top;
|
|
116
114
|
const bottomContainerHeight = pinnedRowsHeight.bottom;
|
|
115
|
+
const nonPinnedColumnsTotalWidth = columnsTotalWidth - leftPinnedWidth - rightPinnedWidth;
|
|
117
116
|
const contentSize = {
|
|
118
|
-
width:
|
|
117
|
+
width: nonPinnedColumnsTotalWidth,
|
|
119
118
|
height: rowsMeta.currentPageTotalHeight
|
|
120
119
|
};
|
|
121
120
|
let viewportOuterSize;
|
|
@@ -164,7 +163,7 @@ export function useGridDimensions(apiRef, props) {
|
|
|
164
163
|
}
|
|
165
164
|
const rowWidth = Math.max(viewportOuterSize.width, columnsTotalWidth + (hasScrollY ? scrollbarSize : 0));
|
|
166
165
|
const minimumSize = {
|
|
167
|
-
width:
|
|
166
|
+
width: columnsTotalWidth,
|
|
168
167
|
height: topContainerHeight + contentSize.height + bottomContainerHeight
|
|
169
168
|
};
|
|
170
169
|
const newDimensions = {
|
|
@@ -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,
|
|
@@ -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';
|
|
@@ -96,9 +96,6 @@ export const useGridPrintExport = (apiRef, props) => {
|
|
|
96
96
|
|
|
97
97
|
// See https://support.google.com/chrome/thread/191619088?hl=en&msgid=193009642
|
|
98
98
|
gridClone.style.contain = 'size';
|
|
99
|
-
const columnHeaders = gridClone.querySelector(`.${gridClasses.columnHeaders}`);
|
|
100
|
-
const columnHeadersInner = columnHeaders.querySelector(`.${gridClasses.columnHeadersInner}`);
|
|
101
|
-
columnHeadersInner.style.width = '100%';
|
|
102
99
|
let gridToolbarElementHeight = ((_querySelector = gridRootElement.querySelector(`.${gridClasses.toolbarContainer}`)) == null ? void 0 : _querySelector.offsetHeight) || 0;
|
|
103
100
|
let gridFooterElementHeight = ((_querySelector2 = gridRootElement.querySelector(`.${gridClasses.footerContainer}`)) == null ? void 0 : _querySelector2.offsetHeight) || 0;
|
|
104
101
|
if (normalizeOptions.hideToolbar) {
|
|
@@ -223,9 +220,13 @@ export const useGridPrintExport = (apiRef, props) => {
|
|
|
223
220
|
page: 0,
|
|
224
221
|
pageSize: visibleRowCount
|
|
225
222
|
};
|
|
226
|
-
apiRef.current.
|
|
227
|
-
|
|
228
|
-
|
|
223
|
+
apiRef.current.setState(state => _extends({}, state, {
|
|
224
|
+
pagination: _extends({}, state.pagination, {
|
|
225
|
+
paginationModel: getDerivedPaginationModel(state.pagination,
|
|
226
|
+
// Using signature `DataGridPro` to allow more than 100 rows in the print export
|
|
227
|
+
'DataGridPro', paginationModel)
|
|
228
|
+
})
|
|
229
|
+
}));
|
|
229
230
|
apiRef.current.forceUpdate();
|
|
230
231
|
}
|
|
231
232
|
await updateGridColumnsForPrint(options == null ? void 0 : options.fields, options == null ? void 0 : options.allColumns, options == null ? void 0 : options.includeCheckboxes);
|