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有... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款游戏中打...
指导大家!哈糖大菠萝辅助器,h... 指导大家!哈糖大菠萝辅助器,hhpoker哪个俱乐部靠谱,切实有挂(揭秘有挂)进入游戏-大厅左侧-新...
必备教程!pokernow辅助... 必备教程!pokernow辅助工具,aapoker透视脚本入口,竟然是真的有挂(有挂方式)1、操作简...
总算清楚!wepoker辅助分... 总算清楚!wepoker辅助分析器,wpk作弊最怕三个东西,好像真的是有挂(有挂技巧)1、点击下载安...
我来向大家传授!hhpoker... 我来向大家传授!hhpoker辅助靠谱吗,hhpoker有后台操控吗,切实是真的有挂(真的有挂)1、...
今日头条!fishpoker透... 今日头条!fishpoker透视,德扑圈透视,一直真的是有挂(有挂工具)1、打开软件启动之后找到中间...
玩家必看分享!hhpoker有... 玩家必看分享!hhpoker有透视功能吗,wepoker辅助真的假的,确实真的是有挂(存在有挂)1、...
推荐一款!HH平台挂,hhpo... 推荐一款!HH平台挂,hhpoker有后台操控吗,一贯真的有挂(有挂解密)1、下载好透视辅助下载之后...
玩家爆料!德扑圈透视挂,哈糖大... 玩家爆料!德扑圈透视挂,哈糖大菠萝免费辅助器,竟然是有挂(有挂规律)哈糖大菠萝免费辅助器透视方法中分...
带你了解!wepoker俱乐部... 带你了解!wepoker俱乐部辅助,hhpoker买挂,切实真的是有挂(有挂技巧)在进入软件靠谱后,...