ng2-smart-table 派生列

ng2-smart-table derived column

我需要通过计算两列的值在 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;
     } 
    }
}
}