Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a Kendo Grid link template behave like a command

I have a Kendo Grid, and instead of having a custom command:

$('#grid').kendoGrid({
    dataSource: data,
    columns:
    [
        ...
        { command: { text: "Details", click: showDetails }, title: " " }
    ]
});

I'd like the same behavior to occur but on a standard link. Is it possible?

This is the functionality I'm looking for: http://jsfiddle.net/dmathisen/ERgkA/2/

But want it to behave like this: http://jsfiddle.net/dmathisen/qXAf6/4/

like image 723
dmathisen Avatar asked Dec 21 '25 13:12

dmathisen


1 Answers

This is similar to what I use in my own projects. You can use whatever markup you desire and style it however you want to make it look functional.

function showDetails(e) {
    var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
    document.getElementById('details').innerHTML = dataItem.quantity;
}

var data = [
    { name: "name1", quantity: 1 },
    { name: "name2", quantity: 4 },
    { name: "name3", quantity: 9 }
];

var grid = $('#grid').kendoGrid({
    dataSource: data,
    columns: [
        { field: 'name', template: '<a href="\\#" class="k-button link">#= name #</a>' },
        { field: 'quantity' }
    ]
}).data('kendoGrid');

grid.table.on('click', '.link', function(e) {
        showDetails.call(grid, e);
});

JsFiddle

http://jsfiddle.net/qXAf6/7/

like image 188
Brett Avatar answered Dec 24 '25 07:12

Brett



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!