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

[datagrid] autosizeColumns does not work #10510

Closed
andymanitara opened this issue Sep 28, 2023 · 20 comments
Closed

[datagrid] autosizeColumns does not work #10510

andymanitara opened this issue Sep 28, 2023 · 20 comments
Labels
component: data grid This is the name of the generic UI component, not the React module! feature: Column resize plan: Premium Impact at least one Premium user status: waiting for author Issue with insufficient information support: commercial Support request from paid users support: question Community support but can be turned into an improvement

Comments

@andymanitara
Copy link

andymanitara commented Sep 28, 2023

The problem in depth 🔍

Hi,

I'm using the latest version of the DataGrid to test out the new autosize feature. The way I use the grid, is once the data comes back from an endpoint we populate the grid. So I was looking to use the apiRef to call apiRef.current.autosizeColumns()

However, it tells me that autosizeColumns doesn't exist and when I log out the entirety of apiRef.current it doesn't exist as a property on the object.

From the documentation, I've tried to understand why it doesn't show or why the autosize doesn't work but I couldn't find an answer. We currently give our columns a set width, would that impact it in any way? Or are there any other props that we could be using in our grid that could stop the autosize from working outside of the dynamic row height which we aren't using?

I'm not sure if I just haven't fully installed something, or was supposed to update another package too but I've only upgraded from 6.14.0 to 6.15.0

Thanks for your help,

Andy

Your environment 🌎

npx @mui/envinfo

Search keywords: autosizeColumns

@andymanitara andymanitara added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Sep 28, 2023
@zannager zannager added support: question Community support but can be turned into an improvement component: data grid This is the name of the generic UI component, not the React module! plan: Premium Impact at least one Premium user and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Sep 28, 2023
@cherniavskii cherniavskii reopened this Oct 3, 2023
@cherniavskii cherniavskii changed the title [question] DataGrid - new autosizeColumns feature [datagrid] autosizeColumns does not work Oct 3, 2023
@romgrk
Copy link
Contributor

romgrk commented Oct 3, 2023

@cherniavskii Why did you reopen this one? Did you notice the issue?

@andymanitara Was this issue resolved for you? Were you using the right package?

@romgrk romgrk added the status: waiting for author Issue with insufficient information label Oct 3, 2023
@cherniavskii
Copy link
Member

I wanted to check if it's reproducible and also see how column autosizing works with asynchronously loaded rows.

@cherniavskii
Copy link
Member

@andymanitara I cannot reproduce the issue with this demo: https://codesandbox.io/s/lucid-roentgen-ynchfy?file=/Demo.tsx
Are you sure you're passing the apiRef prop to the data grid?

@cherniavskii
Copy link
Member

@romgrk One thing I noticed in the example above is that calling apiRef.current.autosizeColumns after updating the rows state doesn't work.
It makes sense - autosizeColumns is being called before the grid renders the rows.

One workaround is to wrap autosizeColumns with setTimeout: https://codesandbox.io/s/sad-pasteur-cdyscq?file=/Demo.tsx
This works, but it's jumpy.

Another option is to use apiRef.current.updateRows + ReactDOM.flushSync: https://codesandbox.io/s/interesting-ben-vh9ndk?file=/Demo.tsx
This works better than setTimeout.

How would you approach this use case?
I think we should document a recommended approach since the use case is common and the solution is not obvious.

@romgrk
Copy link
Contributor

romgrk commented Oct 3, 2023

Sure but maybe open a new issue just for that concern?

However, it tells me that autosizeColumns doesn't exist and when I log out the entirety of apiRef.current it doesn't exist as a property on the object.

My impression from this issue is that the author might have used the community package on which the autosizeColumns API doesn't exist.

@andymanitara
Copy link
Author

andymanitara commented Oct 4, 2023

Hey guys, yes I'm using the apiRef from the data grid, and I'm not using the community package. I'm using the DataGridPremium also if that helps. I'm using a lot of the premium features, including the aggregation etc and that's working fine. For some reason though the apiRef doesn't have the autosizeColumns property still. Perhaps I should try with the DataGridPro version instead and see if its happening there but not the Premium one for some reason?

I can't see how else I'm not getting that. I closed the issue because I ended up ignoring the autosizing feature for now, but it would be good to know. I see the autosize properties on the actual DataGridPremium component itself, just not in the apiRef & I'm definitely getting the useGridApiRef from the premium package.

@cherniavskii
Copy link
Member

