-
-
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
[DataGridPro] <input> in header, conflicts with column reordering & sorting #1915
Comments
Please provide a minimal reproduction test case with the latest version. This would help a lot 👷 . |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
well frist of all you need ideally more columns, at least 2, and one problem is already visible there. When you write a text into that input, then you wanna seelct text inside that input (value), you realize you cant, because drag and drop will be propagated and yo ustart moving whole column. But thats not a wanted effect I assume. I tried to put soem eynthetic events there to stop propagation, but its still not working as desired. None of these events stops the drag and drop |
here is forked code, where you can imitate/reproduce what I described https://codesandbox.io/s/material-demo-forked-02qke writ soem text into wedding input and then try to mark the input value from left to right, and oyu drag whoel columen towards the birthday column. I hope its better explained now |
If you want to disable column reordering, you can use the |
I want to have reordering enabled, but it has to stay disabled in the area of input |
I just checked disableColumnReorder and its not present on XGrid page https://material-ui.com/api/data-grid/x-grid/ as an acceptable parameter, do you know why is that? |
@Bidrman we missed it when we were updating the docs. It will be there after the next release. It will work for |
Ok after a short investigation - the problem is not with the event but rather with the HTML API here https://github.com/mui-org/material-ui-x/blob/master/packages/grid/_modules_/grid/components/columnHeaders/GridColumnHeaderItem.tsx#L211 Basically, we currently lack the option to make a single column not draggable. Maybe it's time to add that option in the column definition? |
@DanailH I dont need it just for single column, but for that input, we use columnHeaders as filter via those inputs (textfields) and currently those inputs are not fully operational due to these drag and drop issues. disableColumnReorder fixes the problem with marking the text in the input but I just noticed another bug there, so I probbaly make new issue here. I am still able to reorder columns if I set disableColumnReorder to true. |
This a known bug/regression: #1762 @Bidrman To clarify it, could you confirm if we get the problem right? You want the column headers to be draggable. Your problem is that end users can't interact with the input when it's rendered in the header. You don't want the input to interfere with the sorting, nor reordering features of the header. |
@oliviertassinari Indeed #1762 is the problem that I was reffering. after marking title you are able to change the order. this of course happens not just in title only. Cells are vulnerable to this behaviour too. You just need to mark text in 2 cells, then drag them aside and you see some show. |
@dtassone @oliviertassinari @oliviertassinari just to let you know, I just created a fix of this issue. you just need to create const [staticColumn, setStatic] = useState(false); in your component and through this you can actually control disableColumnReorder={staticColumn}. last part is just adding synthetic events on the input onFocus => setStatic(true) and onBlur => setStatic(false). after this it works like a charm. maybe this can be implemented as a fix, perhaps?? |
@Bidrman sounds like a good workaround. Are you able to provide a codesandbox maybe? |
@Bidrman as well as how you solve the click sorting issue 👍 |
@dtassone @oliviertassinari will do, once im back from holiday. dont have my laptop with me |
@Bidrman Ok. I had a quick look. This seems to solve perfectly the problem: <span
draggable="true"
onDragStart={(event) => {
event.stopPropagation();
event.preventDefault();
}}
onClick={(event) => {
event.stopPropagation();
}}
> https://codesandbox.io/s/material-demo-forked-bgyj7?file=/demo.tsx Maybe it should be in the docs, https://material-ui.com/components/data-grid/columns/#column-reorder but maybe not, it's overkill. |
We can add a demo about how |
@oliviertassinari its almost identical as my solution I created, I just used more verbous syntax. But it was the only solution that worked for me. Something about the propagation could be added into docs, I am sure it would help other users to save time and some nerves haha. |
@oliviertassinari Have you tried the above code sandbox in Firefox? Im a DataGridPro developer - we need to support Firefox users and this text selection came up for us. It does work for Chrome and Safari but all text selection on the input is disabled in Firefox. I haven't dug into the specifics of why this is broken in Firefox, if I get anything working I will post back |
@dmh143 Indeed the example from https://codesandbox.io/s/material-demo-forked-bgyj7?file=/demo.tsx is not working in new firefox version (91.3). However my fix still working |
@Bidrman There's bug report on Firefox exactly about that: https://bugzilla.mozilla.org/show_bug.cgi?id=739071 To provide an alternative solution I took a different path. Instead of preventing the default behavior of the drag events I tried to change CodeSandbox: https://codesandbox.io/s/material-demo-forked-xujt1g?file=/demo.tsx:186-796 renderHeader: () => (
<strong>
{"Birthday "}
<span
onMouseDown={(event) => {
event.target
.closest(".MuiDataGrid-columnHeaderDraggableContainer")
.setAttribute("draggable", false);
}}
onMouseUp={(event) => {
event.target
.closest(".MuiDataGrid-columnHeaderDraggableContainer")
.setAttribute("draggable", true);
}}
onClick={(event) => {
event.stopPropagation();
}}
>
<input />
</span>
</strong>
) I don't think we should do anything to support out-of-box inputs as column headers in the DataGridPro. While a custom header with an input shouldn't trigger dragging, a normal div element should still allow dragging. We can't have a list of non-draggable elements. To close this issue and to document the possible solution I think we could invest time to add a demo in https://mui.com/components/data-grid/filtering/ with inputs as column headers, where each input allows to filter the respective column. Similar to #2842 but for columns. |
We now have a Header filters functionality to be leveraged in use cases where the intent is to allow quick filtering or possibly add a custom 2nd header row. Closing this issue now. |
I am not even sure if it's a bug, but it seems to me that it might be. When I choose to have a custom column header with draggable columns (sortable: true). Then it makes a bunch of problems.
https://codesandbox.io/s/material-demo-forked-2gtom?file=/demo.tsx
Current Behavior 😯
Draggable functionality propagates everywhere and I cant even mark the text in the input.
Expected Behavior 🤔
ideally, stop all propagation from elements that were custom made.
Steps to Reproduce 🕹
rest of a Datagrid is standard so just use any other
Steps:
PLease provide some guidance how to fix this behaviour
The text was updated successfully, but these errors were encountered: