This is a migrated thread and some comments may be shown as answers.

How to bind a function to a custom Toolbar onclick?

1 Answer 335 Views
Grid
This is a migrated thread and some comments may be shown as answers.
dave
Top achievements
Rank 1
dave asked on 13 Aug 2012, 10:06 PM
I want to create a custom toolbar. Here is my code:

toolbar:[{
    text: "Go to Add User Page",
    className: "k-grid-custom",
    imageClass: "k-add"
}],

function createUser(){
alert('Hello World');
}

I want to call the function named createUser when this button is clicked. How to make it possible?

1 Answer, 1 is accepted

Sort by
0
dave
Top achievements
Rank 1
answered on 14 Aug 2012, 02:45 PM
No one seems to be helping. Anyway i already figured it out.

function test(e){
      return '<a class="k-button" href="#" id="toolbar-add_user" onclick="test_fn()">Add User</a>';
 };
function test_fn(){
        window.location = "http://www.google.com";
};
 toolbar:[{
        name:'add_user',
        template:'#= test()#'
}],

1. First i had to make a function to be able to customize the button and add an onclick event.
2. Then i had to make a new function to listen to the event.

Tags
Grid
Asked by
dave
Top achievements
Rank 1
Answers by
dave
Top achievements
Rank 1
Share this question
or