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透视脚本,wepoker免费脚本咨询-都是真的有辅助神器(哔哩哔哩)1、游戏...
透视专业!wepoker透视脚... 透视专业!wepoker透视脚本免费app,wepoker怎么挂底牌-一直一直总是有辅助插件(哔哩哔...
透视推荐!wpk透视辅助,wp... 透视推荐!wpk透视辅助,wpk安卓下载辅助-一贯有辅助插件(哔哩哔哩)1、用户打开应用后不用登录就...
透视有挂!购买的wpk辅助在哪... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多玩家在这款游戏中打...
透视教你!wpk透视辅助方法,... 透视教你!wpk透视辅助方法,wpk插件-一贯是真的有辅助软件(哔哩哔哩)1、不需要AI权限,帮助你...
透视了解!aapoker怎么选... 透视了解!aapoker怎么选牌,aapoker透视脚本-原来一直都是有辅助app(哔哩哔哩)1、玩...
透视曝光!hhpoker辅助挂... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多玩家在这款游戏中打...
透视必备!如何下载wpk透视版... 透视必备!如何下载wpk透视版,有哪些免费的wpk作弊码-果然有辅助插件(哔哩哔哩)能透视中分为三种...
透视解谜!德普之星私人局辅助器... 透视解谜!德普之星私人局辅助器,德普之星透视辅助插件-好像存在有辅助方法(哔哩哔哩)1、打开软件启动...
透视解迷!wpk是真的还是假的... 透视解迷!wpk是真的还是假的,wpk透视辅助下载-切实是真的有辅助攻略(哔哩哔哩)破解侠是真的助透...