如何使用外部按钮更新剑道网格上的多行 [英] How to update multiple rows on kendo grid with outside button
问题描述
我有一个Kendo网格,其列为:
I have a kendo grid with columns as:
我为关闭"按钮编写了一个函数,当用户通过选中选择行并单击关闭"按钮时,这会将IsClosed列自动更新为真"
i write a function for Close button, when user select rows by check and click Close button, this will auto update IsClosed Column to "True"
这是我的代码:
$(function () {
$('#btnClose').click(function () {
var grid = $('#grOrders').data("kendoGrid");
$.each($('#grOrders :checkbox:checked').closest('tr'), function () {
var data = grid.dataItem($(this));
data.set("IsClosed", true);
});
});
});
当我测试时,它只会更新检查的第一行,不知道为什么?请帮助我.
when i test, it only update a first row checked, don't know why? please help me.
推荐答案
问题在于,一旦调用set("IsClosed", true)
,KendoUI就会重新绘制网格,因此下一个grid.dataItem
将不会返回您期望的结果.
The problem is that as soon as you invoke a set("IsClosed", true)
KendoUI redraws the grid so next grid.dataItem
will not return what you expect.
相反,请尝试执行第一个each
以获得需要修改的项目列表,然后尝试第二个each
进行实际修改.像这样:
Instead, try doing a first each
for getting the list of items that need to be modified and then a second each
for actually modifying them. Something like:
$('#btnClose').click(function () {
var grid = $('#grid').data("kendoGrid");
var rows = $('#grid :checkbox:checked');
var items = [];
$.each(rows, function () {
var item = grid.dataItem($(this).closest("tr"));
items.push(item);
});
$.each(items, function(idx, elem) {
elem.set("IsClosed", true);
});
});
这篇关于如何使用外部按钮更新剑道网格上的多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!