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] Rework column headers and virtual scroller positioning #7001

Merged
merged 22 commits into from
Jan 5, 2023

Conversation

cherniavskii
Copy link
Member

@cherniavskii cherniavskii commented Nov 25, 2022

Closes #602

TODO:

Changelog

Breaking changes

  • The headerHeight prop was renamed to columnHeaderHeight

@cherniavskii cherniavskii added breaking change component: data grid This is the name of the generic UI component, not the React module! v6.x feature: Rendering layout Related to the data grid Rendering engine labels Nov 25, 2022
@mui-bot
Copy link

mui-bot commented Nov 25, 2022

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

These are the results for the performance tests:

Test case Unit Min Max Median Mean σ
Filter 100k rows ms 600.2 1,078 643.3 781.82 167.444
Sort 100k rows ms 585.4 1,164.9 821.8 888.32 188.38
Select 100k rows ms 208.3 296.1 231.7 241.14 30.567
Deselect 100k rows ms 176.4 367.5 202.4 227.1 71.111

Generated by 🚫 dangerJS against 07b9cf3

Copy link
Member

@m4theushw m4theushw left a comment

Choose a reason for hiding this comment

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

I checked the other regressions and it seems that the demo is wrong and this PR uncovered this problem. Before, with position: absolute, it appeared to behave correctly because the dimensions of the absolute positioned element were not taken into account.

