Reputation: 157
I followed the example on the Angular Material website to create a table with multiple sticky header rows. This works perfectly. But, when I take the table and move it inside a tab, only one of the rows sticks as I scroll down. Can this be fixed?
https://stackblitz.com/edit/angular-bklajw-3zzcw7
Notice how when you scroll down in the first table, the first two rows stick. But when you scroll down in the second table, only the second row sticks.
Upvotes: 2
Views: 3450
Reputation: 171
You can explicitly apply position: sticky
and setting top
equals to height of the above row for the second-row header i.e. top: 56px
, and this will make the second-row header also sticky. This is the CSS you need to add.
.mat-header-row:nth-child(2) {
position: sticky;
top: 56px;
}
And here is the forked example with this change applied. https://angular-bklajw-rqkyjm.stackblitz.io
Thank you.
Upvotes: 3
Reputation: 3055
Sticky positions are applied at run time. You can try to fix it using css.
<tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true" class="second-row"></tr>
.second-row .mat-header-cell.mat-table-sticky {
top: 55px !important;
}
Working example:- https://angular-bklajw-rwgxn9.stackblitz.io
Not the cleanest of solution but will get the work done.
Upvotes: 0