From d9ac050aea0b9a03a959a67e6a71c923d5562351 Mon Sep 17 00:00:00 2001 From: Rom Grk Date: Thu, 22 Feb 2024 04:39:36 -0500 Subject: [PATCH] [data grid] Performance: DOM changes (#12013) Signed-off-by: Rom Grk Co-authored-by: Olivier Tassinari Co-authored-by: Andrew Cherniavskyi --- .../aggregation/AggregationRenderCell.js | 1 + .../aggregation/AggregationRenderCell.tsx | 1 + .../column-dimensions/ColumnAutosizing.js | 7 ++- .../column-dimensions/ColumnAutosizing.tsx | 7 ++- .../ColumnAutosizingAsync.js | 7 ++- .../ColumnAutosizingAsync.tsx | 11 +++- .../custom-columns/SparklineColumn.js | 1 + .../custom-columns/SparklineColumn.tsx | 1 + .../data-grid/demo/PopularFeaturesDemo.js | 2 + .../data-grid/demo/PopularFeaturesDemo.tsx | 2 + .../data-grid/editing/CustomEditComponent.js | 1 + .../data-grid/editing/CustomEditComponent.tsx | 1 + .../migration-data-grid-v6.md | 5 +- .../x/api/data-grid/data-grid-premium.json | 18 ++---- docs/pages/x/api/data-grid/data-grid-pro.json | 18 ++---- docs/pages/x/api/data-grid/data-grid.json | 18 ++---- .../x/api/data-grid/grid-actions-col-def.md | 1 + docs/pages/x/api/data-grid/grid-col-def.md | 1 + .../data-grid/grid-single-select-col-def.md | 1 + .../data-grid-premium/data-grid-premium.json | 13 ++-- .../data-grid-pro/data-grid-pro.json | 13 ++-- .../data-grid/data-grid/data-grid.json | 13 ++-- .../src/columns/employees.columns.tsx | 2 + .../src/renderer/renderProgress.tsx | 18 ++++-- .../columnResize/useGridColumnResize.tsx | 5 +- .../src/tests/rowReorder.DataGridPro.test.tsx | 2 +- .../src/colDef/gridActionsColDef.tsx | 1 + .../src/colDef/gridBooleanColDef.tsx | 1 + .../colDef/gridCheckboxSelectionColDef.tsx | 1 + .../components/GridScrollbarFillerCell.tsx | 28 ++------- .../src/components/cell/GridCell.tsx | 21 ++++--- .../components/containers/GridRootStyles.ts | 61 ++++++++++++++----- .../x-data-grid/src/constants/gridClasses.ts | 39 +++++++++--- .../src/models/colDef/gridColDef.ts | 6 ++ 34 files changed, 193 insertions(+), 135 deletions(-) diff --git a/docs/data/data-grid/aggregation/AggregationRenderCell.js b/docs/data/data-grid/aggregation/AggregationRenderCell.js index 4f034261d423..1bf1c1bcc7b3 100644 --- a/docs/data/data-grid/aggregation/AggregationRenderCell.js +++ b/docs/data/data-grid/aggregation/AggregationRenderCell.js @@ -11,6 +11,7 @@ const COLUMNS = [ type: 'number', width: 180, availableAggregationFunctions: ['min', 'max', 'avg', 'size'], + display: 'flex', // Imdb rating is on a scale from 0 to 10, the MUI rating component is on a scale from 0 to 5 renderCell: (params) => { if (params.aggregation && !params.aggregation.hasCellUnit) { diff --git a/docs/data/data-grid/aggregation/AggregationRenderCell.tsx b/docs/data/data-grid/aggregation/AggregationRenderCell.tsx index 11f653668ba1..a0de64c3ee69 100644 --- a/docs/data/data-grid/aggregation/AggregationRenderCell.tsx +++ b/docs/data/data-grid/aggregation/AggregationRenderCell.tsx @@ -11,6 +11,7 @@ const COLUMNS: GridColDef[] = [ type: 'number', width: 180, availableAggregationFunctions: ['min', 'max', 'avg', 'size'], + display: 'flex', // Imdb rating is on a scale from 0 to 10, the MUI rating component is on a scale from 0 to 5 renderCell: (params) => { if (params.aggregation && !params.aggregation.hasCellUnit) { diff --git a/docs/data/data-grid/column-dimensions/ColumnAutosizing.js b/docs/data/data-grid/column-dimensions/ColumnAutosizing.js index 030c4d0534d9..3d46d27bbd9b 100644 --- a/docs/data/data-grid/column-dimensions/ColumnAutosizing.js +++ b/docs/data/data-grid/column-dimensions/ColumnAutosizing.js @@ -36,7 +36,12 @@ function useData(length) { { field: 'id', headerName: 'Brand ID' }, { field: 'brand', headerName: 'Brand name' }, { field: 'rep', headerName: 'Representative' }, - { field: 'rating', headerName: 'Rating', renderCell: renderRating }, + { + field: 'rating', + headerName: 'Rating', + renderCell: renderRating, + display: 'flex', + }, ]; return { rows, columns }; diff --git a/docs/data/data-grid/column-dimensions/ColumnAutosizing.tsx b/docs/data/data-grid/column-dimensions/ColumnAutosizing.tsx index 5f813676e7ee..841b6642113d 100644 --- a/docs/data/data-grid/column-dimensions/ColumnAutosizing.tsx +++ b/docs/data/data-grid/column-dimensions/ColumnAutosizing.tsx @@ -39,7 +39,12 @@ function useData(length: number) { { field: 'id', headerName: 'Brand ID' }, { field: 'brand', headerName: 'Brand name' }, { field: 'rep', headerName: 'Representative' }, - { field: 'rating', headerName: 'Rating', renderCell: renderRating }, + { + field: 'rating', + headerName: 'Rating', + renderCell: renderRating, + display: 'flex' as const, + }, ]; return { rows, columns }; diff --git a/docs/data/data-grid/column-dimensions/ColumnAutosizingAsync.js b/docs/data/data-grid/column-dimensions/ColumnAutosizingAsync.js index 01490fbfceb2..b030e5f9c060 100644 --- a/docs/data/data-grid/column-dimensions/ColumnAutosizingAsync.js +++ b/docs/data/data-grid/column-dimensions/ColumnAutosizingAsync.js @@ -15,7 +15,12 @@ const columns = [ { field: 'id', headerName: 'Brand ID' }, { field: 'brand', headerName: 'Brand name' }, { field: 'rep', headerName: 'Representative' }, - { field: 'rating', headerName: 'Rating', renderCell: renderRating }, + { + field: 'rating', + headerName: 'Rating', + renderCell: renderRating, + display: 'flex', + }, ]; function renderRating(params) { diff --git a/docs/data/data-grid/column-dimensions/ColumnAutosizingAsync.tsx b/docs/data/data-grid/column-dimensions/ColumnAutosizingAsync.tsx index 2140a5e5ae3b..d5a7cee379fb 100644 --- a/docs/data/data-grid/column-dimensions/ColumnAutosizingAsync.tsx +++ b/docs/data/data-grid/column-dimensions/ColumnAutosizingAsync.tsx @@ -3,7 +3,7 @@ import Button from '@mui/material/Button'; import Rating from '@mui/material/Rating'; import Stack from '@mui/material/Stack'; import { useGridApiRef } from '@mui/x-data-grid'; -import { DataGridPro, GridApiPro } from '@mui/x-data-grid-pro'; +import { DataGridPro, GridApiPro, GridColDef } from '@mui/x-data-grid-pro'; import { randomInt, randomRating, @@ -12,11 +12,16 @@ import { import * as ReactDOM from 'react-dom'; import { GridData } from 'docsx/data/data-grid/virtualization/ColumnVirtualizationGrid'; -const columns = [ +const columns: GridColDef[] = [ { field: 'id', headerName: 'Brand ID' }, { field: 'brand', headerName: 'Brand name' }, { field: 'rep', headerName: 'Representative' }, - { field: 'rating', headerName: 'Rating', renderCell: renderRating }, + { + field: 'rating', + headerName: 'Rating', + renderCell: renderRating, + display: 'flex', + }, ]; function renderRating(params: any) { diff --git a/docs/data/data-grid/custom-columns/SparklineColumn.js b/docs/data/data-grid/custom-columns/SparklineColumn.js index 3b6eb6b9016b..f2a38c1813cf 100644 --- a/docs/data/data-grid/custom-columns/SparklineColumn.js +++ b/docs/data/data-grid/custom-columns/SparklineColumn.js @@ -24,6 +24,7 @@ const sparklineColumnType = { sortable: false, editable: false, groupable: false, + display: 'flex', renderCell: (params) => , }; diff --git a/docs/data/data-grid/custom-columns/SparklineColumn.tsx b/docs/data/data-grid/custom-columns/SparklineColumn.tsx index b643d30d037d..cf646189b49f 100644 --- a/docs/data/data-grid/custom-columns/SparklineColumn.tsx +++ b/docs/data/data-grid/custom-columns/SparklineColumn.tsx @@ -36,6 +36,7 @@ const sparklineColumnType: GridColTypeDef = { sortable: false, editable: false, groupable: false, + display: 'flex', renderCell: (params) => , }; diff --git a/docs/data/data-grid/demo/PopularFeaturesDemo.js b/docs/data/data-grid/demo/PopularFeaturesDemo.js index b30a71abeae7..3da89e7e926b 100644 --- a/docs/data/data-grid/demo/PopularFeaturesDemo.js +++ b/docs/data/data-grid/demo/PopularFeaturesDemo.js @@ -368,6 +368,7 @@ const columns = [ flex: 0.2, minWidth: 100, groupable: false, + display: 'flex', renderCell: (params) => { if (params.aggregation) { return ; @@ -430,6 +431,7 @@ const columns = [ flex: 0.3, type: 'singleSelect', valueOptions: ['Premium', 'Pro', 'Community'], + display: 'flex', renderCell: (params) => { if (params.aggregation) { return ; diff --git a/docs/data/data-grid/demo/PopularFeaturesDemo.tsx b/docs/data/data-grid/demo/PopularFeaturesDemo.tsx index 982e81055f7e..89912c4f12c4 100644 --- a/docs/data/data-grid/demo/PopularFeaturesDemo.tsx +++ b/docs/data/data-grid/demo/PopularFeaturesDemo.tsx @@ -383,6 +383,7 @@ const columns: GridColDef[] = [ flex: 0.2, minWidth: 100, groupable: false, + display: 'flex', renderCell: (params) => { if (params.aggregation) { return ; @@ -445,6 +446,7 @@ const columns: GridColDef[] = [ flex: 0.3, type: 'singleSelect', valueOptions: ['Premium', 'Pro', 'Community'], + display: 'flex', renderCell: (params: GridRenderCellParams) => { if (params.aggregation) { return ; diff --git a/docs/data/data-grid/editing/CustomEditComponent.js b/docs/data/data-grid/editing/CustomEditComponent.js index d5d5cd3596fd..bdacf3318440 100644 --- a/docs/data/data-grid/editing/CustomEditComponent.js +++ b/docs/data/data-grid/editing/CustomEditComponent.js @@ -58,6 +58,7 @@ const columns = [ { field: 'rating', headerName: 'Rating', + display: 'flex', renderCell: renderRating, renderEditCell: renderRatingEditInputCell, editable: true, diff --git a/docs/data/data-grid/editing/CustomEditComponent.tsx b/docs/data/data-grid/editing/CustomEditComponent.tsx index 63d036378717..d0fb1bde9c10 100644 --- a/docs/data/data-grid/editing/CustomEditComponent.tsx +++ b/docs/data/data-grid/editing/CustomEditComponent.tsx @@ -65,6 +65,7 @@ const columns: GridColDef[] = [ { field: 'rating', headerName: 'Rating', + display: 'flex', renderCell: renderRating, renderEditCell: renderRatingEditInputCell, editable: true, diff --git a/docs/data/migration/migration-data-grid-v6/migration-data-grid-v6.md b/docs/data/migration/migration-data-grid-v6/migration-data-grid-v6.md index e9077aa350d6..3ce5734605a1 100644 --- a/docs/data/migration/migration-data-grid-v6/migration-data-grid-v6.md +++ b/docs/data/migration/migration-data-grid-v6/migration-data-grid-v6.md @@ -104,6 +104,7 @@ As a result, the following changes have been made: - The main element now corresponds to the virtal scroller element. - Headers are now contained in the virtual scroller. - Pinned row and column sections are now contained in the virtual scroller. +- The cell inner wrapper `.MuiDataGrid-cellContent` has been removed.