【问题标题】:Angular 6 mat-table using sticky column with flex does not workAngular 6 mat-table 使用带有 flex 的粘性列不起作用
【发布时间】:2019-05-11 04:00:45
【问题描述】:

我正在使用角度 7,材质 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>

mat-row-header 声明为 min-width 以添加水平滚动

我的每一列都有特定的宽度,使用如下代码

flex: 0 0 50px;

有解决这个问题的办法吗?

【问题讨论】:

    标签: angular flexbox angular-material sticky


    【解决方案1】:

    我终于解决了这个问题。

    在版本7.1.1 中更改了材料设计。

    为了使用粘性列,您需要使用&lt;table mat-table&gt;&lt;/table&gt; 标签而不是&lt;mat-table&gt;&lt;/mat-table&gt;&lt;th mat-header-cell&gt;,&lt;td mat-cell&gt; 而不是&lt;mat-header-cell&gt;&lt;mat-cell&gt;

    这就是我的桌子现在的样子:

    <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>
    

    【讨论】:

    • 你好,我想问一下当有 2 列需要粘性时,你的粘性列会发生什么情况?桌子乱了吗?
    • 不,我做到了,而且效果很好,你用的是哪个浏览器和什么版本?
    • 嘿,我猜列的宽度有问题
    【解决方案2】:

    如果我们对表格宽度进行一些更改,角度材料将不起作用,所以基本上我把这个 css 放在使所有列的宽度相同

    .mat-header-cell, .mat-footer-cell, .mat-cell {
      min-width: 100px;
      box-sizing: border-box;
      text-align: center;
    
    }
    

    现在它可以工作了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-26
      • 2019-04-05
      • 1970-01-01
      • 2019-10-01
      • 2018-07-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多