How to update multiple rows on kendo grid with outside button

守給你的承諾、 提交于 2019-12-11 06:36:46

问题


I have a kendo grid with columns as:

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"

and this is my code:

$(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.


回答1:


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.

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);
    });
});


来源:https://stackoverflow.com/questions/26727676/how-to-update-multiple-rows-on-kendo-grid-with-outside-button

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!