Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
cherniavskii committed Jul 11, 2022
1 parent 305983b commit 9d1b57c
Show file tree
Hide file tree
Showing 12 changed files with 294 additions and 875 deletions.
213 changes: 31 additions & 182 deletions docs/data/data-grid/rows/RowPinning.js
Original file line number Diff line number Diff line change
@@ -1,199 +1,48 @@
import * as React from 'react';
import { DataGridPro } from '@mui/x-data-grid-pro';
import {
randomCity,
randomEmail,
randomId,
randomInt,
randomTraderName,
randomUserName,
} from '@mui/x-data-grid-generator';

const columns = [
{ field: 'id', headerName: 'ID', width: 200 },
{ field: 'firstName', headerName: 'First name', width: 200 },
{ field: 'lastName', headerName: 'Last name', width: 200 },
{ field: 'occupation', headerName: 'Occupation', width: 200 },
{ field: 'birthday', headerName: 'Birthday', width: 200, type: 'date' },
{ field: 'name', headerName: 'Name', width: 150 },
{ field: 'city', headerName: 'City', width: 150 },
{ field: 'username', headerName: 'Username' },
{ field: 'email', headerName: 'Email', width: 200 },
{ field: 'age', type: 'number', headerName: 'Age' },
];

const data = [
{
id: 1,
firstName: 'Walter',
lastName: 'White',
occupation: 'Chemistry teacher',
birthday: '09-07-1958',
},
{
id: 2,
firstName: 'Jesse',
lastName: 'Pinkman',
occupation: 'Dealer',
birthday: '09-24-1984',
},
{
id: 3,
firstName: 'Skyler',
lastName: 'White',
occupation: 'Bookkeeper',
birthday: '08-11-1970',
},
{
id: 4,
firstName: 'Saul',
lastName: 'Goodman',
occupation: 'Lawyer',
birthday: '',
},
{
id: 5,
firstName: 'Hank',
lastName: 'Schrader',
occupation: 'DEA Agent',
birthday: '',
},
{
id: 6,
firstName: 'Gus',
lastName: 'Fring',
occupation: 'Restaurant owner',
birthday: '',
},
{
id: 7,
firstName: 'Mike',
lastName: 'Ehrmantraut',
occupation: 'Private Investigator',
birthday: '',
},
{
id: 8,
firstName: 'Walter',
lastName: 'White',
occupation: 'Chemistry teacher',
birthday: '09-07-1958',
},
{
id: 9,
firstName: 'Jesse',
lastName: 'Pinkman',
occupation: 'Dealer',
birthday: '09-24-1984',
},
{
id: 10,
firstName: 'Skyler',
lastName: 'White',
occupation: 'Bookkeeper',
birthday: '08-11-1970',
},
{
id: 11,
firstName: 'Saul',
lastName: 'Goodman',
occupation: 'Lawyer',
birthday: '',
},
{
id: 12,
firstName: 'Hank',
lastName: 'Schrader',
occupation: 'DEA Agent',
birthday: '',
},
{
id: 13,
firstName: 'Gus',
lastName: 'Fring',
occupation: 'Restaurant owner',
birthday: '',
},
{
id: 14,
firstName: 'Mike',
lastName: 'Ehrmantraut',
occupation: 'Private Investigator',
birthday: '',
},
{
id: 15,
firstName: 'Walter',
lastName: 'White',
occupation: 'Chemistry teacher',
birthday: '09-07-1958',
},
{
id: 16,
firstName: 'Jesse',
lastName: 'Pinkman',
occupation: 'Dealer',
birthday: '09-24-1984',
},
{
id: 17,
firstName: 'Skyler',
lastName: 'White',
occupation: 'Bookkeeper',
birthday: '08-11-1970',
},
{
id: 18,
firstName: 'Saul',
lastName: 'Goodman',
occupation: 'Lawyer',
birthday: '',
},
{
id: 19,
firstName: 'Hank',
lastName: 'Schrader',
occupation: 'DEA Agent',
birthday: '',
},
{
id: 20,
firstName: 'Gus',
lastName: 'Fring',
occupation: 'Restaurant owner',
birthday: '',
},
{
id: 21,
firstName: 'Mike',
lastName: 'Ehrmantraut',
occupation: 'Private Investigator',
birthday: '',
},
];
const rows = [];

const pinnedRowsTop = [1, 20];
const pinnedRowsBottom = [3, 2];
function getRow() {
return {
id: randomId(),
name: randomTraderName(),
city: randomCity(),
username: randomUserName(),
email: randomEmail(),
age: randomInt(10, 80),
};
}

for (let i = 0; i < 10; i += 1) {
rows.push(getRow());
}

const rows = [];
const pinnedRows = {
top: [],
bottom: [],
top: [getRow(), getRow()],
bottom: [getRow()],
};

data.forEach((row) => {
if (pinnedRowsTop.includes(row.id)) {
pinnedRows.top.push(row);
} else if (pinnedRowsBottom.includes(row.id)) {
pinnedRows.bottom.push(row);
} else {
rows.push(row);
}
});

export default function RowPinning() {
return (
<div style={{ height: 500, width: '100%' }}>
<DataGridPro
columns={columns}
pinnedRows={pinnedRows}
rows={rows}
initialState={{
pinnedColumns: { left: ['id'], right: ['birthday'] },
pagination: {
pageSize: 10,
},
}}
pagination
rowsPerPageOptions={[5, 10]}
/>
<DataGridPro columns={columns} rows={rows} pinnedRows={pinnedRows} />
</div>
);
}
Loading

0 comments on commit 9d1b57c

Please sign in to comment.