2013-06-04 39 views
1

我需要在网格行和细节视图上绑定一些事件。我正在使用可观察的视图模型,并注册了一些事件,并试图使用行模板和详细信息模板将它们绑定到DOM。到目前为止没有进展。绑定Kendo网格事件

$("#grid").kendoGrid({ 
    sortable:true, 
    rowTemplate:'<tr class="k-master-row"> 
     <td class="k-hierarchy-cell"><a class="k-icon k-plus" href=""></a></td> 
     <td><a data-bind:"click:highlight">click in row ${id}</a></td><td>${bool}</td> 
    </tr>', 
    detailTemplate:'<a data-bind:"click:highlight">click In details ${id}</a>', 
    columns: [{field:'id',sortable:false}, {field:'bool'}], 
    dataBound: function(e) { 
     var grid=$("#grid").data('kendoGrid'); 
     grid.expandRow("tr.k-master-row"); 
    } 
}); 


var model=({ 
    highlight:function(){ 
     console.log(this.id); 
    }, 
    items:[{id: 1123, bool: true}, {id: 223, bool: false}] 
}); 
kendo.bind($("#grid"),kendo.observable(model)); 

这是jsFiddle http://jsfiddle.net/amGmr/9/。使用MVVM有没有可能使用网格绑定事件?

+0

你弄清楚该怎么办呢?你可以请张贴答案吗? – Lijo

回答

4

您应指定您希望通过数据绑定属性绑定到事件和事件的结合:

<div data-role="grid" 
    data-bind="source: dataSource, events:{dataBound: dataBound, detailInit: detailInit}" 
></div> 

<script> 
var viewModel = kendo.observable({ 
    dataBound: function(e) { 
     var grid = e.sender; // `this` is the viewModel instance 
    }, 
    detailInit: function(e) { 
     var grid = e.sender; // `this` is the viewModel instance 
    }, 
    dataSource: [ 
     { name: "John Doe" }, 
     { name: "Jane Doe" } 
    ] 
}); 
</script> 
+0

这不适用于我使用kendo v2015.2.805我也试过在网格创建之前的选项上定义dataBound处理程序的非mvvm方法。 – War

+0

鉴于解决方案无法解决点击:突出显示事件问题。 – Ashish