-
-
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
[XGrid] Add ability to disable reorder on some columns #2085
Conversation
For the name of the property, I would refer to https://material-ui.com/guides/api/#property-naming |
This page is for props, I don't think the shorthand argument really applies here. Both approaches can make sense
Most options are in the affirmative form so I think we should rename |
@mui-org/x I have two behavior points to discuss AG Grid differentiate
Do you think it's something we want to implement ? Do we want to also block the re-ordering when it is done with |
@flaviendelangle Yeah, right, the shorthand advantage is specific to the props. I will update this section to mention the second advantage: as a developer, you always know what the default value is by looking at the name of the prop.
I think that the difference is not negligeable. If we wanted to be really low-level and maximize flexibility, we could say to the developers:
I guess that for 2. to work, it also needs 1. Maybe we can implement 2, and in the future, expose 1 in the API if we see a real use case? So far the problem we want to solve is to force the selection checkbox to stay on the starting position. |
#2085 (comment) @oliviertassinari What do you mean by "implemented with a controlled API" ? |
const targetCol = getColumnHeaderCell(0).firstChild!; | ||
|
||
fireEvent.dragStart(dragCol); | ||
fireEvent.dragEnter(targetCol); |
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.
If the column can't be reordered we don't even allow the user to start dragging it. We could check if the draggable
attribute is false or if GRID_COLUMN_HEADER_DRAGGING_CSS_CLASS
was not added.
!targetCol.disableReorder || | ||
(targetColVisibleIndex > 0 && targetColVisibleIndex < visibleColumnAmount - 1); | ||
|
||
const cursorMoveDirectionX = getCursorMoveDirectionX(cursorPosition.current, coordinates); |
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 another PR:
This cursorMoveDirectionX
is wrong. It's always "right" the first time. We need to save the cursor position when the user starts dragging
const dragOverEvent = createEvent.dragOver(target); | ||
// Safari 13 doesn't have DragEvent. | ||
// RTL fallbacks to Event which doesn't allow to set these fields during initialization. | ||
Object.defineProperty(dragOverEvent, 'clientX', { value: 1 }); |
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 another PR:
Add an argument to allow to change the clientX
. We use this value to check if the user is moving to the left or right.
packages/grid/_modules_/grid/hooks/features/columnReorder/useGridColumnReorder.tsx
Show resolved
Hide resolved
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 have tested the behavior with a disableReorder
on a column in the middle: https://codesandbox.io/s/material-demo-forked-2c26p?file=/demo.js. It's weird. But 👍 for ignoring this for now. I think that it would be more efficient & effective to ship and wait for feedback.
I mean, the new prop allows preventing end-users to start the drag and drop from the column, it's already great. It comes with a bonus behavior (that is likely outside of the scope of disableReorder
) of preventing other columns to go past it.
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.
Good job!
Closes #1161
Closes #1768
Implemented behavior :
disableReorder: true
can't be drag&droppeddisableReorder: true
, we can't drag&drop a column left of itdisableReorder: true
, we can't drag&drop a column right of itRight now the behavior is at the drag&drop level, I do not block the updates made with
apiRef
.Do we want to do it?
Do you prefer?
ORWe have both (
disableExport
butresizable
), which is not great from a user perspective I think.I did not implement the behavior on the column panel yet. Preview: https://deploy-preview-2085--material-ui-x.netlify.app/components/data-grid/columns/#column-reorder.