Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DataGrid] Column spanning #4020

Merged
merged 42 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
e32e825
implement column spanning
cherniavskii Mar 17, 2022
bfda437
pass aria-colspan to Cell directly
cherniavskii Mar 18, 2022
1fc6eed
perf: get rid of expensive Array.include
cherniavskii Mar 18, 2022
44d3ae2
rename `collapsedByColSpan`
cherniavskii Mar 18, 2022
5e99ac6
improve readability
cherniavskii Mar 18, 2022
78bb8a4
perf: get rid of expensive Array.slice
cherniavskii Mar 18, 2022
bfd1ed1
rename column spanning api type
cherniavskii Mar 18, 2022
478718a
get rid of Array.slice
cherniavskii Mar 18, 2022
0f5551a
fix jsdoc
cherniavskii Mar 21, 2022
7f9806d
do not use data-attributes to query cells for column resizing
cherniavskii Mar 21, 2022
299693a
Merge branch 'master' into column-spanning
cherniavskii Mar 21, 2022
fcb3cfd
Merge branch 'master' into column-spanning
cherniavskii Mar 22, 2022
aa01afb
return early if colSpan === 1
cherniavskii Mar 22, 2022
cb66205
do not pass `cellParams` to `calculateCellColSpan`
cherniavskii Mar 22, 2022
7b3b63c
do not pass `colSpan` attribute to GridCell div element
cherniavskii Mar 22, 2022
9bc8d89
update docs
cherniavskii Mar 22, 2022
b03d63e
use getFirstNonSpannedColumnToRender directly
cherniavskii Mar 23, 2022
aa8a2c8
improve ColumnSpanningDerived demo
cherniavskii Mar 23, 2022
93f2c9c
Merge branch 'master' into column-spanning
cherniavskii Mar 23, 2022
f96fbb5
update js demo
cherniavskii Mar 23, 2022
dad062b
update warning on colSpan in combination with other features
cherniavskii Mar 24, 2022
6d197d0
Merge branch 'master' into column-spanning
cherniavskii Mar 25, 2022
9a6b959
Merge branch 'master' into column-spanning
cherniavskii Apr 4, 2022
b142999
build api docs
cherniavskii Apr 4, 2022
a53c5e2
make break slot empty
cherniavskii Apr 4, 2022
d25aeda
remove console logs
cherniavskii Apr 4, 2022
43e2020
add failing unit test
cherniavskii Apr 4, 2022
ac54ad3
fix failing test
cherniavskii Apr 4, 2022
fe1246f
Merge branch 'master' into column-spanning
cherniavskii Apr 11, 2022
d3d0aff
use generics in colSpan
cherniavskii Apr 11, 2022
af9f0e3
fix ts errors
cherniavskii Apr 11, 2022
9311848
build api docs
cherniavskii Apr 11, 2022
ab689f2
update feature comparison
cherniavskii Apr 11, 2022
d0928f0
Merge branch 'master' into column-spanning
cherniavskii Apr 11, 2022
52819bd
update docs
cherniavskii Apr 11, 2022
6cb1a46
update docs
cherniavskii Apr 11, 2022
dd2c728
Merge branch 'master' into column-spanning
cherniavskii Apr 11, 2022
2236beb
disable some features in colSpan demos
cherniavskii Apr 11, 2022
d9b8565
code review fixes
cherniavskii Apr 11, 2022
b782aeb
reuse `rowId` variable
cherniavskii Apr 11, 2022
b5e50d1
get rid of document.activeElement in tests
cherniavskii Apr 11, 2022
919cffb
Merge branch 'master' into column-spanning
cherniavskii Apr 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 182 additions & 0 deletions docs/data/data-grid/columns/ColumnSpanningDerived.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { DataGridPro } from '@mui/x-data-grid-pro';

const slotTimesLookup = {
0: '09:00 - 10:00',
1: '10:00 - 11:00',
2: '11:00 - 12:00',
3: '12:00 - 13:00',
4: '13:00 - 14:00',
5: '14:00 - 15:00',
6: '15:00 - 16:00',
7: '16:00 - 17:00',
};

