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

相关内容

热门资讯

黑科技插件!微乐小程序免费黑科... 黑科技插件!微乐小程序免费黑科技,微信小程序微乐辅助器脚本(透视)总是是有辅助插件(哔哩哔哩)所有人...
透视绝活儿!wpk俱乐部有没有... 透视绝活儿!wpk俱乐部有没有辅助(WePoKer软件)真是有辅助工具(哔哩哔哩)1、wpk俱乐部有...
透视好友房!微乐小程序黑科技,... 透视好友房!微乐小程序黑科技,微乐智能插件激活码(透视)本来是真的辅助技巧(哔哩哔哩)暗藏猫腻,小编...
透视方针!hhpoker脚本(... 透视方针!hhpoker脚本(WePoKer脚本)真是真的是有辅助方法(哔哩哔哩)该软件可以轻松地帮...
辅助透视!微乐小程序黑科技免费... 辅助透视!微乐小程序黑科技免费,微信微乐自建房脚本免费下载(透视)其实是真的辅助app(哔哩哔哩)所...
透视法子!wepoker有没有... 透视法子!wepoker有没有辅助(HHpoker透视挂)竟然真的是有辅助工具(哔哩哔哩)1)wep...
透视模拟器!微信微乐游戏辅助脚... 透视模拟器!微信微乐游戏辅助脚本,微乐自建房辅助入口官网(透视)好像是真的辅助器(哔哩哔哩)1、下载...
透视模块!pokemomo辅助... 透视模块!pokemomo辅助工具(WePoKer机器人)一贯是真的有辅助神器(哔哩哔哩)pokem...
透视ai!微乐小程序黑科技,微... 透视ai!微乐小程序黑科技,微乐自建房插件免费软件(透视)好像是有辅助工具(哔哩哔哩)该软件可以轻松...
透视秘籍!hhpoker有没有... 透视秘籍!hhpoker有没有作必弊挂(WePoKer规律)一直是真的有辅助技巧(哔哩哔哩);1、全...