components icon indicating copy to clipboard operation
components copied to clipboard

[Table] Add input for sticky headers

Open andrewseguin opened this issue 9 years ago • 24 comments

Add an input to <cdk-table> that makes the table's header stick to the top of the scroll container.

Interim solution: Use styles position: sticky; top: 0 on the header element.

andrewseguin avatar Jul 19 '17 21:07 andrewseguin

@kal93 Currently working on it right now. We're going the route of using position: sticky. It leaves IE out of the race but it's much more efficient than us coming up with a custom solution that would be less efficient than letting the browser handle it.

Here's a stackblitz that I'm using to play with the idea: https://stackblitz.com/edit/angular-vttjfe?file=app%2Fhello.component.html

andrewseguin avatar Apr 25 '18 18:04 andrewseguin

@pantonis I did this in my styles.css

You may need to look at the styles on the parent container if this doesn't work (eg. display or flex settings) - but this works quite nicely for me until there's an official update.

/* Table header row */
mat-header-row {
    /*https://github.com/angular/material2/issues/5885*/
    position: sticky;
    top: -.5px;
    background: white;
    z-index: 100;
}

Thanks much. It worked like gem

kamalSaiDd avatar Dec 03 '18 19:12 kamalSaiDd

For now, here's a fun solution. Separate your table into two - the first won't show any rows, and the second won't display the header. Make the overflow scroll only on the rows.

@andrewseguin Creative, but filtering and sorting becomes an issue with this solution. This issue was opened in Jul 2017 - has there been any progress on scrolling just the body of the table? Looking for something exactly like the complex example here: https://v0.material-ui.com/#/components/table

ryansperzel1 avatar Apr 04 '19 19:04 ryansperzel1

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.