-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[DataGridPro] Tree data row reordering #19401
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
Open
MBilalShafi
wants to merge
71
commits into
mui:master
Choose a base branch
from
MBilalShafi:tree-data-row-grouping
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,693
−569
Open
Changes from all commits
Commits
Show all changes
71 commits
Select commit
Hold shift + click to select a range
1fb9dc2
Extract reusable stuff to Pro package
MBilalShafi e2c0928
Initial stub for treeDataReorderValidator
MBilalShafi 01d7ef9
Add a demo
MBilalShafi 1e4a820
Support same parent reordering (simple use case)
MBilalShafi a92b8a0
Merge branch 'master' into tree-data-row-grouping
MBilalShafi cd6a63e
Update the demo to 2 levels
MBilalShafi 319d5e8
Remove irrelevant validation cases
MBilalShafi edf71dc
Updates
MBilalShafi eedddb0
Add setTreeDataPath() prop
MBilalShafi 92be312
Implement cross parent leaf operation
MBilalShafi 119b90b
Add CrossParentGroupOperation
MBilalShafi b4a1b04
Merge branch 'master' into tree-data-row-grouping
MBilalShafi a32cff2
Merge branch 'master' into tree-data-row-grouping
MBilalShafi 2a69d6b
Add 'over' position and move the drop indicator to overlay
MBilalShafi 4136ed4
Revert to the pseudo element approach
MBilalShafi 8edd70f
Allow executor to access dropPosition
MBilalShafi 099ebc7
✨ Add drop on leaf use-case
MBilalShafi b9df30b
💬 Some formatting
MBilalShafi 8669fe4
🎋 Allow to expand tree data rows at any nested level by hovering + im…
MBilalShafi 71174e9
Add isRowOrderable
MBilalShafi cc547e7
➕ Introduce isValidRowReorder prop
MBilalShafi 4ea0c3c
Merge branch 'master' into tree-data-row-grouping
MBilalShafi b36a709
Fix circular dependency
MBilalShafi c6d8874
Regenerate docs
MBilalShafi e50a2c2
Add missing props
MBilalShafi 2b3b53c
Improve docs
MBilalShafi 4bb3b57
Fix flickering during dragOver
MBilalShafi becedc5
Remove possibility to drop a group on one of it's own descendants
MBilalShafi 7546e11
Update isValidRowReorder to respect internal validation boundaries
MBilalShafi 7d2aa25
Update demo
MBilalShafi 8ce8c91
Wait for async operations to complete before publishing event
MBilalShafi 51479a2
Lint
MBilalShafi 48e21db
Use proper methods for all the use-cases, irrespective of package
MBilalShafi cb2ec34
Widen the grid configuration types a bit
MBilalShafi 667fae4
Cleanup
MBilalShafi 4d50c07
Export public types
MBilalShafi 2237538
Add a couple docs' sections
MBilalShafi 33d2b32
Merge branch 'master' into tree-data-row-grouping
MBilalShafi 6fc3662
docs:api
MBilalShafi cba173a
Generate proper signature in API documentation
MBilalShafi e2a6040
Minor docs update
MBilalShafi 1c871e8
Add test coverage
MBilalShafi d814eae
Merge branch 'master' into tree-data-row-grouping
MBilalShafi 180deac
Add a selector
MBilalShafi ddb778f
Add a demo to sync with external rows object
MBilalShafi ac37fe4
docs:api
MBilalShafi 1a5b2e3
Fix a few breaking tests
MBilalShafi e8db417
Fix more tests
MBilalShafi f44ddb1
Fix: Lint
MBilalShafi 633d121
Improve tests
MBilalShafi e8831a5
Merge remote-tracking branch 'upstream/master' into tree-data-row-gro…
MBilalShafi 957db89
Merge remote-tracking branch 'upstream/master' into tree-data-row-gro…
MBilalShafi 0c379a4
Merge branch 'master' into tree-data-row-grouping
MBilalShafi 3aa1ce7
Merge branch 'master' into tree-data-row-grouping
MBilalShafi 922b1c9
Remove the hack thanks to #19697
MBilalShafi 9a9fd0e
Improve docs
MBilalShafi dc6022b
Apply suggestion from @arminmeh
MBilalShafi 747ab9c
Apply suggestion from @siriwatknp
MBilalShafi 70eddf5
Apply suggestion from @arminmeh
MBilalShafi 5e3a4af
remove unused imports
arminmeh 7581156
Finish todo
arminmeh eaa8ff9
Merge branch 'master' into tree-data-row-grouping
MBilalShafi 3edcca9
Docs improvements
MBilalShafi a65a901
Make the demo use 'Tree data'
MBilalShafi f27b224
Update heading
MBilalShafi 33086af
A few updates on tests
MBilalShafi 7122b37
Test updates
MBilalShafi 118d9bb
Simplify await calls
MBilalShafi fd6f65d
Cleanup unused classes
MBilalShafi 7607b63
Cleanup outdated test
MBilalShafi e8ce355
Clean up a couple conditions
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 hidden or 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,26 @@ | ||
import * as React from 'react'; | ||
import { DataGridPro } from '@mui/x-data-grid-pro'; | ||
import { useDemoData } from '@mui/x-data-grid-generator'; | ||
|
||
const isRowReorderable = (params) => { | ||
return params.row.quantity < 50000; | ||
}; | ||
|
||
export default function RowReorderingDisabled() { | ||
const { data, loading } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 20, | ||
maxColumns: 20, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGridPro | ||
{...data} | ||
loading={loading} | ||
rowReordering | ||
isRowReorderable={isRowReorderable} | ||
/> | ||
</div> | ||
); | ||
} |
26 changes: 26 additions & 0 deletions
26
docs/data/data-grid/row-ordering/RowReorderingDisabled.tsx
This file contains hidden or 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,26 @@ | ||
import * as React from 'react'; | ||
import { DataGridPro, type IsRowReorderableParams } from '@mui/x-data-grid-pro'; | ||
import { useDemoData } from '@mui/x-data-grid-generator'; | ||
|
||
const isRowReorderable = (params: IsRowReorderableParams) => { | ||
return params.row.quantity < 50000; | ||
}; | ||
|
||
export default function RowReorderingDisabled() { | ||
const { data, loading } = useDemoData({ | ||
dataSet: 'Commodity', | ||
rowLength: 20, | ||
maxColumns: 20, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGridPro | ||
{...data} | ||
loading={loading} | ||
rowReordering | ||
isRowReorderable={isRowReorderable} | ||
/> | ||
</div> | ||
); | ||
} |
6 changes: 6 additions & 0 deletions
6
docs/data/data-grid/row-ordering/RowReorderingDisabled.tsx.preview
This file contains hidden or 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,6 @@ | ||
<DataGridPro | ||
{...data} | ||
loading={loading} | ||
rowReordering | ||
isRowReorderable={isRowReorderable} | ||
/> |
42 changes: 42 additions & 0 deletions
42
docs/data/data-grid/row-ordering/RowReorderingValidation.js
This file contains hidden or 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,42 @@ | ||
import * as React from 'react'; | ||
import { DataGridPro } from '@mui/x-data-grid-pro'; | ||
import { useDemoData } from '@mui/x-data-grid-generator'; | ||
|
||
const isValidRowReorder = (context) => { | ||
if (context.sourceNode.type === 'group') { | ||
return true; | ||
} | ||
if (context.targetNode.type === 'leaf') { | ||
return context.sourceNode.parent !== context.targetNode.parent; | ||
} | ||
return false; | ||
}; | ||
|
||
const getTreeDataPath = (row) => { | ||
return row.path; | ||
}; | ||
|
||
const setTreeDataPath = (path, row) => { | ||
return { ...row, path }; | ||
}; | ||
|
||
export default function RowReorderingValidation() { | ||
const { data, loading } = useDemoData({ | ||
dataSet: 'Employee', | ||
rowLength: 100, | ||
treeData: { maxDepth: 2, groupingField: 'name', averageChildren: 4 }, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGridPro | ||
{...data} | ||
setTreeDataPath={setTreeDataPath} | ||
getTreeDataPath={getTreeDataPath} | ||
loading={loading} | ||
rowReordering | ||
isValidRowReorder={isValidRowReorder} | ||
/> | ||
</div> | ||
); | ||
} |
46 changes: 46 additions & 0 deletions
46
docs/data/data-grid/row-ordering/RowReorderingValidation.tsx
This file contains hidden or 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,46 @@ | ||
import * as React from 'react'; | ||
import { | ||
DataGridPro, | ||
GridValidRowModel, | ||
ReorderValidationContext, | ||
} from '@mui/x-data-grid-pro'; | ||
import { useDemoData } from '@mui/x-data-grid-generator'; | ||
|
||
const isValidRowReorder = (context: ReorderValidationContext) => { | ||
if (context.sourceNode.type === 'group') { | ||
return true; | ||
} | ||
if (context.targetNode.type === 'leaf') { | ||
return context.sourceNode.parent !== context.targetNode.parent; | ||
} | ||
return false; | ||
}; | ||
|
||
const getTreeDataPath = (row: GridValidRowModel) => { | ||
return row.path; | ||
}; | ||
|
||
const setTreeDataPath = (path: string[], row: GridValidRowModel) => { | ||
return { ...row, path }; | ||
}; | ||
|
||
export default function RowReorderingValidation() { | ||
const { data, loading } = useDemoData({ | ||
dataSet: 'Employee', | ||
rowLength: 100, | ||
treeData: { maxDepth: 2, groupingField: 'name', averageChildren: 4 }, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGridPro | ||
{...data} | ||
setTreeDataPath={setTreeDataPath} | ||
getTreeDataPath={getTreeDataPath} | ||
loading={loading} | ||
rowReordering | ||
isValidRowReorder={isValidRowReorder} | ||
/> | ||
</div> | ||
); | ||
} |
8 changes: 8 additions & 0 deletions
8
docs/data/data-grid/row-ordering/RowReorderingValidation.tsx.preview
This file contains hidden or 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,8 @@ | ||
<DataGridPro | ||
{...data} | ||
setTreeDataPath={setTreeDataPath} | ||
getTreeDataPath={getTreeDataPath} | ||
loading={loading} | ||
rowReordering | ||
isValidRowReorder={isValidRowReorder} | ||
/> |
This file contains hidden or 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 hidden or 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,35 @@ | ||
import * as React from 'react'; | ||
import { DataGridPro } from '@mui/x-data-grid-pro'; | ||
import { useDemoData } from '@mui/x-data-grid-generator'; | ||
|
||
const getTreeDataPath = (row) => { | ||
return row.path; | ||
}; | ||
|
||
const setTreeDataPath = (path, row) => { | ||
return { | ||
...row, | ||
path, | ||
}; | ||
}; | ||
|
||
export default function TreeDataReordering() { | ||
const { data, loading } = useDemoData({ | ||
dataSet: 'Employee', | ||
rowLength: 100, | ||
treeData: { maxDepth: 3, groupingField: 'name', averageChildren: 2 }, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGridPro | ||
{...data} | ||
loading={loading} | ||
rowReordering | ||
disableRowSelectionOnClick | ||
getTreeDataPath={getTreeDataPath} | ||
setTreeDataPath={setTreeDataPath} | ||
/> | ||
</div> | ||
); | ||
} |
This file contains hidden or 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,35 @@ | ||
import * as React from 'react'; | ||
import { DataGridPro, type DataGridProProps } from '@mui/x-data-grid-pro'; | ||
import { useDemoData } from '@mui/x-data-grid-generator'; | ||
|
||
const getTreeDataPath: DataGridProProps['getTreeDataPath'] = (row) => { | ||
return row.path; | ||
}; | ||
|
||
const setTreeDataPath: DataGridProProps['setTreeDataPath'] = (path, row) => { | ||
return { | ||
...row, | ||
path, | ||
}; | ||
}; | ||
|
||
export default function TreeDataReordering() { | ||
const { data, loading } = useDemoData({ | ||
dataSet: 'Employee', | ||
rowLength: 100, | ||
treeData: { maxDepth: 3, groupingField: 'name', averageChildren: 2 }, | ||
}); | ||
|
||
return ( | ||
<div style={{ height: 400, width: '100%' }}> | ||
<DataGridPro | ||
{...data} | ||
loading={loading} | ||
rowReordering | ||
disableRowSelectionOnClick | ||
getTreeDataPath={getTreeDataPath} | ||
setTreeDataPath={setTreeDataPath} | ||
/> | ||
</div> | ||
); | ||
} |
This file contains hidden or 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,8 @@ | ||
<DataGridPro | ||
{...data} | ||
loading={loading} | ||
rowReordering | ||
disableRowSelectionOnClick | ||
getTreeDataPath={getTreeDataPath} | ||
setTreeDataPath={setTreeDataPath} | ||
/> |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.