【问题标题】:How do I add a custom column to angular material table?如何将自定义列添加到角度材料表?
【发布时间】:2020-06-10 08:10:34
【问题描述】:

目前,我的数据源中有 4 列。我想对从其中一列收到的数据执行一些操作,然后将该数据添加到表中的新列中。有没有办法做到这一点?

【问题讨论】:

  • 可以用map修改数据。这更像是一个打字稿动作而不是角度。
  • 您可能需要修改数据源并重新渲染表格
  • @Amit,我该怎么做?我修改了数据源,但是在我的角度表中看不到新的列数据。
  • 我没有使用角材料。但是您可以触发 refresh() 方法来更新您的网格

标签: angular angular-material


【解决方案1】:

您可以在将数据设置为 dataSource 之前对其进行更改。 例如,如果你得到一些可观察的 http 数据,你可以这样做:

this.data$ = this.certificateService.certificates$.pipe(
        map(data => {
          data.column5 = data.column4 // and make all other calculations
          return data;
       })
);

然后您可以订阅数据并将其设置在数据源中

 this.data$.subscribe(data => {
   this.dataSource = new MatTableDataSource(data)
 })

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-07
    • 2015-12-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多