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] add position sticky to DataGrid columns (header) on scroll down #5189

Closed
2 tasks done
ShadiBlitz opened this issue Jun 13, 2022 · 7 comments
Closed
2 tasks done
Labels
component: data grid This is the name of the generic UI component, not the React module! customization: css Design CSS customizability duplicate This issue or pull request already exists support: question Community support but can be turned into an improvement

Comments

@ShadiBlitz
Copy link

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Current behavior 😯

No response

Expected behavior 🤔

I would like to achieve a sticky position for the DataGrid Columns header when scrolling down the page. Basically, all I want is when i scroll down and the table still has content is to see the columns header stuck on the top of the page, so I know what are the headers of each columns are. And for the sticky header to be gone when i scroll down and passed all the table content.

Steps to reproduce 🕹

I have tried the following but did not work :

https://codesandbox.io/s/datagriddemo-demo-mui-x-forked-0hq08f?file=/demo.tsx

Context 🔦

No response

Your environment 🌎

`npx @mui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @mui/envinfo` goes here.

Order ID 💳 (optional)

No response

@ShadiBlitz ShadiBlitz added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Jun 13, 2022
@alexfauquette
Copy link
Member

It seems to be possible as follow, but not recomended

export const StyledDataGrid = styled(DataGrid)(({ theme }) => ({
  "& .MuiDataGrid-main": {
    // remove overflow hidden overwise sticky does not work
    overflow: "unset"
  },
  "& .MuiDataGrid-columnHeaders": {
    position: "sticky"
  },
  "& .MuiDataGrid-virtualScroller": {
    // remove the space left for the header
    marginTop: "0!important"
  }
}));

https://codesandbox.io/s/datagriddemo-demo-mui-x-forked-6izdkg?file=/demo.tsx

@alexfauquette alexfauquette 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! customization: css Design CSS customizability and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Jun 14, 2022
@ShadiBlitz
Copy link
Author

ShadiBlitz commented Jun 15, 2022

Thanks for you reply! @alexfauquette
I tried to do the same inside a layout, but keep getting horizontal scroll on the page. I am suspecting it has to do with display: 'flex'.

https://codesandbox.io/s/persistentdrawerleft-demo-material-ui-forked-s1g7sq?file=/demo.tsx

What is causing that ? I tried to fix but had no luck..

@alexfauquette
Copy link
Member

I put a fix width to the data grid container and it works find, so it must be a CSS problem. I will not have time to have a deeper look into it.
https://codesandbox.io/s/persistentdrawerleft-demo-material-ui-forked-yekcfm?file=/demo.tsx

For generic question, you may find help on StackOverflow which has a much larger community

@zigang93
Copy link
Contributor

zigang93 commented Mar 17, 2023

using custom css, it break at v6..

@cherniavskii
Copy link
Member

This was also asked in #7588 (comment)
For the v6, see this demo: https://codesandbox.io/s/datagriddemo-demo-mui-x-forked-vj6msf?file=/demo.tsx

I'll add this demo to our column headers docs.

@KenanYusuf
Copy link
Member

@cherniavskii think we can close this? Seems like a duplicate of #15466 if I am understanding correctly.

@cherniavskii
Copy link
Member

Duplicate of #15466

@cherniavskii cherniavskii marked this as a duplicate of #15466 Jan 2, 2025
@cherniavskii cherniavskii closed this as not planned Won't fix, can't repro, duplicate, stale Jan 2, 2025
@github-actions github-actions bot added the duplicate This issue or pull request already exists label Jan 2, 2025
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! customization: css Design CSS customizability duplicate This issue or pull request already exists support: question Community support but can be turned into an improvement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants