使用带有 Flex 的粘性柱的 Angular 6 mat-table 不起作用

标签 angular flexbox angular-material sticky

我使用的是 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/

相关文章:

Angular 2隐藏或显示子组件

angular - 模拟 Angular Material Dialog afterClosed() 用于单元测试

angular - Angular Material 7 中的多个日期选择

javascript - 无法读取 Angular 中未定义的属性 'find'?

javascript - 有没有办法隐藏没有标题的确认框

angular - 如何在 Component 中使用管道

javascript - 使用过滤器函数从 API 返回过滤结果列表

CSS Flexbox - CSS 网格中的截断文本(仅限 Firefox)

html - 为什么 flex 元素包裹而不是收缩?

css - Safari 中的 Flexbox : Grow and shrink