-
-
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
base: master
Are you sure you want to change the base?
Conversation
Deploy preview: https://deploy-preview-15355--material-ui-x.netlify.app/ |
}, {}), | ||
[rows], | ||
); | ||
const getRowIndex = React.useCallback((id: GridRowId) => lookup[id], [lookup]); |
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.
should we add this method to the GridRowApi
?
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.
Thank you @k-rajat19 for your contribution.
I added a few comments.
Also, Is it possible to add some test coverage for the bugfix?
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?
@@ -63,6 +64,16 @@ export const useGridRowReorder = ( | |||
const ownerState = { classes: props.classes }; | |||
const classes = useUtilityClasses(ownerState); | |||
const [dragRowId, setDragRowId] = React.useState<GridRowId>(''); | |||
const rows = gridExpandedSortedRowEntriesSelector(apiRef); |
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.
Using a selector directly in the React component might yield bugs since it'll not ensure proper reactivity.
Wrapping the selector with useGridSelector
is preferred as it ensures to re-render the component when the state value updates.
@@ -63,6 +64,16 @@ export const useGridRowReorder = ( | |||
const ownerState = { classes: props.classes }; | |||
const classes = useUtilityClasses(ownerState); | |||
const [dragRowId, setDragRowId] = React.useState<GridRowId>(''); | |||
const rows = gridExpandedSortedRowEntriesSelector(apiRef); | |||
const lookup = React.useMemo( |
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'd prefer to off-load this to a selector as it'll remove the need for a memoization as well as ensure proper reactivity.
Wdyt?
Closes #15351
getRowIndexRelativeToVisibleRows
method gives index relative to the current page but I think using the absolute index would help in all cases, added agetRowIndex
method which gives the absolute index.Before: https://codesandbox.io/p/sandbox/row-reorder-v5r5q9
After: https://codesandbox.io/p/sandbox/mui-mui-x-x-data-grid-forked-zmc5hd