-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[DataGridPro] Make Row reordering work with pagination #15355
Open
k-rajat19
wants to merge
7
commits into
mui:master
Choose a base branch
from
k-rajat19:issue-15351
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.
+77
−9
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
86b16ba
make row reordering work with pagination
k-rajat19 4626fd6
Review
k-rajat19 46eda8a
Merge branch 'master' into issue-15351
k-rajat19 6313cb8
fix
k-rajat19 c962d2e
Merge branch 'master' into issue-15351
k-rajat19 ecb01e7
add pageSizeOptions to get rid of warning
k-rajat19 3ac7051
Merge branch 'master' into issue-15351
k-rajat19 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 |
---|---|---|
|
@@ -10,6 +10,7 @@ import { | |
gridRowMaximumTreeDepthSelector, | ||
useGridApiOptionHandler, | ||
GridRowId, | ||
gridRowIndexLookupSelector, | ||
} from '@mui/x-data-grid'; | ||
import { gridEditRowsStateSelector } from '@mui/x-data-grid/internals'; | ||
import { GridRowOrderChangeParams } from '../../../models/gridRowOrderChangeParams'; | ||
|
@@ -63,6 +64,8 @@ export const useGridRowReorder = ( | |
const ownerState = { classes: props.classes }; | ||
const classes = useUtilityClasses(ownerState); | ||
const [dragRowId, setDragRowId] = React.useState<GridRowId>(''); | ||
const lookup = useGridSelector(apiRef, gridRowIndexLookupSelector); | ||
const getRowIndex = React.useCallback((id: GridRowId) => lookup[id], [lookup]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we add this method to the |
||
|
||
React.useEffect(() => { | ||
return () => { | ||
|
@@ -91,17 +94,16 @@ export const useGridRowReorder = ( | |
|
||
dragRowNode.current = event.currentTarget; | ||
dragRowNode.current.classList.add(classes.rowDragging); | ||
|
||
setDragRowId(params.id); | ||
|
||
removeDnDStylesTimeout.current = setTimeout(() => { | ||
dragRowNode.current!.classList.remove(classes.rowDragging); | ||
}); | ||
|
||
originRowIndex.current = apiRef.current.getRowIndexRelativeToVisibleRows(params.id); | ||
originRowIndex.current = getRowIndex(params.id); | ||
apiRef.current.setCellFocus(params.id, GRID_REORDER_COL_DEF.field); | ||
}, | ||
[isRowReorderDisabled, classes.rowDragging, logger, apiRef], | ||
[apiRef, isRowReorderDisabled, logger, classes.rowDragging, getRowIndex], | ||
); | ||
|
||
const handleDragOver = React.useCallback<GridEventListener<'cellDragOver' | 'rowDragOver'>>( | ||
|
@@ -127,7 +129,7 @@ export const useGridRowReorder = ( | |
: event.clientY; | ||
|
||
if (params.id !== dragRowId) { | ||
const targetRowIndex = apiRef.current.getRowIndexRelativeToVisibleRows(params.id); | ||
const targetRowIndex = getRowIndex(params.id); | ||
|
||
const dragDirection = mouseMovementDiff > 0 ? Direction.DOWN : Direction.UP; | ||
const currentReorderState: ReorderStateProps = { | ||
|
@@ -149,7 +151,7 @@ export const useGridRowReorder = ( | |
|
||
previousMousePosition = { x: event.clientX, y: event.clientY }; | ||
}, | ||
[apiRef, logger, dragRowId], | ||
[dragRowId, apiRef, logger, getRowIndex], | ||
); | ||
|
||
const handleDragEnd = React.useCallback<GridEventListener<'rowDragEnd'>>( | ||
|
@@ -179,7 +181,7 @@ export const useGridRowReorder = ( | |
// Emit the rowOrderChange event only once when the reordering stops. | ||
const rowOrderChangeParams: GridRowOrderChangeParams = { | ||
row: apiRef.current.getRow(dragRowId)!, | ||
targetIndex: apiRef.current.getRowIndexRelativeToVisibleRows(params.id), | ||
targetIndex: getRowIndex(params.id), | ||
oldIndex: originRowIndex.current!, | ||
}; | ||
|
||
|
@@ -188,7 +190,7 @@ export const useGridRowReorder = ( | |
|
||
setDragRowId(''); | ||
}, | ||
[isRowReorderDisabled, logger, apiRef, dragRowId], | ||
[apiRef, dragRowId, isRowReorderDisabled, logger, getRowIndex], | ||
); | ||
|
||
useGridApiEventHandler(apiRef, 'rowDragStart', handleDragStart); | ||
|
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
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
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
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 noticed it doesn't work as expected with filtered data.
row-reorder.mp4
Could we make it work properly?
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.
this seems like a separate problem of row reordering with filtered data, also not working in v7 and in v6
v7- https://mui.com/x/react-data-grid/row-ordering/
v6- https://v6.mui.com/x/react-data-grid/row-ordering/
but it is working at the time when row reordering is implemented in #4034
v5- https://deploy-preview-4034--material-ui-x.netlify.app/x/react-data-grid/rows/#row-reorder (working)