What else do I need to make kendo grid's custom toolbar command work?

t3chb0t

I need to add a custom toolbar command to my kendo-grid so I searched the kendo-ui documentation about the grid#configuration-toolbar where I found that:

If an Array value is assigned (to a toolbar property), it will be treated as the list of commands displayed in the grid's Toolbar. Commands can be custom or built-in ("cancel", "create", "save", "excel", "pdf").

and I created a custom command for my toolbar (suggested also in this question Adding custom button to KendoGrid Toolbar Issue)

toolbar: [
    {
        name: "copyRows",
        text: "Copy Rows",
        click: function (e) {
            alert('test');
        }
    },
],

with an additional property for the click event handler like described in the documentation for a command columns.command.click Function:

The JavaScript function executed when the user clicks the command button. The function receives a jQuery Event as an argument.

...however it doesn't fire the the click event and the alert doesn't show up.

Do you know what I am missing here?

The complete code that I test looks like this:

$("#grid").kendoGrid({
    columns: [{
        field: "name"
    }, ],
    editable: true,
    toolbar: [{
        name: "create",
        text: "New Row"
    }, {
        name: "copyRows",
        text: "Copy Rows",
        click: function (e) {
            alert('test');
        }
    }, ],
    dataSource: {
        data: [{
            name: "Jane Doe"
        }],        
    }
});

jsfiddle for custom toolbar command

t3chb0t

I have found the solution. For some strange undocumented reason a toobar command is not the same command as a column command and cannot be customized in the same way. The only thing they have in common is that a toolbar command can invoke a column command. There seems to be no click event in the toolbar:

$("#grid").kendoGrid({
    columns: [{
        field: "name"
    },{
        command: [{
        name: "customCommand",
        text: "Column Command",
        click: function(e){
            alert('Column Command');
        }
    }]
    } ],
    editable: true,
    toolbar: [{
        name: "create",
        text: "New Row"
    }, {
        // This actually calls the column command with the same name.
        name: "customCommand",
        text: "Toolbar Command",
        // The click event never gets fired.
        click: function (e) {
            alert('Toolbar Command');
        }
    }, ],
    dataSource: {
        data: [{
            name: "Jane Doe"
        }],        
    }
});

demo at jsfiddle

But I didn't want to have an extra button in each row only to make the toolbar command work so the solution was to use a custom template for the toolbar with a custom event handler:

$("#grid").kendoGrid({
    columns: [{
        field: "name"
    }],
    editable: true,
    toolbar: [{
        template:
            '<a class="k-button k-button-icontext k-grid-add" href="\\#"><span class="k-icon k-add"></span>New Row</a>' +
            '<a class="k-button k-grid-custom-command" href="\\#">Toolbar Command</a>'
    }],
    dataSource: {
        data: [{
            name: "Jane Doe"
        }],
    }
});

$('a.k-grid-custom-command').click(function (e) {
    alert('Toolbar Command');
});

demo at jsfiddle

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

What else do I need to do/create to make my servlet and AJAX work?

What do I need to do to make my toolbar hide when I scroll?

what do i need to add to make this put request work?

Kendo MVVM Grid Custom Toolbar Syntax

preventDefault() does not work in Kendo grid's custom click handler

Addition of Custom button in Kendo Grid using Kendotoolbar and kendo toolbar button

how do I make selectable or not selectable a kendo grid by a button

Kendo : How do i keep the toolbar when i save and restore a grid state?

What tool do I need to install to make my terminal show the autocompletion of the command that I'm writing?

What do I need to do in my view to make Prism.Uno work with x:Bind?

How do I change the color of the Kendo Grid toolbar "Download to Excel" button?

telerik - add toolbar and command to an existing kendo UI grid

Kendo Grid custom command button shown dynamically

What changes to my HTML and JavaScript code do I need to make, in order for my character_count to work?

After updating Mvvm Light to Version 5, what changes do I need to make RelayCommand CanExecute() work?

Adding custom buttons to Kendo grid toolbar in ASP.NET Core

Set up auditing for Oracle, what else do I need to perform?

Kendo grid's Select command operation configuration

What config files I need to verify to make sudo work?

What do I need to do to get activerecord-import to work?

What modifications do I need to make to my gcloud command to get the list of enabled services in all GCP projects in the below tabular format?

What's missing in this Kendo Grid / DropDownList combination?

Why do I need to pass an object to this class to make it work?

Kendo Grid: Toolbar template issue

What iptables command do I need to allow web server traffic?

What git command do I need to keep a clean commit history?

position:sticky header on a page with content that is taller than body's height, what should I do to make it work?

Play FLV videos in Ubuntu 16.04: what's the (gstreamer?) package(s) I need to install to make Totem do it without error?

What do I need to import for my "Visitable" interface to work in java?