2013-02-12 40 views
3

我正在使用编辑弹出框的模板。我试图强制网格进入编辑模式,并在单击其中一列中的链接时弹出编辑模板。Kendo Grid - 单击模板列时的编辑模式

我尝试使用命令,但我无法将超链接的文本绑定到模型中声明的字段,在本例中为'CourseType'。在命令列中是否支持数据绑定?

columns: [ 
    { 
     command: [ 
      { 
      id: "edit", 
      title: "School Item",  
      template: '<a href="\\#">#=CourseType#</a>', 
      width: 120 
      } 
     ] 
    } 
] 

如果命令列中不支持数据绑定,那么当单击模板字段时如何将网格置于编辑模式?

columns: [ 
    { 
    field: "CourseType", 
    title: "School Item", 
    template: '<a href="\\#">#=CourseType#</a>' 
    } 
] 

回答

2

我不知道你为什么要定义的电池作为HTML anchor但在制作上弹出编辑模式在锚点击时,它进入没有问题。

1)添加到您的模板class,这将允许我们找到这些单元格。例如:

columns: [ 
    { 
     field: "CourseType", 
     title: "School Item", 
     template: '<a href="\\#" class="ob-edit-popup">#=CourseType#</a>' 
    } 
] 

其中我已将class="ob-edit-popup"包括到模板中。

2)添加到您的网格定义选项editable: "popup"

3)初始化后添加下面的JavaScript代码。

$(".ob-edit-popup", grid.tbody).on("click", function (e) { 
    var row = $(this).closest("tr"); 
    grid.editRow(row); 
}) 

grid的结果是:

var grid = $("#grid").kendoGrid({...}).data("kendoGrid"); 
+0

完美,谢谢。 – Stuart 2013-02-12 23:51:06