components icon indicating copy to clipboard operation
components copied to clipboard

Fixed header in mat-table

Open jayakrishna-v opened this issue 8 years ago • 20 comments

Bug, feature request, or proposal: It would be good if we can have a fixed header for mat-table.

What is the expected behavior? Header should always be visible even while scrolling the table body.

What is the current behavior? When the mat-table body is scrolled, the header is also getting scrolled along with the body and getting hidden.

What are the steps to reproduce?

Check the official mat-table link below. https://material.angular.io/components/table/overview

What is the use-case or motivation for changing an existing behavior?

When we had to show more than 50 records per page, user will have to scroll down to see the bottom records. When we scroll down, header should stay static on top of the table and it helps the user to easily identify which column is what.

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Is there anything else we should know?

jayakrishna-v avatar Dec 28 '17 06:12 jayakrishna-v

No working sample available

jayakrishna-v avatar Dec 28 '17 06:12 jayakrishna-v

.mat-header-row {
    position: sticky;
    top: 0;
    background-color: inherit;
}

oktav777 avatar Dec 28 '17 07:12 oktav777

@oktav777 You should also include position: -webkit-sticky for Safari browsers.

.mat-header-row {
    position: sticky;
    position: -webkit-sticky;
    top: 0;
    background-color: inherit;
}

EdricChan03 avatar Dec 28 '17 07:12 EdricChan03

@Chan4077 preprocessor should autoprefix it.

oktav777 avatar Dec 28 '17 07:12 oktav777

@oktav777 the css work .but if the hearder has selection,when scroll the below will occur

before scoll: tim 20171228154817

when scroll: tim 20171228154732

ghost avatar Dec 28 '17 07:12 ghost

Thanks oktav and Chan. The css works fine. But not working in IE 11

jayakrishna-v avatar Dec 28 '17 07:12 jayakrishna-v

@stevenmi add z-index so it looks like:

.mat-header-row {
    top: 0;
    position: sticky;
    z-index: 1;
    background-color: inherit;
}

@jayakrishna-v position: sticky is not supported in IE. If you really need IE, you have to override the styles or change the layout of tables.

oktav777 avatar Dec 28 '17 08:12 oktav777

ok. I have a basic question. Does Angular Material support IE browsers?

jayakrishna-v avatar Dec 28 '17 08:12 jayakrishna-v

@jayakrishna-v Yes, IE11 is supported, see here

oktav777 avatar Dec 28 '17 08:12 oktav777

ok. Thank you

jayakrishna-v avatar Dec 28 '17 08:12 jayakrishna-v

i have tried with solution you have provided to fix mat-tab-header , but not working

jainubaba25 avatar May 19 '18 04:05 jainubaba25

Solution does not work if the table is inside mat-sidenav-container. Any suggestion?

soumyakantiroychowdhury avatar Nov 24 '18 13:11 soumyakantiroychowdhury

@soumyakantiroychowdhury did you find a solution?

charlieshawfeather avatar Dec 10 '18 00:12 charlieshawfeather

@Ch4osCosmo I did not try after that. Will post here if I get a solution.

soumyakantiroychowdhury avatar Dec 10 '18 09:12 soumyakantiroychowdhury

is there a fix for this?

rubenheymans avatar Dec 26 '18 18:12 rubenheymans

Try this:

::ng-deep .mat-tab-header {
  top: 0;
  position: sticky !important;
  z-index: 999 !important;
  background-color: white;
}

mattspaulding avatar Jan 16 '19 22:01 mattspaulding

I want to make the first four columns as sticky. Is there any way in angular mat-table??

pavithra0116 avatar Jun 21 '19 12:06 pavithra0116

<tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr> Tried this solution on @angular/material 8.1.4 . It's working

vankadn avatar Sep 10 '19 15:09 vankadn

I don't understand why would you say Angular Material is compatible with IE 11, if the property 'sticky: true' of mat table's header is not working in IE 11 ?

In addition I see a case where we would need fixed position on header (and not sticky). Suppose you have a fixed header. Setting sticky table's headers would cause them to stick underneath the fixed header, making it invisible.

louis-rogeon avatar Sep 17 '19 14:09 louis-rogeon

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.