const rows = [
{
id: 1,
day: 'Monday',
slots: ['Maths', 'English', 'English', 'Lab', '', 'Lab', 'Music', 'Music'],
},
{
id: 2,
day: 'Tuesday',
slots: [
'Chemistry',
'Chemistry',
'Chemistry',
'Physics',
'',
'Maths',
'Lab',
'Dance',
],
},
{
id: 3,
day: 'Wednesday',
slots: ['Physics', 'English', 'Maths', 'Maths', '', 'Chemistry', 'Chemistry'],
},
{
id: 4,
day: 'Thursday',
slots: [
'Music',
'Music',
'Chemistry',
'Chemistry',
'',
'Chemistry',
'English',
'English',
],
},
{
id: 5,
day: 'Friday',
slots: ['Maths', 'Dance', 'Dance', 'Physics', '', 'English'],
},
];

const slotColumnCommonFields = {
sortable: false,
filterable: false,
minWidth: 140,
cellClassName: (params) => params.value,
colSpan: ({ row, field, value }) => {
const index = Number(field);
let colSpan = 1;
for (let i = index + 1; i < row.slots.length; i += 1) {
const nextValue = row.slots[i];
if (nextValue === value) {
colSpan += 1;
} else {
break;
}
}
return colSpan;
},
};

const columns = [
{
field: 'day',
headerName: 'Day',
},
{
field: '0',
headerName: slotTimesLookup[0],
valueGetter: ({ row }) => row.slots[0],
...slotColumnCommonFields,
},
{
field: '1',
headerName: slotTimesLookup[1],
valueGetter: ({ row }) => row.slots[1],
...slotColumnCommonFields,
},
{
field: '2',
headerName: slotTimesLookup[2],
valueGetter: ({ row }) => row.slots[2],
...slotColumnCommonFields,
},
{
field: '3',
headerName: slotTimesLookup[3],
valueGetter: ({ row }) => row.slots[3],
...slotColumnCommonFields,
},
{
field: '4',
headerName: slotTimesLookup[4],
valueGetter: ({ row }) => row.slots[4],
...slotColumnCommonFields,
},
{
field: '5',
headerName: slotTimesLookup[5],
valueGetter: ({ row }) => row.slots[5],
...slotColumnCommonFields,
},
{
field: '6',
headerName: slotTimesLookup[6],
valueGetter: ({ row }) => row.slots[6],
...slotColumnCommonFields,
},
{
field: '7',
headerName: slotTimesLookup[7],
valueGetter: ({ row }) => row.slots[7],
...slotColumnCommonFields,
},
];

const rootStyles = {
width: '100%',
'& .Maths': {
backgroundColor: 'rgba(157, 255, 118, 0.49)',
},
'& .English': {
backgroundColor: 'rgba(255, 255, 10, 0.49)',
},
'& .Lab': {
backgroundColor: 'rgba(150, 150, 150, 0.49)',
},
'& .Chemistry': {
backgroundColor: 'rgba(255, 150, 150, 0.49)',
},
'& .Physics': {
backgroundColor: 'rgba(10, 150, 255, 0.49)',
},
'& .Music': {
backgroundColor: 'rgba(224, 183, 60, 0.55)',
},
'& .Dance': {
backgroundColor: 'rgba(200, 150, 255, 0.49)',
},
};

export default function ColumnSpanningDerived() {
return (
<Box sx={rootStyles}>
<DataGridPro
columns={columns}
rows={rows}
initialState={{
pinnedColumns: {
left: ['day'],
},
}}
autoHeight
disableExtendRowFullWidth
disableSelectionOnClick
hideFooter
showCellRightBorder
showColumnRightBorder
/>
</Box>
);
}
191 changes: 191 additions & 0 deletions docs/data/data-grid/columns/ColumnSpanningDerived.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { DataGridPro, GridColDef, GridCellParams } from '@mui/x-data-grid-pro';

const slotTimesLookup = {
0: '09:00 - 10:00',
1: '10:00 - 11:00',
2: '11:00 - 12:00',
3: '12:00 - 13:00',
4: '13:00 - 14:00',
5: '14:00 - 15:00',
6: '15:00 - 16:00',
7: '16:00 - 17:00',
};

type Subject =
| 'Maths'
| 'English'
| 'Lab'
| 'Chemistry'
| 'Physics'
| 'Music'
| 'Dance';

