2

场景 我有一个产品详细信息网格,在编辑时会打开一个包含该记录详细信息的弹出窗口。除数量字段外,所有字段都是只读的。因此,当我增加或减少数量时,价格列应根据值反映。因此,如果 1 的数量为 10,那么当我将数量增加到 2 时,它应该反映为 20。

问题 1)我已经研究过编辑器方法,我必须在数量列上使用相同的方法对吗??

2)如何获取价格列的值并更新其值?有没有像编辑器这样的内置方法?我该怎么走??

以下是我准备的 JS fiddle。http://jsbin.com/ugeref/3/edit

谢谢!!

- 哈迪克

4

1 回答 1

2

将您定义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字段quantitytimes 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.

每次更新quantitytotal都会得到updated

看到你在这里修改的代码

于 2013-04-15T21:01:57.490 回答