0

我正在开发 ASP.NET MVC4 应用程序。我在其中使用 Kendo UI 控件。

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

下面是网格命令按钮的一段代码:

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

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

我试图用下面的一些代码覆盖它,但它不起作用。

例子:

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');
 }); '

但以上都不起作用。

任何人都可以建议我这样做吗?

谢谢

4

1 回答 1

2

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

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

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

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

于 2013-07-31T13:34:18.560 回答