如何更改DataBound事件上的网格列值

时间:2013-12-17 09:50:05

标签: javascript html kendo-ui kendo-grid

我有以下网格,

<div class="kotgrid">
</div>

我将数据绑定如下。在这里,我想更改DataBound事件的timedelay列值,

$(".kotgrid").kendoGrid({
    dataSource: dataSource, 
    dataBound: function (e) {
        var grid = this;
        grid.tbody.find('>tr').each(function () {
            var dataItem = grid.dataItem(this);
            var d = new Date();
            var currentTime = parseTime(dataItem.servertime);
            var currenTime = d.getHours() + ":" + d.getMinutes();
            var meanTime = diff(orderTime2, currenTime2)
            //I want to set this meanTime in timedelay coloumn. How can I achieve this?
        })
    },
    filterable: true,
    scrollable: true,
    columns: [
                   { hidden: true, field: "orderitemid" },
                   { field: "tableid", title: "Table No" },
                   { field: "itemname", title: "Items" },
                   { field: "quantity", title: "Quantity" },
                   { field: "modifier", title: "Modifier" },
                   { hidden: true, field: "orderedtime", title: "Time Delay" },
                   { field: "timedelay", title: "Time Delay" },
                   { hidden: true, field: "alert" },
                   { hidden: true, field: "category", groupHeaderTemplate: "#= value #" },
                   { command: { text: "Pickup", click: showDetails} }
             ],
    mobile: "phone",
    editable: false,
    selectable: "row",
    height: "600px"
});

我不知道如何实现它。任何帮助都会非常值得一提。

提前致谢。

1 个答案:

答案 0 :(得分:5)

您不需要遍历<tr>元素,除非您只想对当前页面执行此操作。你可以迭代grid.dataSource.data()。 所以你可以这样做:

var data = this.dataSource.data();
$(data).each(function() {
    var d = new Date();
    var currentTime = parseTime(this.servertime);
    var currenTime = d.getHours() + ":" + d.getMinutes();
    var meanTime = diff(orderTime2, currenTime2)
    // set on dataItem
    this.set("timedelay", meanTime);
});

无论您如何访问dataItem,都可以使用set方法设置任何属性(数据源包含继承自ObservableObject的模型项)。