@romgrk Opened #10578

@romgrk
Copy link
Contributor

romgrk commented Oct 4, 2023

@andymanitara That sounds really weird. Are you able to reproduce the issue in a live example? This codesandbox.io template may be a good starting point.

@romgrk romgrk added the status: waiting for author Issue with insufficient information label Oct 4, 2023
@andymanitara
Copy link
Author

@andymanitara That sounds really weird. Are you able to reproduce the issue in a live example? This codesandbox.io template may be a good starting point.

https://codesandbox.io/s/distracted-ishizaka-mh8sv6?file=/demo.tsx

I'd expect to see the autosizeColumns property on click, in the console I assume? Or does it require something else? The type doesn't even exist on the GridApiPremium it says for me too. I had issues using the DEFAULT_GRID_AUTOSIZE_OPTIONS too

@github-actions github-actions bot removed the status: waiting for author Issue with insufficient information label Oct 5, 2023
@charisseysabel
Copy link

charisseysabel commented Oct 5, 2023

I noticed this as well after our package-lock lockfileVersion changed from 2 -> 3. autosizeColumns is visible on v2, but not 3 🤔

@cherniavskii
Copy link
Member

cherniavskii commented Oct 5, 2023

Are you able to reproduce the issue in a live example? This codesandbox.io template may be a good starting point.

I think I just reproduced it.
EDIT: I just noticed the version "@mui/x-data-grid-premium": "6.0.3", so it's expected.

@cherniavskii
Copy link
Member

cherniavskii commented Oct 5, 2023

@andymanitara @charisseysabel Is this the same error you are experiencing?
Could you double-check which version of @mui/x-data-grid-premium you are using?

@cherniavskii cherniavskii added the status: waiting for author Issue with insufficient information label Oct 5, 2023
@andymanitara
Copy link
Author

@andymanitara @charisseysabel Is this the same error you are experiencing?

Could you double-check which version of @mui/x-data-grid-premium you are using?

I'm using 6.0.15 of the @mui/x-data-grid-premium

@github-actions github-actions bot removed the status: waiting for author Issue with insufficient information label Oct 5, 2023
@charisseysabel
Copy link

charisseysabel commented Oct 5, 2023

@cherniavskii

Is #10510 (comment) the same error you are experiencing?
Could you double-check which version of @mui/x-data-grid-premium you are using?

Yep, that's the error for me.
We're using the latest (v6.16.0) using data-grid-pro

@romgrk
Copy link
Contributor

romgrk commented Oct 5, 2023

@andymanitara You need to use a version of the grid after the autosize feature was released. Can you test again with the latest version? Modifying your codesandbox to use @mui/x-data-grid-premium@6.16.0 fixes the issue for me.

@cherniavskii
Copy link
Member

@romgrk 6.0.15 looks good, that was the first release to include column autosizing https://github.com/mui/mui-x/releases/tag/v6.15.0

@romgrk
Copy link
Contributor

romgrk commented Oct 6, 2023

6.15.0 yes. 6.0.15 no.

@andymanitara
Copy link
Author

andymanitara commented Oct 10, 2023

@romgrk 6.0.15 looks good, that was the first release to include column autosizing https://github.com/mui/mui-x/releases/tag/v6.15.0

That's a typo on my end here, I was using 6.15.0 sorry (as per my opening post) - I have the autosizing props working on the actual DataGrid itself it's just that apiRef.autosizeColumns that doesn't exist for some reason. I can try on 6.16.1 to see if it makes a difference but it should be fine on 6.15.0 and for some reason doesn't work for me still on that version

@romgrk
Copy link
Contributor

romgrk commented Oct 11, 2023

I've tried with the pro & premium packages, versions 6.15.0 and 6.16.1, and it's defined in both of them:
https://codesandbox.io/s/unruffled-snow-gvp55k?file=/src/demo.tsx

image

@andymanitara Can you provide a reproducible codesandbox example? It's not possible for us to understand what's wrong otherwise.

@romgrk romgrk added the status: waiting for author Issue with insufficient information label Oct 11, 2023
@github-actions
Copy link

The issue has been inactive for 7 days and has been automatically closed. If you think that it has been incorrectly closed, please reopen it and provide missing information (if any) or continue the last discussion.

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 plan: Premium Impact at least one Premium user status: waiting for author Issue with insufficient information support: commercial Support request from paid users support: question Community support but can be turned into an improvement
Projects
None yet
Development

No branches or pull requests

5 participants