diff --git a/docs/data/data-grid/layout/FlexLayoutGrid.js b/docs/data/data-grid/layout/FlexLayoutGrid.js
index 807b56922..647ceed4a 100644
--- a/docs/data/data-grid/layout/FlexLayoutGrid.js
+++ b/docs/data/data-grid/layout/FlexLayoutGrid.js
@@ -11,7 +11,7 @@ export default function FlexLayoutGrid() {
 
   return (
     <div style={{ height: 400, width: '100%' }}>
-      <div style={{ display: 'flex', height: '100%' }}>
+      <div style={{ display: 'flex', flexDirection: 'column', height: '100%' }}>
         <div style={{ flexGrow: 1 }}>
           <DataGrid {...data} />
         </div>
diff --git a/docs/data/data-grid/row-height/ExpandableCells.js b/docs/data/data-grid/row-height/ExpandableCells.js
index 919ac9ff1..5df89012c 100644
--- a/docs/data/data-grid/row-height/ExpandableCells.js
+++ b/docs/data/data-grid/row-height/ExpandableCells.js
@@ -84,7 +84,7 @@ for (let i = 0; i < 10; i += 1) {
 
 export default function ExpandableCells() {
   return (
-    <div style={{ height: 400, width: 800 }}>
+    <div style={{ height: 400, width: '100%' }}>
       <DataGrid
         rows={rows}
         columns={columns}

The demo above tries to use width: 800px but the test viewer has max-width: 500px.

{...other}
>
{state.height === null && state.width === null ? null : children(childParams)}
<div ref={handleRef} style={{ flex: 1, overflow: 'auto', ...style }} {...other}>
Copy link
Member

Choose a reason for hiding this comment

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

https://app.argos-ci.com/mui/mui-x/builds/6190/29684886 can be fixed with

Suggested change
<div ref={handleRef} style={{ flex: 1, overflow: 'auto', ...style }} {...other}>
<div ref={handleRef} style={{ flex: disableHeight ? 0 : '1 1 0px', overflow: 'auto', ...style }} {...other}>

The reason for flex: 0 is because when auto height is enabled we don't want the content to shrink.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for your help!

overflow: 'hidden',
display: 'flex',
alignItems: 'center',
boxSizing: 'border-box',
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a bugfix actually, you can see that in v5 the column header border is not visible when you have pinned rows:
https://codesandbox.io/s/strange-sea-6ul544?file=/demo.tsx
You cannot reproduce this in the same demo in the docs because in the docs we use CssBaseline which sets * { box-sizing: border-box }.

I didn't want to extract this into a separate PR to save time.
I'll cherry-pick this change to master once this PR is merged.

@cherniavskii
Copy link
Member Author

Alright, I've finally managed to fix the regressions caused by the layout change 🎉

There are only 3 regressions left in https://app.argos-ci.com/mui/mui-x/builds/6762/31501643:
Screenshot 2022-12-14 at 13 26 05

All 3 are caused by height rounding that we did before.
Before this PR, the virtual scroller had the explicit height set and the value was rounded to a whole pixel:
Screenshot 2022-12-14 at 13 32 43

Now the virtual scroller uses the available space and sometimes it may have subpixel value:
Screenshot 2022-12-14 at 13 33 30

So I believe we should accept the screenshot changes since this is now the expected behavior 👍

Comment on lines +78 to +81
<VirtualScrollerComponent
ref={virtualScrollerRef}
disableVirtualization={isVirtualizationDisabled}
/>
Copy link
Member Author

Choose a reason for hiding this comment

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

I really like this change!

@@ -11,7 +11,7 @@ export default function FlexLayoutGrid() {

return (
<div style={{ height: 400, width: '100%' }}>
<div style={{ display: 'flex', height: '100%' }}>
<div style={{ display: 'flex', flexDirection: 'column', height: '100%' }}>
<div style={{ flexGrow: 1 }}>
<DataGrid {...data} />
Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder what is the point of this demo.
There are 3 wrapper divs, 2 of which seem to be redundant since it's equivalent of

<div style={{ height: 400, width: '100%' }}>
  <DataGrid {...data} />
</div>

What are we trying to cover in this section? https://mui.com/x/react-data-grid/layout/#flex-layout

Copy link
Member Author

Choose a reason for hiding this comment

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

@m4theushw could you take a look at this one? It's off-topic, but it's not clear for me what's the intention of that demo

Copy link
Member

@m4theushw m4theushw Jan 5, 2023

Choose a reason for hiding this comment

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

I don't know why it has this structure. It was created already that way: https://github.com/mui/mui-x/pull/267/files#diff-b4e854d1aab47be29ed3d21847dbed928f8d36d3cafa0162b2ae35293fb9d6da

I suppose the outermost div (the one with height: 400px) was added first to constrain the height so it doesn't extend the full page height. In a real scenario this div wouldn't be needed. Then, the intermediary div (the one with display: flex) was added is to simulate how flex layout is used in real applications. I think the outermost and the intermediary divs can be merged, and height: 100% -> height: 400px.

Copy link
Member

@oliviertassinari oliviertassinari Jan 8, 2023

Choose a reason for hiding this comment

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

If I recall correctly, I used https://ag-grid.com/javascript-data-grid/grid-size/#inside-flexbox-container as inspiration for this demo. But in hindsight, it feels that developers learn nothing from https://next.mui.com/x/react-data-grid/layout/#flex-layout. It could be good to delete this h2 section. This would make more sense

Screenshot 2023-01-08 at 22 25 57

but really? Do we need to teach developer CSS Grid/Flexbox?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, @oliviertassinari
Few minor concerns I also had about the flex demo:

  1. Developers might think that a flex container is required for the grid to work (especially on a quick look at the docs, since it's the first demo on the page).
  2. Developers might copy the whole snippet with 2 nested divs, which is ... unnecessarily complicated 🤷🏻‍♂️

but really? Do we need to teach developer CSS Grid/Flexbox?

I think we can remove the whole section. The main requirement for the parent container is covered in the first few sentences anyway

Copy link
Member

@oliviertassinari oliviertassinari Jan 29, 2023

Choose a reason for hiding this comment

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

@cherniavskii cherniavskii marked this pull request as ready for review December 14, 2022 15:15
@cherniavskii cherniavskii changed the title [DataGrid] Refactor AutoSizer layout [DataGrid] Rework column headers and virtual scroller positioning Dec 14, 2022
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Dec 21, 2022
@github-actions

This comment was marked as outdated.

@github-actions github-actions bot added PR: out-of-date The pull request has merge conflicts and can't be merged and removed PR: out-of-date The pull request has merge conflicts and can't be merged labels Dec 22, 2022
@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 Dec 23, 2022
@cherniavskii cherniavskii enabled auto-merge (squash) January 5, 2023 20:37
@cherniavskii cherniavskii merged commit 00d4569 into mui:next Jan 5, 2023
@cherniavskii cherniavskii deleted the autosizer-layout branch January 5, 2023 20:41
cherniavskii added a commit to cherniavskii/mui-x that referenced this pull request Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change 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 v6.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[DataGrid] Remove headerHeight prop
4 participants