Kendo ui网格中具有批处理编辑的计算列

时间:2019-12-30 01:57:23

标签: jquery kendo-ui kendo-grid

我在剑道网格here中有剑道简单演示。

  1. price会根据quantity的值而变化,这是一个问题,如果quantity更改为1,如何恢复默认值?

  2. 以及如何制作价格列editable:false? (如果设置为true,则价格列将无法动态更改)。

full demo in dojo

save: function(e) {    
  if (e.values.hasOwnProperty("quantity")){
    var current_qty = e.values.quantity;
    var current_price = e.model.price;

    var totalPrice = current_price * current_qty;
    e.model.set('price', totalPrice);

    if(e.values.quantity == 1){
      console.log('set back to default value') ;
    }   
  }
}

2 个答案:

答案 0 :(得分:1)

我在这里找到了这个article可能会有所帮助,在这里demo发现了这个(如果有人需要的话)。基本上,我创建了一个虚拟字段,并且save事件分配了总价。

答案 1 :(得分:0)

这是设置列的方式,该列具有计算所得的字段且不可编辑。

columns: [
     { field: "quantity", title: "quantity", format: "{0:c}" },
     { field: "current_price", title: "current_price", format: "{0:c}" },
     { title: "totalPrice", template: "<span>#= quantity * current_price #</span>", editable: false }],