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

[Table] Sticky header in group #23090

Closed
2 tasks done
idrm opened this issue Oct 16, 2020 · 7 comments · Fixed by #23100
Closed
2 tasks done

[Table] Sticky header in group #23090

idrm opened this issue Oct 16, 2020 · 7 comments · Fixed by #23100
Labels
component: table This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation ready to take Help wanted. Guidance available. There is a high chance the change will be accepted

Comments

@idrm
Copy link

idrm commented Oct 16, 2020

When the stickyHeader option is enabled on a Table and the table contains multiple header rows, only the last of the rows ends up being sticky.

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

Only the last of the header rows is sticky.

Expected Behavior 🤔

All header rows should be sticky.

Steps to Reproduce 🕹

https://codesandbox.io/s/ymv2c

Tech Version
Material-UI v4.11.0
@idrm idrm added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 16, 2020
@oliviertassinari oliviertassinari added the component: table This is the name of the generic UI component, not the React module! label Oct 16, 2020
@oliviertassinari
Copy link
Member

Yeah, I think that you would need to set a different top position for each row of the header group. We also have mui/mui-x#195 in the pipeline.

@oliviertassinari
Copy link
Member

oliviertassinari commented Oct 16, 2020

          <TableHead>
            <TableRow>
              <TableCell align="center" colSpan={columns.length}>
                Another header row
              </TableCell>
            </TableRow>
            <TableRow>
              <TableCell
                style={{ top: 57 }}
                align="center"
                colSpan={columns.length}
              >

https://codesandbox.io/s/material-demo-forked-g12em?file=/demo.tsx

@oliviertassinari oliviertassinari removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 16, 2020
@oliviertassinari oliviertassinari changed the title Quirky behavior with sticky-header tables and multiple header rows [Table] Sticky header in group Oct 16, 2020
@oliviertassinari
Copy link
Member

We can probably improve the documentation for this aspect. It's also not obvious to find the group example introduced for #17909.

@oliviertassinari oliviertassinari added docs Improvements or additions to the documentation ready to take Help wanted. Guidance available. There is a high chance the change will be accepted labels Oct 16, 2020
@idrm
Copy link
Author

idrm commented Oct 16, 2020

Thanks for the quick heads-up. The custom styling did the trick. I presume it's not possible to apply the stickiness props to the <thead> element itself in order to avoid the custom top offset styling.

@oliviertassinari
Copy link
Member

I presume it's not possible to apply the stickiness props to the element itself in order to avoid the custom top offset styling.

It's not possible, to apply the sticky position on the thead, as far as I know. This would have been ideal.

@kkomelin
Copy link

As simple as this:

  <Table>
    <TableHead sx={{ position: 'sticky', top: 0, backgroundColor: 'white' }}>
      <TableRow></TableRow>
      <TableRow></TableRow>
      <TableRow></TableRow>
    </TableHead>
   </Table>

No stickyHeader, no pain.

@juliushuck
Copy link

juliushuck commented Jan 14, 2024

This works for me. I still use the stickyHeader prop to get the correct visual styles. I also change the background color of the header to white by using the themes background paper variable.

<TableContainer sx={{ height: "100%" }}>
    <Table size="small" stickyHeader>
        <TableHead
            sx={{
                position: "sticky",
                top: 0,
                zIndex: 1,
                "& .MuiTableCell-root": { backgroundColor: "background.paper" },
            }}
        >

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: table This is the name of the generic UI component, not the React module! docs Improvements or additions to the documentation ready to take Help wanted. Guidance available. There is a high chance the change will be accepted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants