css - 带粘性标题的 Angular Material 表

标签 css angular typescript angular-material

我将 angular7 与 Angular Material 设计模板一起使用。目前,我的结果如下, enter image description here

但我希望我的结果如下。粘性标题下的滚动条。

enter image description here

我放了一些演示代码和live demo作为引用。

HTML

<div class="example-container mat-elevation-z8">
  <table mat-table [dataSource]="dataSource">

    <!-- Position Column -->
    <ng-container matColumnDef="position">
      <th mat-header-cell *matHeaderCellDef> No. </th>
      <td mat-cell *matCellDef="let element"> {{element.position}} </td>
    </ng-container>

    <!-- Name Column -->
    <ng-container matColumnDef="name">
      <th mat-header-cell *matHeaderCellDef> Name </th>
      <td mat-cell *matCellDef="let element"> {{element.name}} </td>
    </ng-container>

    <!-- Weight Column -->
    <ng-container matColumnDef="weight">
      <th mat-header-cell *matHeaderCellDef> Weight </th>
      <td mat-cell *matCellDef="let element"> {{element.weight}} </td>
    </ng-container>

    <!-- Symbol Column -->
    <ng-container matColumnDef="symbol">
      <th mat-header-cell *matHeaderCellDef> Symbol </th>
      <td mat-cell *matCellDef="let element"> {{element.symbol}} </td>
    </ng-container>

    <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
    <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
  </table>
</div>

CSS

.example-container {
  height: 400px;
  overflow: auto;
}

table {
  width: 100%;
}

最佳答案

您可以使用两个表来做类似的事情,一个用于标题,另一个用于数据。请参阅工作 demo .

关于css - 带粘性标题的 Angular Material 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58618143/

相关文章:

angular - 错误 : Cannot create the component ComponentClass as it was not imported into the testing module

node.js - 在 TypeScript 中创建 swagger web 服务的正确方法是什么

javascript - 在选定区域插入新节点时,Slate.js 会引发错误

javascript - 如何使用 Angular 6 中的库发布指定已发布的 package.json?

css - 如何使用CSS将鼠标悬停在文本上

jquery - 如何在 bootstrap 3 中禁用 col-sm 和 col-xs。

css - 获取 div 占据 100% 的主体高度,减去固定高度的页眉和页脚

Angular 4 - 在每个请求上设置 withCredentials - cors cookie

typescript - 通用 keyof 约束 : must be a key of specific type of object

html - 在 mozilla 中,我的按钮看起来不像在 chrome 中显示的那样好