-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix row pinning with column virtualization
- Loading branch information
1 parent
e4a3c09
commit ff42b31
Showing
7 changed files
with
180 additions
and
5 deletions.
There are no files selected for viewing
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,63 @@ | ||
import * as React from 'react'; | ||
import { DataGridPro } from '@mui/x-data-grid-pro'; | ||
|
||
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` }); | ||
} | ||
|
||
setData({ | ||
rows, | ||
columns, | ||
}); | ||
}, [rowLength, columnLength]); | ||
|
||
return data; | ||
} | ||
|
||
export default function RowPinningWithVirtualization() { | ||
const data = useData(100, 1000); | ||
|
||
console.log('data', data); | ||
|
||
if (!data.rows.length) { | ||
return null; | ||
} | ||
|
||
const [pinnedRow0, pinnedRow1, pinnedRow2, ...rows] = data.rows; | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGridPro | ||
{...data} | ||
rows={rows} | ||
columnBuffer={2} | ||
columnThreshold={2} | ||
pinnedRows={{ top: [pinnedRow0, pinnedRow1], bottom: [pinnedRow2] }} | ||
pinnedColumns={{ | ||
left: ['price1M', 'price67M'], | ||
right: ['price31M', 'price2M'], | ||
}} | ||
/> | ||
</div> | ||
); | ||
} |
11 changes: 11 additions & 0 deletions
11
docs/data/data-grid/rows/RowPinningWithVirtualization.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,11 @@ | ||
<DataGridPro | ||
{...data} | ||
rows={rows} | ||
columnBuffer={2} | ||
columnThreshold={2} | ||
pinnedRows={{ top: [pinnedRow0, pinnedRow1], bottom: [pinnedRow2] }} | ||
pinnedColumns={{ | ||
left: ['price1M', 'price67M'], | ||
right: ['price31M', 'price2M'], | ||
}} | ||
/> |
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,73 @@ | ||
import * as React from 'react'; | ||
import { DataGridPro, GridColDef, GridRowId } from '@mui/x-data-grid-pro'; | ||
|
||
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` }); | ||
} | ||
|
||
setData({ | ||
rows, | ||
columns, | ||
}); | ||
}, [rowLength, columnLength]); | ||
|
||
return data; | ||
} | ||
|
||
export default function RowPinningWithVirtualization() { | ||
const data = useData(100, 1000); | ||
|
||
console.log('data', data); | ||
|
||
if (!data.rows.length) { | ||
return null; | ||
} | ||
|
||
const [pinnedRow0, pinnedRow1, pinnedRow2, ...rows] = data.rows; | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGridPro | ||
{...data} | ||
rows={rows} | ||
columnBuffer={2} | ||
columnThreshold={2} | ||
pinnedRows={{ top: [pinnedRow0, pinnedRow1], bottom: [pinnedRow2] }} | ||
pinnedColumns={{ | ||
left: ['price1M', 'price67M'], | ||
right: ['price31M', 'price2M'], | ||
}} | ||
/> | ||
</div> | ||
); | ||
} |
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