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

How to add event listener to grid toolbar custom buttons or override default ones...

2 Answers 1832 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Cagatay
Top achievements
Rank 1
Cagatay asked on 22 Dec 2011, 04:07 PM
I know we can add custom buttons to toolbar of kendo grid but I coul not find how to add click event listener to these custom buttons ?

TIA

2 Answers, 1 is accepted

Sort by
1
Brandon
Top achievements
Rank 1
answered on 22 Dec 2011, 09:51 PM
This is how I did it, but I would like to know as well if there is a better way.

In my grid declaration:
toolbar: [{ text: "Add New Email", className: "k-grid-addEmail", imageClass: "k-add" },
{ text: "Add New Cell Text Message", className: "k-grid-addText", imageClass: "k-add" },
"save",
"cancel"],

Below that:

$(".k-grid-addEmail").bind('click', function () {
        var grid = $("#gridEmailAddress").data("kendoGrid");
        grid.addRow();
        var newrowdata = grid.dataItem(grid.tbody.find(">tr:first"));
        newrowdata.Address = "";
        newrowdata.Name = "New Email";
        newrowdata.StatusTypes = $.parseJSON(JSON.stringify(initStatusTypes));
        grid.refresh();
        grid.editCell(grid.tbody.find(">tr>td:first"));
    });


One problem I noticed with this was that the Validation for the "Name" cell wasn't getting called unless the user manually clicked in it to edit the cell.

Ideally I would prefer to just have a function get called after the "default function" for "Add" gets called to populate some default data.

Or maybe there is a way to specific the default data?  I'm not an expert (yet).
0
Cagatay
Top achievements
Rank 1
answered on 28 Dec 2011, 04:32 PM
Thanks...
Tags
Grid
Asked by
Cagatay
Top achievements
Rank 1
Answers by
Brandon
Top achievements
Rank 1
Cagatay
Top achievements
Rank 1
Share this question
or