我使用的是 Angular 7, Material 7
我尝试对特定列使用粘性,但它不起作用,
标题变得粘滞,但单元格却没有。
我的 html 如下所示:
<mat-table [dataSource]="dataSourceVaccinations" matSort>
<ng-container matColumnDef="Gender" sticky>
<mat-header-cell *matHeaderCellDef mat-sort-header></mat-header-cell>
<mat-cell *matCellDef="let GetSummaryRecordsVaccinations">
<img [attr.src]="getGenderIcon(Gender)" />
</mat-cell>
</ng-container>
<ng-container matColumnDef="IdentityNumber" sticky>
<mat-header-cell *matHeaderCellDef mat-sort-header> מס' זהות </mat-header-cell>
<mat-cell *matCellDef="let GetSummaryRecordsVaccinations" > {{IdentityNumber}} </mat-cell>
</ng-container>
<ng-container matColumnDef="CodeVaccinationsAllowed">
<mat-header-cell *matHeaderCellDef mat-sort-header> ניתן לחסן סיכום </mat-header-cell>
<mat-cell *matCellDef="let GetSummaryRecordsVaccinations">
<img [attr.src]="getIcon(CodeVaccinationsAllowed)"/> </mat-cell>
</ng-container>
<ng-container matColumnDef="שפעת">
<mat-header-cell *matHeaderCellDef> שפעת </mat-header-cell>
<mat-cell *matCellDef="let GetSummaryRecordsVaccinations">
<div class="center">{{ClassDescription}}
<br/>{{VaccinationDate | date:'dd/MM/yyyy'}}
</div>
</mat-cell>
</ng-container>
<mat-header-row class="mat-row-header-vaccination" *matHeaderRowDef="displayedVaccinationsAllColumns; sticky:true"></mat-header-row>
<mat-row class="mat-row-vaccination" *matRowDef="let row; columns: displayedVaccinationsAllColumns;" (click)="selection.select(row)"></mat-row>
</mat-table>
使用 min-width
声明 mat-row-header
以添加水平滚动
我的每一列都有特定的宽度,使用如下代码
flex: 0 0 50px;
有什么办法可以解决这个问题吗?
最佳答案
我终于解决了这个问题。
Material 设计在版本 7.1.1
中发生了变化。
为了使用粘性列,您需要使用 <table mat-table></table>
标签而不是 <mat-table></mat-table>
和<th mat-header-cell>
, <td mat-cell>
而不是<mat-header-cell>
和<mat-cell>
这就是我的表格现在的样子:
<table mat-table [dataSource]="dataSourceVaccinations" matSort>
<ng-container matColumnDef="Gender" sticky>
<th mat-header-cell *matHeaderCellDef mat-sort-header></th>
<td mat-cell *matCellDef="let GetSummaryRecordsVaccinations">
<img [attr.src]="getGenderIcon(Gender)" />
</td>
</ng-container>
<ng-container matColumnDef="IdentityNumber" sticky>
<th mat-header-cell *matHeaderCellDef mat-sort-header> מס' זהות </th>
<td mat-cell *matCellDef="let GetSummaryRecordsVaccinations" > {{IdentityNumber}} </td>
</ng-container>
<ng-container matColumnDef="CodeVaccinationsAllowed">
<th mat-header-cell *matHeaderCellDef mat-sort-header> ניתן לחסן סיכום </th>
<td *matCellDef="let GetSummaryRecordsVaccinations">
<img [attr.src]="getIcon(CodeVaccinationsAllowed)"/> </td>
</ng-container>
<ng-container matColumnDef="שפעת">
<th mat-header-cell *matHeaderCellDef> שפעת </th>
<td mat-cell *matCellDef="let GetSummaryRecordsVaccinations">
<div class="center">{{ClassDescription}}
<br/>{{VaccinationDate | date:'dd/MM/yyyy'}}
</div>
</td>
</ng-container>
<tr mat-header-row class="mat-row-header-vaccination" *matHeaderRowDef="displayedVaccinationsAllColumns; sticky:true"></tr>
<tr mat-row class="mat-row-vaccination" *matRowDef="let row; columns: displayedVaccinationsAllColumns;" (click)="selection.select(row)"></tr>
</table>
关于使用带有 Flex 的粘性柱的 Angular 6 mat-table 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53702517/