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

[question] autoHeight data grid rows until the max height for the data grid container is set #8516

Closed
tielushko opened this issue Apr 5, 2023 · 5 comments
Labels
component: data grid This is the name of the generic UI component, not the React module! duplicate This issue or pull request already exists plan: Premium Impact at least one Premium user support: commercial Support request from paid users support: question Community support but can be turned into an improvement

Comments

@tielushko
Copy link

tielushko commented Apr 5, 2023

Order ID or Support key 💳 (optional)

62502

The problem in depth 🔍

I am trying to achieve the behavior where if there are few grouping or regular rows, the grid applies the autoHeight property and displays the aggregation row right under the last row, without having this gap in the middle.

Instead of this:
image

Have it be displayed like such:
image

However, whenever the user expands the rows, I want the grid to be able to stop the autoheight property whenever the rows height has reached the maxHeight of 500px for example.

Is there a good way to achieve such behavior? I tried setting the maxHeight on the parent container of the data grid, but it seems that the grid ignores this CSS property.

Is there a way to find out the dimensions of the data grid itself, compare it with the max dimensions allowed for the height, and dynamically set the autoHeight to be false (that was another idea, not sure if such height selector exists in the DataGrid)

I would greatly appreciate any advice!

Best!

Your environment 🌎

`npx @mui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.
@tielushko tielushko added status: waiting for maintainer These issues haven't been looked at yet by a maintainer support: commercial Support request from paid users labels Apr 5, 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 labels Apr 6, 2023
@m4theushw
Copy link
Member

Is there a way to find out the dimensions of the data grid itself, compare it with the max dimensions allowed for the height, and dynamically set the autoHeight to be false (that was another idea, not sure if such height selector exists in the DataGrid)

This would be the only viable way for now. You could listen to the debouncedResize event and check if the new height is greater than the threshold. If it does, then update autoHeight. This event is called with an object containing the width and height.

@m4theushw m4theushw removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Apr 6, 2023
@tielushko
Copy link
Author

I don't believe this would be the optimal solution. here's the sandbox I put together as a trial run of checking the height state of the data grid. You can see the flickering height. I will try to explore the logic a bit more to come up with a solution. If you happen to have an official way of switching between the two states (autoHeight vs fixedHeight please let me know)!

Sandbox Link:

https://codesandbox.io/s/debounced-resize-demo-82tr8b?file=/demo.tsx

@tielushko
Copy link
Author

@m4theushw I figured out the new logic for handling the resize event and determining whether we should autoHeight it or not. I am using the number of rows visible on the screen * rowHeight to determine the current space the rows take up. if the pixel space they take up is less that the threshold for the maxHeight we apply autoHeight. If it is larger, we can apply max height.

The only problem i have with this approach is when you hit expand the grouping row, before it has the chance to setAutoHeight to false, the grid renders every single row that is a child of the expanded row. I was wondering if you might have the suggestion for throttling that event to make sure that the autoHeight was initialized to the false value first, only then expanding the row, so that through row virtualization not every single row gets rendered on the page?

I am attaching the changes in the sandbox for anyone's use: https://codesandbox.io/s/debounced-resize-demo-82tr8b?file=/demo.tsx

@tielushko
Copy link
Author

tielushko commented May 17, 2023

I think after playing around with it a bit more, I realized the focus of the resizing should be on when the rowExpansion or rowGroupingModelChange event happens as these are the ones that change the number of visible rows (probably need to include the filtering too then...). But! here's the working solution inside the same sandbox link: https://codesandbox.io/s/debounced-resize-demo-82tr8b?file=/demo.tsx It does not have the issue of rendering all the children rows, and adjust the height of the container accordingly when the events that modify the number of visible rows happen. Let me know what you think @m4theushw and feel free to close the issue.

@oliviertassinari oliviertassinari changed the title [question] autoHeight data grid rows until the max height for the data grid container is set. [question] autoHeight data grid rows until the max height for the data grid container is set. Aug 17, 2024
@oliviertassinari oliviertassinari changed the title [question] autoHeight data grid rows until the max height for the data grid container is set. [question] autoHeight data grid rows until the max height for the data grid container is set Aug 17, 2024
@oliviertassinari
Copy link
Member

Duplicate of #3524

@oliviertassinari oliviertassinari marked this as a duplicate of #3524 Aug 17, 2024
@github-actions github-actions bot added the duplicate This issue or pull request already exists label Aug 17, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Aug 17, 2024
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! duplicate This issue or pull request already exists plan: Premium Impact at least one Premium user 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

4 participants