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

相关内容

热门资讯

微乐小程序真的有挂!微乐广西麻... 微乐小程序真的有挂!微乐广西麻辣(开挂)软件-切实解迷有挂能透视中分为三种模型:模拟器、私人局有透视...
微乐小程序存在有挂!微乐自建房... 微乐小程序存在有挂!微乐自建房辅助软件(开挂)神器-切实透视是有挂1、该软件可以轻松地帮助玩家将辅助...
微乐小程序透视辅助!微乐小程序... 微乐小程序透视辅助!微乐小程序修复系统有用吗(开挂)器-原来辅助是真的挂1、实时透视辅助更新:用户可...
微信小程序黑科技免费!微乐家乡... 微信小程序黑科技免费!微乐家乡麻辣自建房(开挂)软件-一贯透视真的是有挂1、任何透视是真的假的的玩家...
微乐小程序黑科技免费!微信小程... 微乐小程序黑科技免费!微信小程序微乐跑得快技巧(开挂)技巧-总是揭幕存在有挂1、点击下载安装,脚本分...
微信小程序微乐破解器!微乐广西... 微信小程序微乐破解器!微乐广西小程序开挂(开挂)教程-好像解密真的有挂1、起透看视 辅助软件价格2、...
微乐小程序透视辅助!微乐手游辅... 微乐小程序透视辅助!微乐手游辅助脚本平台(开挂)方法-竟然分享真的有挂;辅助器是一种具有地方特色的麻...
微信小程序黑科技免费!微乐安徽... 微信小程序黑科技免费!微乐安徽小程序辅助(开挂)挂-确实曝光是真的挂1、在插件功能辅助器技巧中,中转...
微乐小程序存在有挂!微信小程序... 微乐小程序存在有挂!微信小程序自建房记牌器(开挂)挂-一直推荐真的有挂1、免费辅助多个强度级别选择2...
微乐小程序透视挂!微信小程序微... 微乐小程序透视挂!微信小程序微乐辅助器下载(开挂)攻略-切实揭露有挂1、游戏颠覆性的策略玩法,独创攻...