[英]add event listener for kendo grid command button
I am working on ASP.NET MVC4 application.In which i am using Kendo UI controls. 我正在使用ASP.NET MVC4应用程序。其中我使用的是Kendo UI控件。
I am using Kendo Grid.And i want to add event listener on Kendo Grid Toolbar's "add new item" button. 我正在使用Kendo Grid.And我想在Kendo Grid Toolbar的“添加新项目”按钮上添加事件监听器。
Below is the piece of the code of Grid command button: 下面是网格命令按钮的代码:
.ToolBar(commands =>
{
commands.Create();
commands.Save();
})
And i want to overrides its click event.Actually i want to check some condition on its click event.And if condition returns true then i want this button should enable otherwise it should be disable. 我想覆盖它的click事件。实际上我想检查其click事件的某些条件。如果condition返回true,那么我希望这个按钮应该启用,否则它应该被禁用。
I have tried to overrides it by some of the below codes but its not worked. 我试图通过以下一些代码覆盖它,但它没有用。
Example: 例:
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');
}); '
But none of above are working. 但上述都不奏效。
Can anyone suggest me the way for this? 任何人都可以建议我的方式吗?
Thanks 谢谢
Use a toolbar template to create your commands. 使用工具栏模板创建命令。 This allows you to specify a onClick event. 这允许您指定onClick事件。
.ToolBar(commands =>
commands.Template("<a class='k-button k-button-icontext' onclick='customCommand()' href='#'></span>Create</a>"))
Then you can do your checking in the js function customCommand(). 然后你可以在js函数customCommand()中进行检查。
More info on toolbar templates: http://docs.kendoui.com/api/web/grid#configuration-toolbar.template 有关工具栏模板的更多信息: http : //docs.kendoui.com/api/web/grid#configuration-toolbar.template
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.