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] Fix grid dimensions calculation with autoHeight=true #7489

Conversation

cherniavskii
Copy link
Member

@cherniavskii cherniavskii commented Jan 12, 2023

Fixes #6970

Before: https://codesandbox.io/s/beautiful-silence-24ue6i?file=/demo.tsx
After: https://codesandbox.io/s/great-microservice-r98k1d?file=/demo.tsx

Steps to reproduce:

  • open the demo
  • filter the Commodity column so that there are no rows matching the filter value (e.g. "qwerty")

TODO:

  • add unit test
  • backport to the master branch

@cherniavskii cherniavskii added bug 🐛 Something doesn't work component: data grid This is the name of the generic UI component, not the React module! feature: Rendering layout Related to the data grid Rendering engine labels Jan 12, 2023
@@ -79,6 +78,7 @@ export function useGridDimensions(
const rootElement = apiRef.current.rootElementRef?.current;
const columnsTotalWidth = gridColumnsTotalWidthSelector(apiRef);
const pinnedRowsHeight = calculatePinnedRowsHeight(apiRef);
const rowsMeta = gridRowsMetaSelector(apiRef.current.state);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rowsMeta.currentPageTotalHeight value was outdated here, so I moved rowsMeta inside the callback.
For example, when filtering the rows and there were no rows matching the filtering criteria, updateGridDimensionsRef was called with the outdated value of rowsMeta.currentPageTotalHeight before applying filters.

@mui-bot
Copy link

mui-bot commented Jan 12, 2023

Messages
📖 Netlify deploy preview: https://deploy-preview-7489--material-ui-x.netlify.app/

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 677 1,600.2 677 992.22 359.897
Sort 100k rows ms 721.3 1,336.3 1,336.3 1,098.22 259.913
Select 100k rows ms 232.4 382.4 275.4 295.52 57.94
Deselect 100k rows ms 222.8 369.7 239.1 265.86 54.662

Generated by 🚫 dangerJS against d2a4af1

@cherniavskii cherniavskii changed the title [DataGrid] Fix grid dimensions calculation on grid size change [DataGrid] Fix grid dimensions calculation with autoHeight=true Jan 12, 2023
@cherniavskii cherniavskii changed the title [DataGrid] Fix grid dimensions calculation with autoHeight=true [DataGrid] Fix grid dimensions calculation with autoHeight=true Jan 12, 2023
@cherniavskii cherniavskii marked this pull request as ready for review January 16, 2023 12:04
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 17, 2023
@github-actions

This comment was marked as outdated.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 18, 2023
@cherniavskii cherniavskii self-assigned this Jan 18, 2023
rowsMeta.currentPageTotalHeight,
totalHeaderHeight,
]);
}, [apiRef, props.scrollbarSize, props.autoHeight, totalHeaderHeight]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing rowsMeta.currentPageTotalHeight caused another bug. Go to https://deploy-preview-7489--material-ui-x.netlify.app/x/react-data-grid/layout/#auto-height and remove all rows. The label is misaligned because its height is from when there was still one row left.

rowsMeta.currentPageTotalHeight as dependency ensured that whenever the total height changed (which may occur not only by filtering but also by removing rows), the dimensions would be updated.

image

I solved this problem in #6979 by checking currentPage.rows.length === 0 instead of the height.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!
What do you think about the direction taken in this PR?

It's not fully ready yet (I've noticed that it doesn't always work), but I think it's still a problem with dimensions calculations rather than overlays layout.
Does it make sense to put more effort into it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there's a bug that makes the returned value of apiRef.current.getRootDimensions inconsistent, then we should fix it, so +1 for pushing this forward. For the specific problem of the "No results" overlay, I think we shouldn't even have this problem in the first place if the overlay weren't rendered on top of the content. In #6979 I delegated to CSS to expand the overlay to fill the available height, it's one less point of failure now. If we consider #7489 as the fix for #6970, I would prefer to still merge my PR as an improvement to how the overlays are rendered.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, sounds good to me!
This PR might be a potential fix for the same issue on the master branch since we won't change the overlays layout in v5.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jun 9, 2023
@github-actions
Copy link

github-actions bot commented Jun 9, 2023

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@cherniavskii
Copy link
Member Author

Closing this PR, because the underlying issue was fixed by #8091

@cherniavskii cherniavskii deleted the fix-wrong-viewport-dimensions-autoHeight branch June 9, 2023 09:45
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: Rendering layout Related to the data grid Rendering engine PR: out-of-date The pull request has merge conflicts and can't be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Data Grid Layout-> AutoHeight causes rerender which makes text "no records found" removed after filtering
3 participants