简体   繁体   English

角材料表动态行

[英]Angular material table dynamic rows

I am creating a project using angular and material.我正在使用角度和材料创建一个项目。 In my project i want to add customised footer row in material table on click of button and delete that row on click of delete button.在我的项目中,我想在单击按钮时在材料表中添加自定义页脚行,并在单击删除按钮时删除该行。

Here is my code:这是我的代码:

https://stackblitz.com/edit/angular-dshjiz-beqnrj?file=src/app/table-basic-example.html https://stackblitz.com/edit/angular-dshjiz-beqnrj?file=src/app/table-basic-example.html

You need to push data in datasource您需要在数据源中推送数据

this.dataSource.data.push({id: 1, name: 'test'})

There is stackblitz examplestackblitz 的例子

You need to push data as mentioned by Armen.您需要像Armen 提到的那样推送数据。 You also need to call renderRows() method of the table as per suggestion https://material.angular.io/components/table/overview#1-write-your-mat-table-and-provide-data您还需要根据建议调用表格的 renderRows() 方法https://material.angular.io/components/table/overview#1-write-your-mat-table-and-provide-data

Please check your updated stackblitz example请检查您更新的stackblitz 示例

Same method can be implemented to delete the row.可以实现相同的方法来删除行。 Just make sure the renderRows method calls everytime the table updates.只要确保每次表更新时都会调用 renderRows 方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM