Angular 6 Material Table Sticky Header doesn't work

十年热恋 提交于 2020-01-24 05:45:50

问题


I need to make the Header of the mat-table component fixed to the top, But It doesn't work.

I have Angular v6.1.7 and @angular/material v6.4.7.

I added the "sticky: true" propertie to the matHeaderRowDef as someone mentions here but it doesn't do anything :(

<tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>

I have this example project: https://stackblitz.com/edit/angular-wem2qa

This is my imports on the TS file:

import { Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild } from "@angular/core";
import { MatDialog, MatExpansionPanel, MatSnackBar, MatSort, MatTableDataSource, Sort } from "@angular/material";

回答1:


Your problem may be not the sticky row itself. You need to add a container around your table to make sure a row can be sticky at top with these styles for example:

.example-container {
  height: 400px;
  overflow: auto;
}

See example on Angular Material documentation: https://material.angular.io/components/table/overview#sticky-rows-and-columns and also check the CSS-tab.



来源:https://stackoverflow.com/questions/52707524/angular-6-material-table-sticky-header-doesnt-work

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!