gpt4 book ai didi

css - Angular 垫表 - 粘性标题不起作用

转载 作者:行者123 更新时间:2023-12-04 15:53:12 26 4
gpt4 key购买 nike

我正在使用 Angular Material 并希望有固定的标题。我已经看到很多解决方案,但没有一个适合我。

通常它应该通过将“sticky: true”添加到“mat-h​​eader-row *matHeaderRowDef=”来工作,但对我来说不是......我检查了我的 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”对我不起作用吗?

提前致谢

最佳答案

试试这个...添加<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;
}

关于css - Angular 垫表 - 粘性标题不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53060820/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com