-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[docs] Add sticky column header demo #8297
Conversation
Netlify deploy previewNetlify deploy preview: https://deploy-preview-8297--material-ui-x.netlify.app/ Updated pagesThese are the results for the performance tests:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional Improvement: Not perfect (2px top border + a small cut around edges) but this may possibly improve the look and feel a bit during the scroll of the sticky header 🤔
diff --git a/docs/data/data-grid/column-header/StickyColumnHeader.tsx b/docs/data/data-grid/column-header/StickyColumnHeader.tsx
index 1d10e0a12..c666ef5e7 100644
--- a/docs/data/data-grid/column-header/StickyColumnHeader.tsx
+++ b/docs/data/data-grid/column-header/StickyColumnHeader.tsx
@@ -1,9 +1,20 @@
import * as React from 'react';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
+import { alpha, darken, lighten, Theme } from '@mui/material/styles';
import { DataGrid, gridClasses } from '@mui/x-data-grid';
import { useDemoData } from '@mui/x-data-grid-generator';
+function getBorderColor(theme: Theme) {
+ if (theme.vars) {
+ return theme.vars.palette.TableCell.border;
+ }
+ if (theme.palette.mode === 'light') {
+ return lighten(alpha(theme.palette.divider, 1), 0.88);
+ }
+ return darken(alpha(theme.palette.divider, 1), 0.68);
+}
+
export default function StickyColumnHeader() {
const { data: commodityData } = useDemoData({
dataSet: 'Commodity',
@@ -35,6 +46,7 @@ export default function StickyColumnHeader() {
},
[`.${gridClasses.columnHeaders}`]: {
position: 'sticky',
+ borderTop: `1px solid ${getBorderColor(theme)}`,
top: 0,
backgroundColor: theme.palette.background.paper,
zIndex: 1,
@@ -57,6 +69,7 @@ export default function StickyColumnHeader() {
},
[`.${gridClasses.columnHeaders}`]: {
position: 'sticky',
+ borderTop: `1px solid ${getBorderColor(theme)}`,
top: 0,
backgroundColor: theme.palette.background.paper,
zIndex: 1,
}); | ||
|
||
return ( | ||
<Box sx={{ width: '100%', height: 350, overflow: 'auto' }}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look good on Windows:
First I have to scroll vertically to be able to scroll horizontally.
What do you think of removing height: 350, overflow: 'auto'
and let the content expand freely? The drawback is that the column headers will be hidden under the docs' toolbar, but we can use top: 65
and put a message explaining that top: 0
should be used outside the MUI website.
It feels more natural without the terrible looking scrollbars.
when would this be merged? would be an amazing feature |
Thanks @Joren-vanGoethem for the feedback, we will try to push this forward as soon as we can, though this is not a new feature and just a demo build on top of the existing Grid. |
This is an awesome demo! Found a small issue with pinned columns where the column content appears on top of the header. pinned.mp4Demo: https://codesandbox.io/s/datagriddemo-demo-mui-x-forked-nwfmzm?file=/demo.tsx |
I'm blind, you can set |
@MBilalShafi thanks for the StickyHeaders demo - This is no longer available in v7.3 release - https://github.com/mui/mui-x/tree/master/docs/data/data-grid/column-header |
@pymenow This has not been merged at all, and lately, we did a lot of improvements around column headers which now use |
@MBilalShafi thanks for the update. The fundamental issue is headers are not sticky when we use auto height. |
That's an interesting point. May I understand more about the use-case where having the header row sticky + using the @romgrk Please feel free to add something that I may have missed. |
True -> To me, it seems the required behavior, since the autoHeight expands the container to the height that all the rows take, due to which there's no scroll on the rows container itself, but the whole page gets scrolled. use-case where having the header row sticky + using the autoHeight prop : When you set a fixed height and go to last page where there are only 1-2 rows , then auto height is needed as against 1st page where you may have enough rows to fit the selected height . |
I don't think this sticky column header thing is possible in Data Grid v7. |
Closes #5189
Closes #7588
Preview: https://deploy-preview-8297--material-ui-x.netlify.app/x/react-data-grid/column-header/#sticky-column-header