angular - ng2-smart-table 派生列

标签 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 获取总值(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/

相关文章:

css - ng2-智能表 : how to use css?

angular - ng2-smart-table 动态更新列表

css - 如何在 ng2-smart-table 上显示自定义图标?

angular - 在 DataTable Angular 中排序格式化日期

Angular 5 编译速度很慢,有时内存不足

html - 如何在 Angular 上呈现原始 HTML

angular - 执行 router.navigate 后刷新组件

Angular 2 ng2-智能表:issue while catch the data from custom button event

javascript - 发布请求时未经授权的 401 Windows 身份验证 + Core 2.2 WebAPI

html - 如何在 Angular 6 应用程序中使用滚动条插件?