Skip to content
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] onColumnWidthChange called before autosize affects column width #12005

Closed
rippi opened this issue Feb 8, 2024 · 3 comments · Fixed by #12140
Closed

[data grid] onColumnWidthChange called before autosize affects column width #12005

rippi opened this issue Feb 8, 2024 · 3 comments · Fixed by #12140
Assignees
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! feature: Column resize

Comments

@rippi
Copy link

rippi commented Feb 8, 2024

Steps to reproduce

Link to live example: https://react-tud9tc.stackblitz.io

Steps:

  1. open console to see logs
  2. resize column by dragging => new column width is logged as expected
  3. autosize column by double-clicking its edge => old column width is logged (wrong behavior)
  4. autosize column again => correct column width after autosize is logged

Current behavior

onColumnWidthChange gets called before autosizing is completed. It is instead called with the column width before autosizing. The second time autosizing calls onColumnWidthChange again, this time with the correct width.

Expected behavior

onColumnWidthChange gets called with the new column width after autosizing is completed

Context

Saving column widths changed by the user in external storage, so it can be retrieved and applied if the same DataGrid is opened again by said user.

Your environment

npx @mui/envinfo Used Chrome 121.0.6167.141 even though not listed
System:
    OS: Windows 11 10.0.22631
  Binaries:
    Node: 18.12.1 - C:\Program Files\nodejs\node.EXE
    npm: 8.19.2 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.14.0 - C:\Program Files\nodejs\pnpm.CMD
  Browsers:
    Chrome: Not Found
    Edge: Chromium (121.0.2277.106)
  npmPackages:
    @emotion/react: ^11.11.3 => 11.11.3
    @emotion/styled: ^11.11.0 => 11.11.0
    @mui/icons-material: ^5.15.9 => 5.15.9
    @mui/material: ^5.15.9 => 5.15.9
    @mui/x-data-grid-pro: ^6.19.3 => 6.19.3
    @types/react: ^18.2.47 => 18.2.47
    react: ^18.2.0 => 18.2.0
    react-dom: ^18.2.0 => 18.2.0
    typescript: ^5.3.3 => 5.3.3

Search keywords: autosize

@rippi rippi added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Feb 8, 2024
@zannager zannager added the component: data grid This is the name of the generic UI component, not the React module! label Feb 9, 2024
@michelengelen michelengelen changed the title onColumnWidthChange called before autosize affects column width [data grid] onColumnWidthChange called before autosize affects column width Feb 9, 2024
@michelengelen
Copy link
Member

I can confirm this behavior (bug).
I'll put it on the board for the team to have a look at.
thanks for raising this issue @rippi 🙇🏼

@michelengelen michelengelen added bug 🐛 Something doesn't work feature: Column resize and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Feb 12, 2024
@shaharyar-shamshi
Copy link
Contributor

@michelengelen I was looking into this issue the problem is before mouseDoubleClick event get trigger mouseUp event is trigger which publish the event of the columnWidthChange with the previous width so we need to stop this behaviour
and publish the event once the column is resized after mouseDoubleClick.

Attaching the reference code of previous implementation

const handleResizeMouseUp = useEventCallback(finishResize);

if you can assign this to me. I can work on the issue

Copy link

⚠️ This issue has been closed.
If you have a similar problem, please open a new issue and provide details about your specific problem.
If you can provide additional information related to this topic that could help future readers, please feel free to leave a comment.

How did we do @rippi?
Your experience with our support team matters to us. If you have a moment, please share your thoughts through our brief survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! feature: Column resize
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants