Reloading kendo ui grid the row item code executes an error

安稳与你 提交于 2019-12-02 14:37:55

问题


I've a web application with kendo ui grid. The grid is load with Bakbone.js when I click a button and I can remove a row with the next code:

$(document).on("click", "#grid tbody tr .ob-delete", function (e) {
    var item = grid.dataItem($(this).closest("tr"));
    var check = confirm("Do I delete:" + item.City );
    if (check) {
        grid.removeRow($(this).closest("tr"));
    }
});

The cofiguration of the button to delete:

 command: [
            "edit", {
            name: "destroy",
            text: "Remove",
            className: "ob-delete"
        }]

When I reload the content (grid) pushing the button, if I want to delete a row, item.City produce an error.

The complete example here

Edited: Solved here! Thanks to @Whizkid747!

To add in

command: [ "edit",{ 
      //...
      click: deleteRow
}] 

Then, when button is clicked a function is called:

function deleteRow(e){
        var item = this.dataItem($(e.currentTarget).closest("tr"));
         var check = confirm("Do I delete:" + item.City );
        if (check) {
            grid.removeRow($(e.currentTarget).closest("tr"));
        }
    } 

回答1:


Not sure, but your grid is actually not the same grid but the old (before the reload) one and second grid is created.

Following line changed:

var item = $('#grid').data().kendoGrid.dataItem($(this).closest("tr"));

updated version.

I suggest you to just change the data through the dataSource.data() method instead of recreating the Grid. Or change your logic so you actually destroy the widget before recreating it.



来源:https://stackoverflow.com/questions/14892406/reloading-kendo-ui-grid-the-row-item-code-executes-an-error

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