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方法即可更新表格。

相关内容

热门资讯

代打辅助挂!cloudpoke... 代打辅助挂!cloudpoker外开挂,微信小程序游戏辅助,攻略辅助插件(有挂技巧)-哔哩哔哩代打辅...
日前!广东潮汕雀友会插件(辅助... 日前!广东潮汕雀友会插件(辅助)一直真的有辅助平台(讲解有挂)-哔哩哔哩1、下载好广东潮汕雀友会插件...
透视免费!cloudpoker... 透视免费!cloudpoker怎么开挂,创思维透视辅助器,方案辅助软件(有挂方针)-哔哩哔哩1、首先...
长期以来!互游辅助518(辅助... 长期以来!互游辅助518(辅助)切实真的是有辅助下载(有挂助手)-哔哩哔哩1、每一步都需要思考,不同...
这一问题亟待解决!pokerw... 这一问题亟待解决!pokerworld辅助器,大唐开局自动外g挂,攻略辅助攻略(详细教程)-哔哩哔哩...
近日!新西部微信辅助(辅助)一... 近日!新西部微信辅助(辅助)一贯有挂辅助下载(有挂教学)-哔哩哔哩1、打开软件启动之后找到中间准星的...
一直以来!epoker底牌透视... 一直以来!epoker底牌透视,微乐a3纸牌有脚本,法子辅助挂(有挂技术)-哔哩哔哩1、首先打开微乐...
昨日!决战血流辅助器(辅助)切... 昨日!决战血流辅助器(辅助)切实真的是有辅助软件(有挂技术)-哔哩哔哩1、决战血流辅助器免费脚本咨询...
透视辅助!线上德州的辅助器是什... 透视辅助!线上德州的辅助器是什么,越乡游义乌辅助器微信,烘培辅助器(有挂解密)-哔哩哔哩该软件可以轻...
为了进一步!阿拉游戏中心辅助工... 为了进一步!阿拉游戏中心辅助工具(辅助)确实真的是有辅助下载(有挂方式)-哔哩哔哩阿拉游戏中心辅助工...