-
-
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
[data grid] onRowOrderChange
is not called sometimes when dragging causes scrolling in datagrid.
#6165
Comments
Thanks @twhiteheadzm Screen.Recording.2022-09-20.at.15.03.38.mov |
With virtualization enabled, the As a workaround, you can disable virtualization with cc @DanailH |
Also, I expect we will face the same issue with column reordering (after #6236 is fixed) |
onRowOrderChange
is not called sometimes when dragging causes scrolling in datagrid.
hey @cherniavskii --- a/packages/grid/x-data-grid-pro/src/components/GridRowReorderCell.tsx
+++ b/packages/grid/x-data-grid-pro/src/components/GridRowReorderCell.tsx
@@ -31,6 +31,7 @@ const useUtilityClasses = (ownerState: OwnerState) => {
function GridRowReorderCell(params: GridRenderCellParams) {
const apiRef = useGridApiContext();
+ const ref = React.useRef<HTMLDivElement>(null);
const rootProps = useGridRootProps();
const sortModel = useGridSelector(apiRef, gridSortModelSelector);
const treeDepth = useGridSelector(apiRef, gridRowMaximumTreeDepthSelector);
@@ -81,9 +82,19 @@ function GridRowReorderCell(params: GridRenderCellParams) {
[apiRef, params.id],
);
+ const dragEnd = (event: React.MouseEvent<HTMLDivElement> | any) => {
+ event.currentTarget.removeEventListener('dragend', dragEnd);
+ publish('rowDragEnd')(event);
+ };
+
const draggableEventHandlers = isDraggable
? {
- onDragStart: publish('rowDragStart'),
+ onDragStart: (event: React.MouseEvent<HTMLDivElement>) => {
+ // IF virtualization is enabled
+
+ ref.current?.addEventListener('dragend', dragEnd);
+ publish('rowDragStart')(event);
+ },
onDragOver: publish('rowDragOver'),
onDragEnd: publish('rowDragEnd'),
}
@@ -94,7 +105,7 @@ function GridRowReorderCell(params: GridRenderCellParams) {
}
return (
- <div className={classes.root} draggable={isDraggable} {...draggableEventHandlers}>
+ <div ref={ref} className={classes.root} draggable={isDraggable} {...draggableEventHandlers}>
<rootProps.components.RowReorderIcon />
<div className={classes.placeholder}>{cellValue}</div>
</div> Demo: https://codesandbox.io/s/awesome-field-rh2gs8?file=/demo.tsx |
@yaredtsy Nice, I like the idea! |
i have submitted a PR. |
Duplicates
Latest version
Current behavior 😯
When dragging a row up or down and it causes scrolling of the table, it sometimes does not call onRowOrderChange. Seems to happen most when scrolling a long way.
The row is moved correctly in the grid and no errors shown in console. Dragging it again a short distance does trigger onRowOrderChange.
Expected behavior 🤔
onRowOrderChange should be called whenever a row is dragged.
Steps to reproduce 🕹
Link to live example:
Steps:
1.
2.
3.
4.
Context 🔦
No response
Your environment 🌎
npx @mui/envinfo
Order ID 💳 (optional)
No response
The text was updated successfully, but these errors were encountered: