Skip to content

Commit

Permalink
[DataGridPro] Add test for column pinning with disabled column virtua…
Browse files Browse the repository at this point in the history
…lization (#16176)
  • Loading branch information
cherniavskii authored and web-flow committed Jan 15, 2025
1 parent 014db97 commit be8fc38
Showing 1 changed file with 77 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// /~https://github.com/mui/mui-x/issues/16136

/* eslint-disable @typescript-eslint/no-use-before-define */
import * as React from 'react';
import { DataGridPro, useGridApiRef } from '@mui/x-data-grid-pro';
import {
randomCreatedDate,
randomTraderName,
randomEmail,
randomUpdatedDate,
} from '@mui/x-data-grid-generator';

export default function DataGridPinnedColumnsNoVirtualization() {
const apiRef = useGridApiRef();

React.useEffect(() => {
if (apiRef.current) {
apiRef.current.unstable_setColumnVirtualization(false);
}
}, [apiRef]);

return (
<div style={{ height: 400, width: '100%' }}>
<DataGridPro
apiRef={apiRef}
rows={rows}
columns={columns}
initialState={{ pinnedColumns: { left: ['name'], right: ['email'] } }}
/>
</div>
);
}

const columns = [
{ field: 'name', headerName: 'Name', width: 160 },
{ field: 'email', headerName: 'Email', width: 200 },
{ field: 'age', headerName: 'Age', type: 'number' },
{
field: 'dateCreated',
headerName: 'Date Created',
type: 'date',
width: 180,
},
{
field: 'lastLogin',
headerName: 'Last Login',
type: 'dateTime',
width: 220,
},
];

const rows = [
{
id: 1,
name: randomTraderName(),
email: randomEmail(),
age: 25,
dateCreated: randomCreatedDate(),
lastLogin: randomUpdatedDate(),
},
{
id: 2,
name: randomTraderName(),
email: randomEmail(),
age: 36,
dateCreated: randomCreatedDate(),
lastLogin: randomUpdatedDate(),
},
{
id: 3,
name: randomTraderName(),
email: randomEmail(),
age: 19,
dateCreated: randomCreatedDate(),
lastLogin: randomUpdatedDate(),
},
];

0 comments on commit be8fc38

Please sign in to comment.