-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[DataGrid] Row spanning #14124
Changes from 50 commits
Commits
Show all changes
56 commits
Select commit
Hold shift + click to select a range
5d31a72
[Data Grid] Row spanning POC
MBilalShafi 958808c
Fix a few issues
MBilalShafi 7894afa
Add basic keyboard navigation
MBilalShafi b5d7add
Add hook and initializer to other packages
MBilalShafi bbfad03
Some housekeeping
MBilalShafi 0c86f39
Remove planned flag
MBilalShafi 0880c1b
Add support for valueGetter
MBilalShafi c526ea6
Add rowSpanValueGetter to support exclusion from row spanning even wh…
MBilalShafi ed97a2d
Improve docs a bit
MBilalShafi c458c57
Add new feature flag
MBilalShafi c4dd3d7
Merge branch 'master' into row-spanning
MBilalShafi 51bc9d4
Fix column resize
MBilalShafi e2a4605
Add a couple of demos
MBilalShafi bf15c95
Some changes on the demos
MBilalShafi 427e61d
Update docs and add a new demo
MBilalShafi 7ddcc0a
Support keyboard navigation from column spanned cell to row spanned cell
MBilalShafi 5dfc6b7
Merge branch 'master' into row-spanning
MBilalShafi 7c8dfbc
Improvement
MBilalShafi 5a121b1
Lint
MBilalShafi d0944ae
Merge branch 'master' into row-spanning
MBilalShafi c169d6c
Refactor
MBilalShafi c85f2e7
Change an example
MBilalShafi 74419c4
Improve a demo
MBilalShafi 1a4bd79
Remove stray prop
MBilalShafi d40f448
Fix failing of getRow API method
MBilalShafi bfc5c84
Optimize performance - make it work on rendered subset of rows
MBilalShafi aabb50d
Avoid reacting to column-only context changes
MBilalShafi 31efb7c
Merge branch 'master' into row-spanning
MBilalShafi 089c214
Virtualization: Keep the spanned cell in the viewport on scroll down
MBilalShafi 967cde8
Add some initial tests
MBilalShafi dd5d95a
Ignore column context changes
MBilalShafi 230d04a
Fix keyboard navigation bug
MBilalShafi ef2bcf6
Fix rtl related tests
MBilalShafi 43fcacd
Merge branch 'master' into row-spanning
MBilalShafi d85fe94
Skip tests in jsdom
MBilalShafi e7cb855
Do some updates to demos
MBilalShafi 0d74c82
Address comments
MBilalShafi cc34911
Compute the row spanning state in initializer
MBilalShafi 157a993
Add detail panel toggle to skipped fields
MBilalShafi 9cb2253
Update docs
MBilalShafi ba514cc
Lint + refactor
MBilalShafi cacef0f
Fix test + refactor
MBilalShafi 1e6b50e
Make the behavior smooth with filtering
MBilalShafi a3005ab
Docs improvement
MBilalShafi a536d4a
Merge branch 'master' into row-spanning
MBilalShafi 14c3bcc
Merge branch 'master' into row-spanning
MBilalShafi dae11b7
Merge branch 'master' into row-spanning
MBilalShafi 72cccda
Add more tests
MBilalShafi e6ba91d
Update getting started
MBilalShafi f68b1ed
Skip JS dom test
MBilalShafi 4c9a218
Armin's code review comments addressed
MBilalShafi 085b108
Apply suggestions from code review
MBilalShafi fdcf26b
Move warning and rephrase
MBilalShafi 31b421e
CI
MBilalShafi 9408e2f
Update
MBilalShafi 7031634
Merge branch 'master' into row-spanning
MBilalShafi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,130 @@ | ||
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} | ||
density="compact" | ||
showCellVerticalBorder | ||
showColumnVerticalBorder | ||
disableRowSelectionOnClick | ||
unstable_rowSpanning={enabled} | ||
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, | ||
}, | ||
]; |
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,130 @@ | ||
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} | ||
density="compact" | ||
showCellVerticalBorder | ||
MBilalShafi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
showColumnVerticalBorder | ||
disableRowSelectionOnClick | ||
unstable_rowSpanning={enabled} | ||
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, | ||
}, | ||
]; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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?
If not, this suggestion makes sense to me.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 valuesConsider 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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.