Kendo Grid - 单击模板化列时的编辑模式

时间:2013-02-12 17:12:32

标签: kendo-ui 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>'
  }
]

1 个答案:

答案 0 :(得分: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");
相关问题