const rows: Array<{ id: number; day: string; slots: Array<Subject | ''> }> = [
{
id: 1,
day: 'Monday',
slots: ['Maths', 'English', 'English', 'Lab', '', 'Lab', 'Music', 'Music'],
},
{
id: 2,
day: 'Tuesday',
slots: [
'Chemistry',
'Chemistry',
'Chemistry',
'Physics',
'',
'Maths',
'Lab',
'Dance',
],
},
{
id: 3,
day: 'Wednesday',
slots: ['Physics', 'English', 'Maths', 'Maths', '', 'Chemistry', 'Chemistry'],
},
{
id: 4,
day: 'Thursday',
slots: [
'Music',
'Music',
'Chemistry',
'Chemistry',
'',
'Chemistry',
'English',
'English',
],
},
{
id: 5,
day: 'Friday',
slots: ['Maths', 'Dance', 'Dance', 'Physics', '', 'English'],
},
];

const slotColumnCommonFields: Partial<GridColDef> = {
sortable: false,
filterable: false,
minWidth: 140,
cellClassName: (params: GridCellParams) => params.value,
colSpan: ({ row, field, value }: GridCellParams) => {
const index = Number(field);
let colSpan = 1;
for (let i = index + 1; i < row.slots.length; i += 1) {
const nextValue = row.slots[i];
if (nextValue === value) {
colSpan += 1;
} else {
break;
}
}
return colSpan;
},
};

const columns: GridColDef[] = [
{
field: 'day',
headerName: 'Day',
},
{
field: '0',
headerName: slotTimesLookup[0],
valueGetter: ({ row }) => row.slots[0],
...slotColumnCommonFields,
},
{
field: '1',
headerName: slotTimesLookup[1],
valueGetter: ({ row }) => row.slots[1],
...slotColumnCommonFields,
},
{
field: '2',
headerName: slotTimesLookup[2],
valueGetter: ({ row }) => row.slots[2],
...slotColumnCommonFields,
},
{
field: '3',
headerName: slotTimesLookup[3],
valueGetter: ({ row }) => row.slots[3],
...slotColumnCommonFields,
},
{
field: '4',
headerName: slotTimesLookup[4],
valueGetter: ({ row }) => row.slots[4],
...slotColumnCommonFields,
},
{
field: '5',
headerName: slotTimesLookup[5],
valueGetter: ({ row }) => row.slots[5],
...slotColumnCommonFields,
},
{
field: '6',
headerName: slotTimesLookup[6],
valueGetter: ({ row }) => row.slots[6],
...slotColumnCommonFields,
},
{
field: '7',
headerName: slotTimesLookup[7],
valueGetter: ({ row }) => row.slots[7],
...slotColumnCommonFields,
},
];

const rootStyles = {
width: '100%',
'& .Maths': {
backgroundColor: 'rgba(157, 255, 118, 0.49)',
},
'& .English': {
backgroundColor: 'rgba(255, 255, 10, 0.49)',
},
'& .Lab': {
backgroundColor: 'rgba(150, 150, 150, 0.49)',
},
'& .Chemistry': {
backgroundColor: 'rgba(255, 150, 150, 0.49)',
},
'& .Physics': {
backgroundColor: 'rgba(10, 150, 255, 0.49)',
},
'& .Music': {
backgroundColor: 'rgba(224, 183, 60, 0.55)',
},
'& .Dance': {
backgroundColor: 'rgba(200, 150, 255, 0.49)',
},
};

export default function ColumnSpanningDerived() {
cherniavskii marked this conversation as resolved.
Show resolved Hide resolved
return (
<Box sx={rootStyles}>
<DataGridPro
columns={columns}
rows={rows}
initialState={{
pinnedColumns: {
left: ['day'],
},
}}
autoHeight
disableExtendRowFullWidth
disableSelectionOnClick
hideFooter
showCellRightBorder
showColumnRightBorder
/>
</Box>
);
}
15 changes: 15 additions & 0 deletions docs/data/data-grid/columns/ColumnSpanningDerived.tsx.preview
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<DataGridPro
columns={columns}
rows={rows}
initialState={{
pinnedColumns: {
left: ['day'],
},
}}
autoHeight
disableExtendRowFullWidth
disableSelectionOnClick
hideFooter
showCellRightBorder
showColumnRightBorder
/>
Loading