-
-
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 8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import { DataGrid } from '@mui/x-data-grid'; | ||
|
||
export default function RowSpanning() { | ||
return ( | ||
<Box sx={{ height: 400, width: '100%' }}> | ||
<DataGrid | ||
rows={rows} | ||
columns={columns} | ||
initialState={{ | ||
pagination: { | ||
paginationModel: { | ||
pageSize: 10, | ||
}, | ||
}, | ||
}} | ||
showCellVerticalBorder | ||
pageSizeOptions={[10]} | ||
disableRowSelectionOnClick | ||
unstable_rowSpanning | ||
disableVirtualization | ||
sx={{ | ||
'& .MuiDataGrid-row.Mui-hovered': { | ||
backgroundColor: 'transparent', | ||
}, | ||
'& .MuiDataGrid-row:hover': { | ||
backgroundColor: 'transparent', | ||
}, | ||
}} | ||
/> | ||
</Box> | ||
); | ||
} | ||
|
||
const columns = [ | ||
{ | ||
field: 'event', | ||
headerName: 'Event', | ||
width: 200, | ||
editable: true, | ||
}, | ||
{ | ||
field: 'indicator', | ||
headerName: 'Indicator', | ||
width: 150, | ||
editable: true, | ||
}, | ||
{ | ||
field: 'action', | ||
headerName: 'Action', | ||
width: 150, | ||
editable: true, | ||
}, | ||
{ | ||
field: 'decision', | ||
headerName: 'Decision', | ||
type: 'number', | ||
width: 100, | ||
}, | ||
{ | ||
field: 'location', | ||
headerName: 'Location', | ||
type: 'number', | ||
width: 100, | ||
rowSpanValueGetter: () => { | ||
// Exclude this column from row spanning irrespective of the values | ||
return undefined; | ||
}, | ||
}, | ||
]; | ||
|
||
const rows = [ | ||
{ | ||
id: 1, | ||
event: 'Event 1', | ||
indicator: 'Indicator 1', | ||
action: 'Actions 1', | ||
decision: 1, | ||
location: 2, | ||
}, | ||
{ | ||
id: 2, | ||
event: 'Event 1', | ||
indicator: 'Indicator 1', | ||
action: 'Actions 2', | ||
decision: 1, | ||
location: 3, | ||
}, | ||
{ | ||
id: 3, | ||
event: 'Event 1', | ||
indicator: 'Indicator 1', | ||
action: 'Actions 3', | ||
decision: 1, | ||
location: 1, | ||
}, | ||
{ | ||
id: 4, | ||
event: 'Event 1', | ||
indicator: 'Indicator 2', | ||
action: 'Actions 1', | ||
decision: 4, | ||
location: 3, | ||
}, | ||
{ | ||
id: 5, | ||
event: 'Event 1', | ||
indicator: 'Indicator 2', | ||
action: 'Actions 2', | ||
decision: 4, | ||
location: 3, | ||
}, | ||
{ | ||
id: 6, | ||
event: 'Event 2', | ||
indicator: 'Indicator 1', | ||
action: 'Actions 1', | ||
decision: 6, | ||
location: 1, | ||
}, | ||
{ | ||
id: 7, | ||
event: 'Event 2', | ||
indicator: 'Indicator 1', | ||
action: 'Actions 2', | ||
decision: 6, | ||
location: 2, | ||
}, | ||
{ | ||
id: 8, | ||
event: 'Event 2', | ||
indicator: 'Indicator 1', | ||
action: 'Actions 3', | ||
decision: 6, | ||
location: 2, | ||
}, | ||
{ | ||
id: 9, | ||
event: 'Event 2', | ||
indicator: 'Indicator 2', | ||
action: 'Actions 1', | ||
decision: 9, | ||
location: 1, | ||
}, | ||
{ | ||
id: 10, | ||
event: 'Event 2', | ||
indicator: 'Indicator 2', | ||
action: 'Actions 2', | ||
decision: 9, | ||
location: 4, | ||
}, | ||
{ | ||
id: 11, | ||
event: 'Event 3', | ||
indicator: 'Indicator 1', | ||
action: 'Actions 1', | ||
decision: 11, | ||
location: 1, | ||
}, | ||
{ | ||
id: 12, | ||
event: 'Event 3', | ||
indicator: 'Indicator 1', | ||
action: 'Actions 2', | ||
decision: 11, | ||
location: 1, | ||
}, | ||
{ | ||
id: 13, | ||
event: 'Event 3', | ||
indicator: 'Indicator 1', | ||
action: 'Actions 3', | ||
decision: 11, | ||
location: 2, | ||
}, | ||
{ | ||
id: 14, | ||
event: 'Event 3', | ||
indicator: 'Indicator 2', | ||
action: 'Actions 1', | ||
decision: 14, | ||
location: 4, | ||
}, | ||
{ | ||
id: 15, | ||
event: 'Event 3', | ||
indicator: 'Indicator 2', | ||
action: 'Actions 2', | ||
decision: 14, | ||
location: 3, | ||
}, | ||
]; |
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,194 @@ | ||
import * as React from 'react'; | ||
import Box from '@mui/material/Box'; | ||
import { DataGrid, GridColDef } from '@mui/x-data-grid'; | ||
|
||
export default function RowSpanning() { | ||
return ( | ||
<Box sx={{ height: 400, width: '100%' }}> | ||
<DataGrid | ||
rows={rows} | ||
columns={columns} | ||
initialState={{ | ||
pagination: { | ||
paginationModel: { | ||
pageSize: 10, | ||
}, | ||
}, | ||
}} | ||
showCellVerticalBorder | ||
pageSizeOptions={[10]} | ||
disableRowSelectionOnClick | ||
unstable_rowSpanning | ||
disableVirtualization | ||
sx={{ | ||
'& .MuiDataGrid-row.Mui-hovered': { | ||
backgroundColor: 'transparent', | ||
}, | ||
'& .MuiDataGrid-row:hover': { | ||
backgroundColor: 'transparent', | ||
}, | ||
}} | ||
/> | ||
</Box> | ||
); | ||
} | ||
|
||
const columns: GridColDef<(typeof rows)[number]>[] = [ | ||
{ | ||
field: 'event', | ||
headerName: 'Event', | ||
width: 200, | ||
editable: true, | ||
}, | ||
{ | ||
field: 'indicator', | ||
headerName: 'Indicator', | ||
width: 150, | ||
editable: true, | ||
}, | ||
{ | ||
field: 'action', | ||
headerName: 'Action', | ||
width: 150, | ||
editable: true, | ||
}, | ||
{ | ||
field: 'decision', | ||
headerName: 'Decision', | ||
type: 'number', | ||
width: 100, | ||
}, | ||
{ | ||
field: 'location', | ||
headerName: 'Location', | ||
type: 'number', | ||
width: 100, | ||
rowSpanValueGetter: () => { | ||
// Exclude this column from row spanning irrespective of the values | ||
return undefined; | ||
}, | ||
}, | ||
]; | ||
|
||
const rows = [ | ||
{ | ||
id: 1, | ||
event: 'Event 1', | ||
indicator: 'Indicator 1', | ||
action: 'Actions 1', | ||
decision: 1, | ||
location: 2, | ||
}, | ||
{ | ||
id: 2, | ||
event: 'Event 1', | ||
indicator: 'Indicator 1', | ||
action: 'Actions 2', | ||
decision: 1, | ||
location: 3, | ||
}, | ||
{ | ||
id: 3, | ||
event: 'Event 1', | ||
indicator: 'Indicator 1', | ||
action: 'Actions 3', | ||
decision: 1, | ||
location: 1, | ||
}, | ||
{ | ||
id: 4, | ||
event: 'Event 1', | ||
indicator: 'Indicator 2', | ||
action: 'Actions 1', | ||
decision: 4, | ||
location: 3, | ||
}, | ||
{ | ||
id: 5, | ||
event: 'Event 1', | ||
indicator: 'Indicator 2', | ||
action: 'Actions 2', | ||
decision: 4, | ||
location: 3, | ||
}, | ||
{ | ||
id: 6, | ||
event: 'Event 2', | ||
indicator: 'Indicator 1', | ||
action: 'Actions 1', | ||
decision: 6, | ||
location: 1, | ||
}, | ||
{ | ||
id: 7, | ||
event: 'Event 2', | ||
indicator: 'Indicator 1', | ||
action: 'Actions 2', | ||
decision: 6, | ||
location: 2, | ||
}, | ||
{ | ||
id: 8, | ||
event: 'Event 2', | ||
indicator: 'Indicator 1', | ||
action: 'Actions 3', | ||
decision: 6, | ||
location: 2, | ||
}, | ||
{ | ||
id: 9, | ||
event: 'Event 2', | ||
indicator: 'Indicator 2', | ||
action: 'Actions 1', | ||
decision: 9, | ||
location: 1, | ||
}, | ||
{ | ||
id: 10, | ||
event: 'Event 2', | ||
indicator: 'Indicator 2', | ||
action: 'Actions 2', | ||
decision: 9, | ||
location: 4, | ||
}, | ||
{ | ||
id: 11, | ||
event: 'Event 3', | ||
indicator: 'Indicator 1', | ||
action: 'Actions 1', | ||
decision: 11, | ||
location: 1, | ||
}, | ||
{ | ||
id: 12, | ||
event: 'Event 3', | ||
indicator: 'Indicator 1', | ||
action: 'Actions 2', | ||
decision: 11, | ||
location: 1, | ||
}, | ||
{ | ||
id: 13, | ||
event: 'Event 3', | ||
indicator: 'Indicator 1', | ||
action: 'Actions 3', | ||
decision: 11, | ||
location: 2, | ||
}, | ||
{ | ||
id: 14, | ||
event: 'Event 3', | ||
indicator: 'Indicator 2', | ||
action: 'Actions 1', | ||
decision: 14, | ||
location: 4, | ||
}, | ||
{ | ||
id: 15, | ||
event: 'Event 3', | ||
indicator: 'Indicator 2', | ||
action: 'Actions 2', | ||
decision: 14, | ||
location: 3, | ||
}, | ||
]; |
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.