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] Row spanning #14124

Merged
merged 56 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
5d31a72
[Data Grid] Row spanning POC
MBilalShafi Aug 6, 2024
958808c
Fix a few issues
MBilalShafi Aug 6, 2024
7894afa
Add basic keyboard navigation
MBilalShafi Aug 7, 2024
b5d7add
Add hook and initializer to other packages
MBilalShafi Aug 7, 2024
bbfad03
Some housekeeping
MBilalShafi Aug 7, 2024
0c86f39
Remove planned flag
MBilalShafi Aug 7, 2024
0880c1b
Add support for valueGetter
MBilalShafi Aug 7, 2024
c526ea6
Add rowSpanValueGetter to support exclusion from row spanning even wh…
MBilalShafi Aug 7, 2024
ed97a2d
Improve docs a bit
MBilalShafi Aug 7, 2024
c458c57
Add new feature flag
MBilalShafi Aug 19, 2024
c4dd3d7
Merge branch 'master' into row-spanning
MBilalShafi Aug 19, 2024
51bc9d4
Fix column resize
MBilalShafi Aug 19, 2024
e2a4605
Add a couple of demos
MBilalShafi Aug 20, 2024
bf15c95
Some changes on the demos
MBilalShafi Aug 20, 2024
427e61d
Update docs and add a new demo
MBilalShafi Aug 20, 2024
7ddcc0a
Support keyboard navigation from column spanned cell to row spanned cell
MBilalShafi Aug 20, 2024
5dfc6b7
Merge branch 'master' into row-spanning
MBilalShafi Aug 20, 2024
7c8dfbc
Improvement
MBilalShafi Aug 21, 2024
5a121b1
Lint
MBilalShafi Aug 21, 2024
d0944ae
Merge branch 'master' into row-spanning
MBilalShafi Aug 21, 2024
c169d6c
Refactor
MBilalShafi Aug 21, 2024
c85f2e7
Change an example
MBilalShafi Aug 21, 2024
74419c4
Improve a demo
MBilalShafi Aug 21, 2024
1a4bd79
Remove stray prop
MBilalShafi Aug 21, 2024
d40f448
Fix failing of getRow API method
MBilalShafi Aug 31, 2024
bfc5c84
Optimize performance - make it work on rendered subset of rows
MBilalShafi Sep 1, 2024
aabb50d
Avoid reacting to column-only context changes
MBilalShafi Sep 1, 2024
31efb7c
Merge branch 'master' into row-spanning
MBilalShafi Sep 2, 2024
089c214
Virtualization: Keep the spanned cell in the viewport on scroll down
MBilalShafi Sep 2, 2024
967cde8
Add some initial tests
MBilalShafi Sep 2, 2024
dd5d95a
Ignore column context changes
MBilalShafi Sep 2, 2024
230d04a
Fix keyboard navigation bug
MBilalShafi Sep 2, 2024
ef2bcf6
Fix rtl related tests
MBilalShafi Sep 3, 2024
43fcacd
Merge branch 'master' into row-spanning
MBilalShafi Sep 3, 2024
d85fe94
Skip tests in jsdom
MBilalShafi Sep 3, 2024
e7cb855
Do some updates to demos
MBilalShafi Sep 3, 2024
0d74c82
Address comments
MBilalShafi Sep 5, 2024
cc34911
Compute the row spanning state in initializer
MBilalShafi Sep 9, 2024
157a993
Add detail panel toggle to skipped fields
MBilalShafi Sep 9, 2024
9cb2253
Update docs
MBilalShafi Sep 9, 2024
ba514cc
Lint + refactor
MBilalShafi Sep 9, 2024
cacef0f
Fix test + refactor
MBilalShafi Sep 9, 2024
1e6b50e
Make the behavior smooth with filtering
MBilalShafi Sep 11, 2024
a3005ab
Docs improvement
MBilalShafi Sep 11, 2024
a536d4a
Merge branch 'master' into row-spanning
MBilalShafi Sep 11, 2024
14c3bcc
Merge branch 'master' into row-spanning
MBilalShafi Sep 16, 2024
dae11b7
Merge branch 'master' into row-spanning
MBilalShafi Sep 16, 2024
72cccda
Add more tests
MBilalShafi Sep 16, 2024
e6ba91d
Update getting started
MBilalShafi Sep 16, 2024
f68b1ed
Skip JS dom test
MBilalShafi Sep 16, 2024
4c9a218
Armin's code review comments addressed
MBilalShafi Sep 18, 2024
085b108
Apply suggestions from code review
MBilalShafi Sep 20, 2024
fdcf26b
Move warning and rephrase
MBilalShafi Sep 20, 2024
31b421e
CI
MBilalShafi Sep 20, 2024
9408e2f
Update
MBilalShafi Sep 20, 2024
7031634
Merge branch 'master' into row-spanning
MBilalShafi Sep 20, 2024
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
138 changes: 138 additions & 0 deletions docs/data/data-grid/row-spanning/RowSpanning.js
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering what the behavior should be with editing.

