将您定义DataSource
为:
var dataSource = new kendo.data.DataSource({
data : data,
schema: {
model: {
id : "Id",
fields: {
productName: { editable: false},
quantity : { editable: true, type : "number" },
price : { editable: false, type : "number" },
total : { editable: false, type : "number" }
}
}
}
});
您应该在其中添加一个total
字段quantity
times price
。
注意:此外,我已经定义了不同字段的类型,让 KendoUI 知道它们是数字并生成正确的小部件。
然后,定义grid
为:
$("#grid").kendoGrid({
dataSource: dataSource,
pageable : true,
height : 400,
toolbar : ["create"],
columns : [
{ field: "productName", title: "Product Name" },
{ field: "quantity", title: "Quantity", format: "{0:c}"},
{ field: "total", title: "Total", template: "#= quantity * price #", width: "150px" },
{ command: ["edit", "destroy"], title: " " }
],
editable : "popup"
});
我在其中添加了一个Total
使用模板的列,该模板是quantity * price
.
每次更新quantity
,total
都会得到updated
。
看到你在这里修改的代码