javascript 如何更改 DataBound 事件上的网格列值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20630855/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change grid column value on DataBound event
提问by Gunaseelan
I have the following Grid,
我有以下网格,
<div class="kotgrid">
</div>
And I bound the data as following. Here I want to change timedelay
column value on DataBound event,
我将数据绑定如下。在这里,我想更改timedelay
DataBound 事件上的列值,
$(".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"
});
I don't know how to achieve it. Any help will be highly appreciable.
我不知道如何实现它。任何帮助将是非常可观的。
Thanks in advance.
提前致谢。
回答by Lars H?ppner
You don't need to iterate over the <tr>
elements, unless you only want to do it for the current page. You can just iterate over grid.dataSource.data().
So you could do something like:
您不需要迭代<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);
});
Regardless of how you get access to the dataItem
, you can set any property using the setmethod (the data source contains Model items which inherit from ObservableObject).
无论您如何访问dataItem
,都可以使用set方法设置任何属性(数据源包含从 ObservableObject 继承的模型项)。