我正在使用 Angular 4 和 Angular 材料来构建一张桌子。
我想要mat-sort-header
有条件地添加到以下模板中。
<mat-header-cell *matHeaderCellDef mat-sort-header>Id</mat-header-cell>
我尝试过以下代码:
<mat-header-cell *matHeaderCellDef [mat-sort-header]=" column!='id' ? column : false ">Id</mat-header-cell>
但它仍然在表中为此列添加排序标题。
我的整体表格如下所示,并且工作正常,除了排序标题问题:
<mat-table #table1 [dataSource]="records" matSort class="mat-cell">
<ng-container *ngFor="let column of keys" [matColumnDef]="column">
<mat-header-cell *matHeaderCellDef [mat-sort-header]=" column!='actions' ? column : false ">
<p *ngIf=" column!='actions' ">{{ column }}</p>
<button *ngIf=" column=='actions' " mat-icon-button color="primary" (click)="functionA()">
<mat-icon class="indigo-icon" aria-label="Example icon-button with a heart icon">add</mat-icon>
</button>
</mat-header-cell>
<mat-cell *matCellDef="let row; let i=index;">
<p *ngIf=" column!='actions' ">{{ row[column] }}</p>
<button *ngIf=" column=='actions' " mat-icon-button color="accent" (click)="functionA()">
<mat-icon class="indigo-icon" aria-label="Edit">edit</mat-icon>
</button>
<button *ngIf=" column=='actions' " mat-icon-button color="accent" (click)="functionA()">
<mat-icon class="indigo-icon" aria-label="Delete">delete</mat-icon>
</button>
</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="keys"></mat-header-row>
<mat-row *matRowDef="let row; columns: keys;"></mat-row>
</mat-table>
嗯,我解决了如下:
<mat-header-cell *matHeaderCellDef [mat-sort-header]=" column!='actions' ? column : null " [disabled]=" column=='actions' ? true : false " >
需要绑定disabled
财产。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)