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

Toolbar template button click event

2 Answers 1774 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Hans-Jürgen
Top achievements
Rank 1
Veteran
Hans-Jürgen asked on 16 Feb 2021, 03:59 PM

Hey,

I'm using a template to get a button into my grid toolbar since my atempt to write it analog to teh treelist doesn't work. But I can't access the click event. I want to open a custom create-dialog for grid items.

For the treelist i use something like this:

toolbar: [{
 
imageClass: 'k-i-plus',
name: 'createPosition',
text: 'New',
click() {
$('#newItemDialog').data('kendoDialog').open();
},
},
'search',
]

 

Since this doesn't seem to work I tried this but can't access the click-event:

 

$myGrid.kendoGrid({
        dataSource: myDatasource,
        columns: [
        ....
        ],
        toolbar: [
            {
                template: '<a class="k-button" href="\\#" id="newItemButton" ">New</a><span class="k-textbox k-grid-search k-display-flex"><input autocomplete="off" placeholder="Search..." title="Search..." class="k-input"><span class="k-input-icon"><span class="k-icon k-i-search"></span></span></span>'
            }
        ],
       
    }).after(() => {
        $('newItemButton').kendoButton({
            icon: 'k-i-plus',
            click: onNewClick
        });
    });
 
function onNewClick() {
    $('#newItemDialog').data('kendoDialog').open();
}

2 Answers, 1 is accepted

Sort by
0
Accepted
Mihaela
Telerik team
answered on 18 Feb 2021, 10:08 AM

Hello Hans-Jürgen,

Thank you for sharing the code snippets.

While I was investigating them, I have noticed that the "#" is missing in the jQuery selector of the 'newItemButton' in the after() method (inserted below in blue font):

.after(() => {
  $('#newItemButton').kendoButton({
     icon: 'k-i-plus',
     click: onNewClick
   });
});

Would you try to add it and ensure that the click event is triggered accordingly?

In case further assistance is needed, let me know.

 

Regards, Mihaela Lukanova Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Hans-Jürgen
Top achievements
Rank 1
Veteran
answered on 18 Feb 2021, 01:23 PM

Head->Desk

Yes, that was it. Now I feel stupid ^^;

Thank you for your help!

Tags
Grid
Asked by
Hans-Jürgen
Top achievements
Rank 1
Veteran
Answers by
Mihaela
Telerik team
Hans-Jürgen
Top achievements
Rank 1
Veteran
Share this question
or