Toolbar template button click event

3 posts, 1 answers
  1. Hans-Jürgen
    Hans-Jürgen avatar
    9 posts
    Member since:
    Feb 2020

    Posted 16 Feb Link to this post

    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. Answer
    Mihaela
    Admin
    Mihaela avatar
    41 posts

    Posted 18 Feb Link to this post

    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/.

  3. Hans-Jürgen
    Hans-Jürgen avatar
    9 posts
    Member since:
    Feb 2020

    Posted 18 Feb in reply to Mihaela Link to this post

    Head->Desk

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

    Thank you for your help!

Back to Top