【问题标题】:ng2-smart-table derived columnng2-smart-table 派生列
【发布时间】:2020-01-03 18:34:13
【问题描述】:

我需要通过计算两列的值在 ng2-smart-table 中创建一个自定义列。

我尝试使用 valuePrepareFunction() 但它不起作用

    OrderQuantity:{
      title: 'OrderQuantity',
    },
    UnitPrice:{
      title: 'UnitPrice',
    },
    Total:{
      title: 'Total',
      type: 'custom',
      //Need to get total by : OrderQuantity*UnitPrice
    },

我需要通过 = OrderQuantity*UnitPrice 获得总值

【问题讨论】:

    标签: angular ng2-smart-table


    【解决方案1】:

    正如你提到的,你可以通过使用 ng2-smart-table 中的 valuePrepareFunction 来做到这一点。

    根据文档,此函数将使用 2 个参数调用:单元格、行。因此,您可以简单地使用它,如下所示。

    settings = {
    columns: {
    OrderQuantity:{
          title: 'OrderQuantity',
        },
        UnitPrice:{
          title: 'UnitPrice',
        },
        Total:{
          title: 'Total',
          valuePrepareFunction :(cell, row) =>{
              return row.OrderQuantity * row.UnitPrice;
         } 
        }
    }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-07-08
      • 1970-01-01
      • 2019-01-08
      • 2019-04-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-21
      • 2018-05-12
      相关资源
      最近更新 更多