简体   繁体   English

角度垫表-粘性标题不起作用

[英]Angular mat-table - sticky header doesn't works

I am using Angular Material and want to have fixed headers. 我正在使用Angular Material,并希望具有固定的标题。 I saw many solutions already, but none works for me. 我已经看到了许多解决方案,但是没有一个适合我。

Normally it should work by adding "sticky: true" to the "mat-header-row *matHeaderRowDef=", but not for me... I checked my Angular Material & Angular CDK version, they are up-to-date. 通常,它应该通过在“ mat-h​​eader-row * matHeaderRowDef =“上添加“ sticky:true”来工作,但对我而言不行。我检查了我的Angular Material和Angular CDK版本,它们是最新的。

html: HTML:

<mat-table #table [dataSource]="dataSource">

  <ng-container matColumnDef="fromTo">
    <mat-header-cell *matHeaderCellDef> Absender/Empfänger </mat-header-cell>
    <mat-cell *matCellDef="let entry">{{entry.customer.shownName}} </mat-cell>
  </ng-container>

  <ng-container matColumnDef="forwarder">
    <mat-header-cell *matHeaderCellDef> Spediteur </mat-header-cell>
    <mat-cell *matCellDef="let entry"> {{entry.forwarder.shownName}} </mat-cell>
  </ng-container>

  <ng-container matColumnDef="binType">
    <mat-header-cell *matHeaderCellDef> BehälterTyp </mat-header-cell>
    <mat-cell *matCellDef="let entry"> {{entry.bin.name}} </mat-cell>
  </ng-container>

  <ng-container matColumnDef="inboundQty">
    <mat-header-cell *matHeaderCellDef> Eingang </mat-header-cell>
    <mat-cell *matCellDef="let entry"> {{entry.inboundQty}} </mat-cell>
  </ng-container>

  <ng-container matColumnDef="outboundQty">
    <mat-header-cell *matHeaderCellDef> Ausgang </mat-header-cell>
    <mat-cell *matCellDef="let entry"> {{entry.outboundQty}} </mat-cell>
  </ng-container>

  <ng-container matColumnDef="comment">
    <mat-header-cell *matHeaderCellDef> Kommentar </mat-header-cell>
    <mat-cell *matCellDef="let entry"> {{entry.comment}} </mat-cell>
  </ng-container>

  <ng-container matColumnDef="user">
    <mat-header-cell *matHeaderCellDef> Benutzer </mat-header-cell>
    <mat-cell *matCellDef="let entry"> {{entry.user.email}} </mat-cell>
  </ng-container>

  <mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></mat-header-row>
  <mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>

package.json: 的package.json:

  "@angular/cdk": "^7.0.0",
    "@angular/material": "^7.0.0",

any idea why "sticky:true" doesn't works for me? 知道为什么“ sticky:true”对我不起作用吗?

Thanks in advance 提前致谢

Try this... Add <div class="example-container><div> 试试这个...添加<div class="example-container><div>

<div class="example-container >
  <mat-table #table [dataSource]="dataSource">

  <ng-container matColumnDef="fromTo">
    <mat-header-cell *matHeaderCellDef> Absender/Empfänger </mat-header-cell>
    <mat-cell *matCellDef="let entry">{{entry.customer.shownName}} </mat-cell>
  </ng-container>

  <ng-container matColumnDef="forwarder">
    <mat-header-cell *matHeaderCellDef> Spediteur </mat-header-cell>
    <mat-cell *matCellDef="let entry"> {{entry.forwarder.shownName}} </mat-cell>
  </ng-container>

  <ng-container matColumnDef="binType">
    <mat-header-cell *matHeaderCellDef> BehälterTyp </mat-header-cell>
    <mat-cell *matCellDef="let entry"> {{entry.bin.name}} </mat-cell>
  </ng-container>

  <ng-container matColumnDef="inboundQty">
    <mat-header-cell *matHeaderCellDef> Eingang </mat-header-cell>
    <mat-cell *matCellDef="let entry"> {{entry.inboundQty}} </mat-cell>
  </ng-container>

  <ng-container matColumnDef="outboundQty">
    <mat-header-cell *matHeaderCellDef> Ausgang </mat-header-cell>
    <mat-cell *matCellDef="let entry"> {{entry.outboundQty}} </mat-cell>
  </ng-container>

  <ng-container matColumnDef="comment">
    <mat-header-cell *matHeaderCellDef> Kommentar </mat-header-cell>
    <mat-cell *matCellDef="let entry"> {{entry.comment}} </mat-cell>
  </ng-container>

  <ng-container matColumnDef="user">
    <mat-header-cell *matHeaderCellDef> Benutzer </mat-header-cell>
    <mat-cell *matCellDef="let entry"> {{entry.user.email}} </mat-cell>
  </ng-container>

  <mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></mat-header-row>
  <mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
  </mat-table>
</div>

Add this CSS 添加此CSS

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM