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] implement maxWidth to auto resizing #15658

Open
itamaryatom opened this issue Nov 28, 2024 · 2 comments
Open

[data grid] implement maxWidth to auto resizing #15658

itamaryatom opened this issue Nov 28, 2024 · 2 comments
Labels
component: data grid This is the name of the generic UI component, not the React module! feature: Column resize new feature New feature or request support: commercial Support request from paid users

Comments

@itamaryatom
Copy link

itamaryatom commented Nov 28, 2024

The problem in depth

I have a data-grid and show it with a skeleton while fetching data. When data is fetched after rendering the it I use autosizeColumns on all the columns to fit their new content.
I have a column with paths that are sometime very long (around 1000px) so they need to have a limit when auto resizing (around 400px).

I have tried:

  • adding maxWidth: 400px to the colDef, but now it can't be manually resized more than that, which is bad for me.
  • adding to the colDef width: 400 and only auto resizing columns with the default width (which I saw is 100px). I would like to avoid this solution because it has potential for future unexpected bugs.
  • creating custom property initialMaxWidth on the colDefs and adding custom logic inside an useEffect to reset their size to initialMaxWidth if they are wider after rendering the auto resize. This is both flaky and ugly.

Here is a showcase implementing the first two solutions I've tried which are mentioned above.

Is there a clean and simple way to implement these requirements with DataGrid?
Thanks In advance.

Your environment

System:
OS: macOS 15.1.1
Binaries:
Node: 23.3.0 - ~/.nvm/versions/node/v23.3.0/bin/node
npm: 10.9.0 - ~/.nvm/versions/node/v23.3.0/bin/npm
pnpm: Not Found
Browsers:
Chrome: 131.0.6778.86
npmPackages:
@emotion/react: ^11.13.3 => 11.13.3
@emotion/styled: ^11.13.0 => 11.13.0
@mui/core-downloads-tracker: 6.1.6
@mui/icons-material: ^6.1.2 => 6.1.6
@mui/material: ^6.1.2 => 6.1.6
@mui/private-theming: 6.1.7
@mui/styled-engine: 6.1.6
@mui/styles: ^6.1.7 => 6.1.7
@mui/system: 6.1.6
@mui/types: 7.2.19
@mui/utils: 6.1.7
@mui/x-charts: ^7.22.2 => 7.22.2
@mui/x-charts-vendor: 7.20.0
@mui/x-data-grid: 7.22.2
@mui/x-data-grid-pro: ^7.22.2 => 7.22.2
@mui/x-date-pickers: ^7.22.2 => 7.22.2
@mui/x-internals: 7.21.0
@mui/x-license: 7.21.0
@types/react: ^18.3.3 => 18.3.12
react: ^18.3.1 => 18.3.1
react-dom: ^18.3.1 => 18.3.1
typescript: ^5.5.3 => 5.6.3

Search keywords: maxWidth, inititialMaxWidth, max, width
Order ID: 66WEN3-MLDMV

@itamaryatom itamaryatom added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Nov 28, 2024
@github-actions github-actions bot added the component: data grid This is the name of the generic UI component, not the React module! label Nov 28, 2024
@michelengelen
Copy link
Member

Hey @itamaryatom .... thanks for opening an issue here.
I don't think what you are trying to achieve is possible with the given features.

It does make sense though to include new options for the autosizing feature like maxAutoWidth and minAutoWidth tbh. There is only one problem that might occur when using it together with the expand option. If used together how should the grid behave? expand and ignore the max width, or does the max width take precedence?

Thoughts @mui/xgrid ?

@michelengelen michelengelen changed the title [question] how to implement maxWidth only to auto resizing and not to manual resizing? [data grid] implement maxWidth to auto resizing Nov 29, 2024
@michelengelen michelengelen added new feature New feature or request feature: Column resize and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Nov 29, 2024
@github-project-automation github-project-automation bot moved this to 🆕 Needs refinement in MUI X Data Grid Nov 29, 2024
@cherniavskii
Copy link
Member

While not exactly what you're looking for, if only some are too wide then includeOutliers: false (default value) could work. Here's an example: https://codesandbox.io/p/sandbox/data-grid-initial-max-width-forked-85q8lv

Did you try that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: data grid This is the name of the generic UI component, not the React module! feature: Column resize new feature New feature or request support: commercial Support request from paid users
Projects
Status: 🆕 Needs refinement
Development

No branches or pull requests

3 participants