Kendo-Knockout: Calling a method that changes viewmodel property from a template with data-binding inside a grid, breaks bindings

混江龙づ霸主 提交于 2019-12-01 11:52:51

Using Knockout templates inside of the grid is not fully supported at this point. Right now your row is bound, because the elements are there when Knockout first passes over the document to apply bindings.

After the data is updated, the rows are re-rendered and the bindings are lost.

One fix is to use an event handler for the "dataBound" event that rebinds the table. This could be done globally, something like:

ko.bindingHandlers.kendoGrid.options.dataBound = function(data) {
    var body = this.element.find("tbody")[0];

    if (body) {
       ko.applyBindings(ko.dataFor(body), body);   
    }
};

Here is a sample: http://jsfiddle.net/rniemeyer/5Zkyg/

I also added a custom binding that prevents Knockout from binding the table on the first pass, so that it is not bound twice (once overall applyBindings and once from the dataBound handler.

Ultimately, this is something that I want to support better in Knockout-Kendo and it is the next thing that I plan to work on with the library.

Here is a sample of how it might work from a branch that I had started a while back: http://jsfiddle.net/rniemeyer/xBL2B/

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