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

相关内容

热门资讯

透视解迷"aapok... 透视解迷"aapoker怎么设置提高好牌几率"确实是有辅助器(哔哩哔哩)aapoker怎么设置提高好...
现场直击"菠萝辅助器... 现场直击"菠萝辅助器免费版的特点"aapoker透视脚本(竟然是真的辅助修改器)-哔哩哔哩1、下载好...
透视曝光"pokem... 透视曝光"pokemmo手机脚本辅助器"切实真的是有辅助挂(哔哩哔哩)1、超多福利:超高返利,海量正...
目前来看"wepok... 目前来看"wepoker轻量版透视方法"pokermaster辅助器(总是是真的辅助工具)-哔哩哔哩...
透视开挂"wepok... 透视开挂"wepoker有透视功能吗"本来是有辅助技巧(哔哩哔哩)1、玩家可以在wepoker有透视...
透视总结"智星德州可... 透视总结"智星德州可以透视吗"wepoker辅助工具(果然是真的辅助下载)-哔哩哔哩1、起透看视 智...
透视解密"wepok... 您好,wepoker透视挂底牌这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054...
透视软件"hhpok... 透视软件"hhpoker德州机器人"拱趴大菠萝万能辅助器(切实真的有辅助平台)-哔哩哔哩1、很好的工...
透视必备"wepok... 透视必备"wepoker破解器有用吗"好像有辅助教程(哔哩哔哩)该软件可以轻松地帮助玩家将wepok...
透视真的"werpl... 透视真的"werplan有挂吗"拱趴大菠萝辅助神器(其实真的有辅助软件)-哔哩哔哩;所有人都在同一条...