-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DataGrid] Support column virtualization with dynamic row height (#15541
- Loading branch information
1 parent
419eb67
commit 00c0b2b
Showing
18 changed files
with
188 additions
and
9 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
docs/data/data-grid/row-height/VirtualizeColumnsWithAutoRowHeight.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import * as React from 'react'; | ||
import { DataGrid } from '@mui/x-data-grid'; | ||
|
||
function useData(rowLength, columnLength) { | ||
const [data, setData] = React.useState({ columns: [], rows: [] }); | ||
|
||
React.useEffect(() => { | ||
const rows = []; | ||
|
||
for (let i = 0; i < rowLength; i += 1) { | ||
const row = { | ||
id: i, | ||
}; | ||
|
||
for (let j = 1; j <= columnLength; j += 1) { | ||
row[`price${j}M`] = `${i.toString()}, ${j} `; | ||
} | ||
|
||
rows.push(row); | ||
} | ||
|
||
const columns = []; | ||
|
||
for (let j = 1; j <= columnLength; j += 1) { | ||
columns.push({ field: `price${j}M`, headerName: `${j}M`, width: 55 }); | ||
} | ||
|
||
setData({ | ||
rows, | ||
columns, | ||
}); | ||
}, [rowLength, columnLength]); | ||
|
||
return data; | ||
} | ||
|
||
export default function VirtualizeColumnsWithAutoRowHeight() { | ||
const data = useData(100, 100); | ||
|
||
return ( | ||
<div style={{ height: 600, width: '100%' }}> | ||
<DataGrid | ||
{...data} | ||
getRowHeight={() => 'auto'} | ||
virtualizeColumnsWithAutoRowHeight | ||
/> | ||
</div> | ||
); | ||
} |
59 changes: 59 additions & 0 deletions
59
docs/data/data-grid/row-height/VirtualizeColumnsWithAutoRowHeight.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import * as React from 'react'; | ||
import { DataGrid, GridColDef, GridRowId } from '@mui/x-data-grid'; | ||
|
||
export interface DataRowModel { | ||
id: GridRowId; | ||
[price: string]: number | string; | ||
} | ||
|
||
export interface GridData { | ||
columns: GridColDef[]; | ||
rows: DataRowModel[]; | ||
} | ||
|
||
function useData(rowLength: number, columnLength: number) { | ||
const [data, setData] = React.useState<GridData>({ columns: [], rows: [] }); | ||
|
||
React.useEffect(() => { | ||
const rows: DataRowModel[] = []; | ||
|
||
for (let i = 0; i < rowLength; i += 1) { | ||
const row: DataRowModel = { | ||
id: i, | ||
}; | ||
|
||
for (let j = 1; j <= columnLength; j += 1) { | ||
row[`price${j}M`] = `${i.toString()}, ${j} `; | ||
} | ||
|
||
rows.push(row); | ||
} | ||
|
||
const columns: GridColDef[] = []; | ||
|
||
for (let j = 1; j <= columnLength; j += 1) { | ||
columns.push({ field: `price${j}M`, headerName: `${j}M`, width: 55 }); | ||
} | ||
|
||
setData({ | ||
rows, | ||
columns, | ||
}); | ||
}, [rowLength, columnLength]); | ||
|
||
return data; | ||
} | ||
|
||
export default function VirtualizeColumnsWithAutoRowHeight() { | ||
const data = useData(100, 100); | ||
|
||
return ( | ||
<div style={{ height: 600, width: '100%' }}> | ||
<DataGrid | ||
{...data} | ||
getRowHeight={() => 'auto'} | ||
virtualizeColumnsWithAutoRowHeight | ||
/> | ||
</div> | ||
); | ||
} |
5 changes: 5 additions & 0 deletions
5
docs/data/data-grid/row-height/VirtualizeColumnsWithAutoRowHeight.tsx.preview
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<DataGrid | ||
{...data} | ||
getRowHeight={() => 'auto'} | ||
virtualizeColumnsWithAutoRowHeight | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters