angular - Angular Material 粘性行不起作用
问题描述
您好,我遵循粘性标题行的角度材料文档示例https://material.angular.io/components/table/overview#sticky-rows-and-columns 但不适用于我。这是我的html代码
<div class="content mat-white-bg">
<mat-table #table [dataSource]="dataSource"
matSort matSortDirection="asc" matSortDisableClear>
<ng-container matColumnDef="Code">
<mat-header-cell *matHeaderCellDef mat-sort-header>
<mat-form-field>
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="{{'Kodi' | translate}}">
</mat-form-field>
<button (click)="sortTable($event.target.value)" mat-button class="mat-icon-button ">
<mat-icon>sort</mat-icon>
</button>
</mat-header-cell>
<mat-cell *matCellDef="let client">
<p class="text-truncate ">
{{client.Code}}
</p>
</mat-cell>
</ng-container>
<ng-container matColumnDef="FirstName">
<mat-header-cell *matHeaderCellDef mat-sort-header>
<mat-form-field>
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="{{'Emri' | translate}}">
</mat-form-field>
<button (click)="sortTable($event.target.value)" mat-button class="mat-icon-button">
<mat-icon>sort</mat-icon>
</button>
</mat-header-cell>
<mat-cell *matCellDef="let client">
<p class="text-truncate ">
{{client.FirstName}}
</p>
</mat-cell>
</ng-container>
<ng-container matColumnDef="Address">
<mat-header-cell *matHeaderCellDef mat-sort-header>
<mat-form-field>
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="{{'Adresa' | translate}}">
</mat-form-field>
<button (click)="sortTable($event.target.value)" mat-button class="mat-icon-button">
<mat-icon>sort</mat-icon>
</button>
</mat-header-cell>
<mat-cell *matCellDef="let client" fxHide fxShow.gt-sm>
<p class="text-truncate ">
{{client.Address}}
</p>
</mat-cell>
</ng-container>
<ng-container matColumnDef="City">
<mat-header-cell *matHeaderCellDef mat-sort-header fxHide fxShow.gt-sm>
<mat-form-field>
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="{{'Qyteti' | translate}}">
</mat-form-field>
<button (click)="sortTable()" mat-button class="mat-icon-button ">
<mat-icon>sort</mat-icon>
</button>
</mat-header-cell>
<mat-cell *matCellDef="let client" fxHide fxShow.gt-sm>
<p class="text-truncate ">
{{client.City}}
</p>
</mat-cell>
</ng-container>
<ng-container matColumnDef="Email">
<mat-header-cell *matHeaderCellDef mat-sort-header fxHide fxShow.gt-sm>
<mat-form-field>
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Email">
</mat-form-field>
<button (click)="sortTable()" mat-button class="mat-icon-button">
<mat-icon>sort</mat-icon>
</button>
</mat-header-cell>
<mat-cell *matCellDef="let client" fxHide fxShow.gt-sm>
<p class="email text-truncate">
{{client.Email}}
</p>
</mat-cell>
</ng-container>
<ng-container matColumnDef="Tel">
<mat-header-cell *matHeaderCellDef mat-sort-header fxHide fxShow.gt-sm>
<mat-form-field>
<input matInput (keyup)="applyFilter($event.target.value)" placeholder="Tel">
</mat-form-field>
<button (click)="sortTable()" mat-button class="mat-icon-button ">
<mat-icon>sort</mat-icon>
</button>
</mat-header-cell>
<mat-cell *matCellDef="let client" fxHide fxShow.gt-sm>
{{client.Tel}}
</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></mat-header-row>
<mat-row *matRowDef="let client; columns: displayedColumns;"
class="client"></mat-row>
</mat-table>
</div>
我已将sticky 设置为true,例如示例,但出现错误无法绑定到'matHeaderRowDefSticky',因为它不是'mat-header-row' 的已知属性
解决方案
该sticky
属性是在版本 6.3.0 中引入的。您可以升级@angular/material
并@angular/cdk
尝试解决您的问题
检查这个Github 问题
推荐阅读
- javascript - 无法捕获无效的表单正文错误 discord.js
- json - 如何在 Realm 版本 10.15.0 中将数据转换为 Json
- javascript - 如何重用一个类中定义的类方法,该类方法可以在打字稿中的另一个类中使用?
- r - R - 如何绘制生成的样本均值?
- reactjs - 访问被 CORS 阻止的 XMLHttpRequest,请求的资源上不存在“Access-Control-Allow-Origin”标头,仅用于 PUT 和 DELETE API
- sql - 如何使用 SQL 选择查询获取特定数据?
- java - 带有管理面板的图像和视频下载器应用程序以及 Android Studio 上的用户应用程序
- sql - 在 EF 6 中按两列选择 Min() 和其他列和 GroupBy
- jquery - 选择选项过滤无法正常工作
- performance - Spark“第一个”窗口功能比“最后一个”花费的时间长得多