Reputation: 143
Hi I've added a button to the toolbar of my KendoUI Grid, but I have a couple of issues, I'm hoping someone can assist with.
Uncaught ReferenceError: sendEmail is not defined.
I don't understand why it isn't seeing my function. Just for testing purposes I'm displaying an alert until it sees it.
toolbar: [
{ name: "create", text: "Add" },
{ template: "<input type='button' class='k-button' value='Email Users' onclick='sendEmail()' />",
imageclass: "k-icon k-i-pencil" }
]
function sendEmail() {
debugger;
alert('Send Emails');
}
Can someone please help?
Upvotes: 5
Views: 34096
Reputation: 666
There are many ways to use this. Please use below example.
toolbar: [
//{ template: kendo.template($("#k-tmpl-toolbar").html()) },
{ name: "Add", template: kendo.template("<button class='k-button k-button-sm k-rounded-md k-button-solid k-button-solid-primary' onclick='AddNewRecord()'>Add New</button>") },
{ name: "search" },
//{ name: "create", title: "New" },
],
Upvotes: 0
Reputation: 609
this works for me:
grid.find(".k-grid-toolbar").on("click", ".k-grid-myButton", function (e) { alert("it's work") ;});
Upvotes: 0
Reputation: 235
According to the documentation you would need to return the function that you want to occur on click. Like this:
template: '<a class="k-button" href="\\#" onclick="return toolbar_click()">Command</a>'
I hope that helps.
Upvotes: 3
Reputation: 39
Is your function sendEmail() initialized in document.ready or $(()=>{}); if not you will have to initialize it or else you could use this way
add a id for the button and write this in your document.ready (remove the onlcick from the button tag).
$("#examplebuttonid").click(()=>{
//write your code in here
});
Upvotes: -1
Reputation: 15387
You can Use as below:
toolbar: [
{
name: "Add",
text: "Send Email",
click: function(e){alert('Send Emails'); return false;}
}
],
Upvotes: 4