如何在角度材料表中添加自定义列? [英] How do I add a custom column to angular material table?
本文介绍了如何在角度材料表中添加自定义列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当前,我的数据源中有4列.我想对从某列中接收到的数据执行一些操作,然后将该数据添加到表中的新列中.有什么办法吗?
Currently, I have 4 columns in my data source. I want to perform some operations from the data I receive from one of the columns, and then add that data to a new column in the table. Is there any way to do that?
推荐答案
您可以在将数据设置为dataSource之前对其进行更改. 例如,如果您可以观察到一些http数据,则可以执行以下操作:
You could make changes in data before setting it to dataSource. For example, if you get some http data as observable, you could do:
this.data$ = this.certificateService.certificates$.pipe(
map(data => {
data.column5 = data.column4 // and make all other calculations
return data;
})
);
然后您可以订阅数据并将其设置在数据源中
Then you could subscribe on data and set it in datasource
this.data$.subscribe(data => {
this.dataSource = new MatTableDataSource(data)
})
这篇关于如何在角度材料表中添加自定义列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文