我正在使用Angular Material,并希望具有固定的标题。 我已经看到了许多解决方案,但是没有一个适合我。
通常它应该通过在“ mat-header-row * matHeaderRowDef =“上添加“ sticky:true”来工作,但对我来说不行。 我检查了我的Angular Material和Angular CDK版本,它们是最新的。
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:
"@angular/cdk": "^7.0.0",
"@angular/material": "^7.0.0",
知道为什么“ sticky:true”对我不起作用吗?
预先感谢
答案 0 :(得分:0)
尝试一下...
添加<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>
添加此CSS
.example-container {
height: 400px;
overflow: auto;
}