angular - 选中复选框后动态显示 mat-table 行
问题描述
在选中第一列中的复选框后,我正在尝试使用 angular mat-table 在我的清单中显示下一步。
<table mat-table [dataSource]="checklist.checklistStepList" matSort>
<ng-container matColumnDef="checked">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Checked</th>
<td mat-cell *matCellDef="let step" *ngIf="displayStep(step)"><mat-checkbox [checked]="step.result==='CHECKED'" (change)="updateCheck(step)"></mat-checkbox></td>
</ng-container>
<ng-container matColumnDef="step">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Step</th>
<td mat-cell *matCellDef="let step" *ngIf="displayStep(step)">{{step.title}}</td>
</ng-container>
<ng-container matColumnDef="description">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Description</th>
<td mat-cell *matCellDef="let step" *ngIf="displayStep(step)">{{step.description}}</td>
</ng-container>
<ng-container matColumnDef="owner">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Owner</th>
<td mat-cell *matCellDef="let step" *ngIf="displayStep(step)">{{step.owner}}</td>
</ng-container>
<ng-container matColumnDef="date">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Date</th>
<td mat-cell *matCellDef="let step" *ngIf="displayStep(step)">{{step.date}}</td>
</ng-container>
<ng-container matColumnDef="assignment">
<th mat-header-cell *matHeaderCellDef mat-sort-header>Assignments</th>
<td mat-cell *matCellDef="let step" *ngIf="displayStep(step)">{{step.assignment}}</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="columnToDisplay"></tr>
<tr mat-row *matRowDef="let row; columns: columnToDisplay"></tr>
</table>
正如您在此处看到的,我正在尝试使用该函数隐藏/显示我的清单步骤,该函数displayStep(step)
只是一个告诉我是否应该显示该步骤并返回布尔值的函数。
这里的问题是我的step
参数无法识别。
我希望看到第一步的输出,然后在检查后显示下一步。
Stackblitz:https ://stackblitz.com/edit/angular-fwnnzf
解决方案
要隐藏未检查的行,您可以这样做
<tr mat-header-row *matHeaderRowDef="columnToDisplay"></tr>
<tr mat-row *matRowDef="let row; columns: columnToDisplay" [hidden]="!row.checked">
</tr>
[hidden]=true
同时隐藏它
你可以看到这个例子here
推荐阅读
- visual-studio-app-center - Xamarin UItest 是否支持本地?还是现在只适用于应用中心?
- python - Scrapy:meta['proxy'] 还是 meta['proxy']?
- grid - Extjs 可编辑网格将行推开
- python-3.7 - sys.executable 的 Python 3.7 无法识别的字符
- reactjs - lodash 的 isEqual 是提高 shouldComponentUpdate 性能的可行方法吗?
- list - 函数式编程 F# 中的列表递归
- security - Spring Boot Swagger REST Server Unreachable at Port 6000 由于 localhost not secure 错误
- ios - AKNodeRecorder 崩溃
- c++ - 在 C++ 中,堆分配对象内的堆栈对象在哪里分配?
- ios - JSON 可解码问题