angular - 角材料 - 垫表动态页脚/标题 rowDef
问题描述
我正在尝试有条件地显示footer-row
我的垫子表。
基于这个讨论,我知道不知何故,我必须用removeFooterRowDef
它来删除它,我猜addFooterRowDef
还是setFooterRowDef
带来另一个。
但是我找不到关于如何使用其中之一的正确解释。
请注意,我已尝试将页脚行包装在 ng 容器中。
<ng-container *ngIf="hasFooter">
<tr mat-footer-row *matFooterRowDef="footerRowDef"></tr>
<ng-container>
但即使hasFooter
是假的,该行仍然存在。
解决方案
根据这个问题的答案,我发现它与viewChild
模板中的like结合使用,有
<ng-container>
<tr *matFooterRowDef="columns" mat-footer-row></tr>
</ng-container>
并在组件类中
@ViewChild(MatFooterRowDef, {static: true}) footerDef: MatFooterRowDef;
@ViewChild(MatTable, {static: true}) table: MatTable;
removeFooter() {
this.table.removeFooterRowDef(this.footerDef);
}
addFooter() {
this.table.setFooterRowDef(this.footerDef);
}
要添加新的页脚,我们会调用addFooterRowDef
,但我会调用setFooterRowDef
来覆盖任何现有的页脚。
所有其他方法都以相同rowDef
的headerRowDef
方式工作。而且columnDef
,我猜。
如果有人需要,我把它留在这里。
推荐阅读
- typo3 - 网格元素为空
- swift - 调整 UIImage 的大小以适应 Swift 中的 UIImageView
- r - 如何生成所有国家的 10x10km 网格单元?
- dart - Dart中如何根据多个条件过滤和移除Lists中的Maps
- python - 我的数组没有存储 while 循环中的值
- reactjs - 反应中具有展开折叠扩展的 Cytoscape 引发错误
- python - 从父类覆盖类方法而不影响下游类
- matlab - 使用 Matlab 设置树莓派蓝牙
- angular - TypeError: common.ɵsetRootDomAdapter is not a function 。服务 ssr 后面临问题
- plugins - 如何向strapi上传插件添加额外的字段?