为kendo grid命令按钮添加事件监听器

时间:2013-07-31 11:05:20

标签: events override toolbar kendo-grid commandbutton

我正在使用ASP.NET MVC4应用程序。我使用的是Kendo UI控件。

我正在使用Kendo Grid。我想在Kendo Grid Toolbar的“添加新项目”按钮上添加事件监听器。

以下是网格命令按钮的代码:

 .ToolBar(commands =>
               {
                   commands.Create();
                   commands.Save();
           })

我想覆盖它的click事件。实际上我想检查其click事件的某些条件。如果condition返回true,那么我希望这个按钮应该启用,否则它应该被禁用。

我试图通过以下某些代码覆盖它,但它没有用。

示例:

1)  '$(".k-button.k-button-icontext.k-grid-add").bind("click", function () {   
     alert('add link event');
 });

2)   $(".k-grid-Add").on('click',function () {    
     alert("Hello");
});

 3)   $(".k-button.k-button-icontext.k-grid-add").on("click", function () {   
     alert('add link event');
 }); '

但上述情况均无效。

  
    

有人能建议我这样做吗?

  

由于

1 个答案:

答案 0 :(得分:2)

使用工具栏模板创建命令。这允许您指定onClick事件。

.ToolBar(commands => 
 commands.Template("<a class='k-button k-button-icontext' onclick='customCommand()' href='#'></span>Create</a>"))

然后你可以在js函数customCommand()中进行检查。

有关工具栏模板的更多信息:http://docs.kendoui.com/api/web/grid#configuration-toolbar.template

相关问题