我需要通过计算两列的值在 ng2-smart-table 中创建自定义列。
我尝试使用 valuePrepareFunction() 但它不起作用
OrderQuantity:{
title: 'OrderQuantity',
},
UnitPrice:{
title: 'UnitPrice',
},
Total:{
title: 'Total',
type: 'custom',
//Need to get total by : OrderQuantity*UnitPrice
},
我需要通过 = OrderQuantity*UnitPrice 获取总值(value)
最佳答案
正如您提到的,您可以通过使用 ng2-smart-table 中的 valuePrepareFunction 来完成此操作。
根据文档,该函数将使用 2 个参数调用:单元格、行。因此,您可以简单地使用它,如下所示。
settings = {
columns: {
OrderQuantity:{
title: 'OrderQuantity',
},
UnitPrice:{
title: 'UnitPrice',
},
Total:{
title: 'Total',
valuePrepareFunction :(cell, row) =>{
return row.OrderQuantity * row.UnitPrice;
}
}
}
}
关于angular - ng2-smart-table 派生列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57727852/