AngularMaterial@ViewChildMatTable:如何更新表格?
创始人
2024-10-28 08:01:15
0
  1. 首先,在组件的类中使用ViewChild来引用MatTable组件。 import { MatTable } from '@angular/material/table'; @ViewChild(MatTable) table: MatTable;

  2. 接下来,您可以通过调用MatTable的renderRows方法来强制组件重新渲染表格以更新数据。 this.table.renderRows();

下面是一个完整的示例代码: import { Component, OnInit, ViewChild } from '@angular/core'; import { MatTable } from '@angular/material/table';

@Component({ selector: 'app-my-component', templateUrl: './my-component.component.html', styleUrls: ['./my-component.component.css'] }) export class MyComponentComponent implements OnInit { displayedColumns: string[] = ['position', 'name', 'weight', 'symbol']; dataSource = ELEMENT_DATA;

@ViewChild(MatTable) table: MatTable;

constructor() { }

ngOnInit(): void { }

updateTableData() { // Here you can update the data source of the table this.dataSource.push({position: 5, name: 'Hydrogen', weight: 1.0079, symbol: 'H'});

// This will render the updated data on the table
this.table.renderRows();

}

}

请注意,此示例代码假定您已经在组件中定义了要显示在表格中的列和数据。此外,当您更改数据源时,只需调用renderRows方法即可更新表格。

相关内容

热门资讯

wepoker透视脚本免费使用... wepoker透视脚本免费使用视频!poker world辅助器(透视)软件-一贯教你存在有挂1、不...
pokemmo辅助工具!wep... pokemmo辅助工具!wepoker辅助分析器(透视)器-总是推荐存在有挂1、玩家可以在wepok...
wepoker透视辅助!we-... wepoker透视辅助!we-poker是什么软件(透视)工具-本来总结有挂1、起透看视 we-po...
wepoker有用吗!佛手在线... wepoker有用吗!佛手在线大菠萝智能辅助器(透视)器-其实辅助是真的挂1、每一步都需要思考,不同...
wpk俱乐部辅助器!约局吧德州... wpk俱乐部辅助器!约局吧德州可以透视吗(透视)脚本-一贯详细是真的挂1、上手简单,内置详细流程视频...
约局吧德州真的有透视挂吗!wp... 约局吧德州真的有透视挂吗!wpk辅助哪里买(透视)技巧-本来必备是真的挂1、起透看视 约局吧德州真的...
sohoo poker辅助器!... sohoo poker辅助器!扑克之星辅助(透视)技巧-本来详情真的是有挂1、sohoo poker...
wepoker透视脚本!wpk... wepoker透视脚本!wpk私人辅助(透视)app-都是曝光有挂wepoker透视脚本破解侠是真的...
智星菠萝有挂吗!德州局hhpo... 智星菠萝有挂吗!德州局hhpoker(透视)工具-都是专业真的是有挂1、智星菠萝有挂吗辅助器安装包、...
aapoker俱乐部靠谱吗!w... aapoker俱乐部靠谱吗!wepokerplus开挂(透视)教程-竟然教你是有挂;1、金币登录送、...