Should editing a cell that spans multiple rows update all the repeating values? It makes sense to me.
Although is not how colSpan behaves (example: https://stackblitz.com/edit/react-ucq5za?file=Demo.tsx).

What do you think @mui/xgrid ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand user expectations very well for this feature, but I was wondering if there is a case where users would want to change the value of individual cells that are part of a row span?

Should editing a cell that spans multiple rows update all the repeating values?

If not, this suggestion makes sense to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see use cases for both

  1. If you have structured data and you use rowspan to show value of the parent once for all rows, you would probably want to update all of them at once
  2. If we connected cells in a column for an age, then you probably don't want to update all of them at once

Copy link
Member Author

@MBilalShafi MBilalShafi Aug 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we connected cells in a column for an age, then you probably don't want to update all of them at once

I believe such rows shouldn't be spanned in the first place. I introduced a prop rowSpanValueGetter to allow excluding unwanted values from being spanned.

For example with age, as you mentioned, it could be the same yet belong to different person. So if we avoid spanning them, we could go with the assumption: editing a cell that spans multiple rows would update all the repeating values

Consider this example: https://deploy-preview-14124--material-ui-x.netlify.app/x/react-data-grid/row-spanning/#customizing-row-spanned-cells

George Floyd and Cynthia Duke are both 25 years old but rowSpanValueGetter is used to correctly span the values.

Does it make sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for our pretty automated feature, this gives enough initial control to cover both cases

Copy link
Member Author

@MBilalShafi MBilalShafi Aug 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After thinking more about this, I'm inclined to not go with this approach for now, mainly because it is a breaking behavioral change.

Currently, on every cell or row update, processRowUpdate prop gets fired once.

If we go with the suggested behavior, the processRowUpdate will get fired more than once each edit (depending on the impacted rows).

The current behavior might also be useful in some cases where the users intend to modify the spanned cells based on the values.

break-spanned-cells.mp4

And the column spanning works in a similar way too, so it should be fine for now.

We might wait for some user feedback around this before deciding to go with the suggested approach. And even if we decide to go with it, we do it at a major, to avoid breaking changes.

Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { DataGrid } from '@mui/x-data-grid';
import FormControlLabel from '@mui/material/FormControlLabel';
import Switch from '@mui/material/Switch';

export default function RowSpanning() {
const [enabled, setEnabled] = React.useState(true);

return (
<Box sx={{ width: '100%' }}>
<FormControlLabel
checked={enabled}
onChange={(event) => setEnabled(event.target.checked)}
control={<Switch />}
label="Enable row spanning"
/>
<Box sx={{ height: 300 }}>
<DataGrid
rows={rows}
columns={columns}
initialState={{
pagination: {
paginationModel: {
pageSize: 10,
},
},
}}
density="compact"
showCellVerticalBorder
pageSizeOptions={[10]}
disableRowSelectionOnClick
unstable_rowSpanning={enabled}
disableVirtualization
hideFooter
sx={{
'& .MuiDataGrid-row:hover': {
backgroundColor: 'transparent',
},
'& .bold': {
fontWeight: 'bold',
},
}}
/>
</Box>
</Box>
);
}

const columns = [
{
field: 'code',
headerName: 'Item Code',
width: 85,
cellClassName: ({ row }) => (row.summaryRow ? 'bold' : ''),
},
{
field: 'description',
headerName: 'Description',
width: 170,
},
{
field: 'quantity',
headerName: 'Quantity',
width: 80,
// Do not span the values
rowSpanValueGetter: () => null,
},
{
field: 'unitPrice',
headerName: 'Unit Price',
type: 'number',
valueFormatter: (value) => (value ? `$${value}.00` : ''),
},
{
field: 'totalPrice',
headerName: 'Total Price',
type: 'number',
valueGetter: (value, row) => value ?? row?.unitPrice,
valueFormatter: (value) => `$${value}.00`,
cellClassName: ({ row }) => (row.summaryRow ? 'bold' : ''),
},
];

const rows = [
{
id: 1,
code: 'A101',
description: 'Wireless Mouse',
quantity: 2,
unitPrice: 50,
totalPrice: 100,
},
{
id: 2,
code: 'A102',
description: 'Mechanical Keyboard',
quantity: 1,
unitPrice: 75,
},
{
id: 3,
code: 'A103',
description: 'USB Dock Station',
quantity: 1,
unitPrice: 400,
},
{
id: 4,
code: 'A104',
description: 'Laptop',
quantity: 1,
unitPrice: 1800,
totalPrice: 2050,
},
{
id: 5,
code: 'A104',
description: '- 16GB RAM Upgrade',
quantity: 1,
unitPrice: 100,
totalPrice: 2050,
},
{
id: 6,
code: 'A104',
description: '- 512GB SSD Upgrade',
quantity: 1,
unitPrice: 150,
totalPrice: 2050,
},
{
id: 7,
code: 'TOTAL',
totalPrice: 2625,
summaryRow: true,
},
];
138 changes: 138 additions & 0 deletions docs/data/data-grid/row-spanning/RowSpanning.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import { DataGrid, GridColDef } from '@mui/x-data-grid';
import FormControlLabel from '@mui/material/FormControlLabel';
import Switch from '@mui/material/Switch';

export default function RowSpanning() {
const [enabled, setEnabled] = React.useState(true);

return (
<Box sx={{ width: '100%' }}>
<FormControlLabel
checked={enabled}
onChange={(event) => setEnabled((event.target as HTMLInputElement).checked)}
control={<Switch />}
label="Enable row spanning"
/>
<Box sx={{ height: 300 }}>
<DataGrid
rows={rows}
columns={columns}
initialState={{
pagination: {
paginationModel: {
pageSize: 10,
},
},
}}
density="compact"
showCellVerticalBorder
MBilalShafi marked this conversation as resolved.
Show resolved Hide resolved
pageSizeOptions={[10]}
disableRowSelectionOnClick
unstable_rowSpanning={enabled}
disableVirtualization
hideFooter
sx={{
'& .MuiDataGrid-row:hover': {
backgroundColor: 'transparent',
},
'& .bold': {
fontWeight: 'bold',
},
}}
/>
</Box>
</Box>
);
}

const columns: GridColDef<(typeof rows)[number]>[] = [
{
field: 'code',
headerName: 'Item Code',
width: 85,
cellClassName: ({ row }) => (row.summaryRow ? 'bold' : ''),
},
{
field: 'description',
headerName: 'Description',
width: 170,
},
{
field: 'quantity',
headerName: 'Quantity',
width: 80,
// Do not span the values
rowSpanValueGetter: () => null,
},
{
field: 'unitPrice',
headerName: 'Unit Price',
type: 'number',
valueFormatter: (value) => (value ? `$${value}.00` : ''),
},
{
field: 'totalPrice',
headerName: 'Total Price',
type: 'number',
valueGetter: (value, row) => value ?? row?.unitPrice,
valueFormatter: (value) => `$${value}.00`,
cellClassName: ({ row }) => (row.summaryRow ? 'bold' : ''),
},
];

const rows = [
{
id: 1,
code: 'A101',
description: 'Wireless Mouse',
quantity: 2,
unitPrice: 50,
totalPrice: 100,
},
{
id: 2,
code: 'A102',
description: 'Mechanical Keyboard',
quantity: 1,
unitPrice: 75,
},
{
id: 3,
code: 'A103',
description: 'USB Dock Station',
quantity: 1,
unitPrice: 400,
},
{
id: 4,
code: 'A104',
description: 'Laptop',
quantity: 1,
unitPrice: 1800,
totalPrice: 2050,
},
{
id: 5,
code: 'A104',
description: '- 16GB RAM Upgrade',
quantity: 1,
unitPrice: 100,
totalPrice: 2050,
},
{
id: 6,
code: 'A104',
description: '- 512GB SSD Upgrade',
quantity: 1,
unitPrice: 150,
totalPrice: 2050,
},
{
id: 7,
code: 'TOTAL',
totalPrice: 2625,
summaryRow: true,
},
];
Loading
Loading