angular - ng2-smart-table 派生列
问题描述
我需要通过计算两列的值在 ng2-smart-table 中创建一个自定义列。
我尝试使用 valuePrepareFunction() 但它不起作用
OrderQuantity:{
title: 'OrderQuantity',
},
UnitPrice:{
title: 'UnitPrice',
},
Total:{
title: 'Total',
type: 'custom',
//Need to get total by : OrderQuantity*UnitPrice
},
我需要通过 = OrderQuantity*UnitPrice 获得总值
解决方案
正如您所提到的,您可以通过使用 ng2-smart-table 中的 valuePrepareFunction 来做到这一点。
根据文档,将使用 2 个参数调用此函数:单元格、行。因此,您可以简单地使用它,如下所示。
settings = {
columns: {
OrderQuantity:{
title: 'OrderQuantity',
},
UnitPrice:{
title: 'UnitPrice',
},
Total:{
title: 'Total',
valuePrepareFunction :(cell, row) =>{
return row.OrderQuantity * row.UnitPrice;
}
}
}
}
推荐阅读
- javascript - JavaScript 显示内容
- mongodb - 如何在 Github Actions 构建脚本上使用基础镜像?
- libreoffice-calc - 假设 Libreoffice 中的值:如果输入单元格具有特定值,我可以使用计算的值计算公式吗?
- javascript - 正则表达式删除多于 on : 或
- python - 用非类型对象注释参数
- node.js - 如何减慢节点 JS 事件侦听器的速度?
- python - 如何在python中选择二维数组的索引?
- d3.js - 在聚集条形图上使用的居中 svg 图像
- mule - Mule CloudHub 部署 API 自动发现失败,代码为 412
- ios - SwiftUI Picker 填充问题 - 选择器中的 ForEach 循环不填充