Kendo grid button click arguments

跟風遠走 提交于 2021-02-10 05:27:47

问题


I have a kendo grid with a button column. When the button is clicked, I want it to call a javascript function with the row's data as parameters. Here's what I have so far

$(grd).kendoGrid({
    dataSource: ds,
    detailInit: detailInit,
    columns: [ {field: "foo", title: "bar" },
               {field: "Y" },
               {command: { text: "MyButton", click: doStuff } } ]
    });

function doStuff(e)
{
    //e is click events but I want to pass in data from the row instead
    //following is code I found here but item is null for me
    var row = $(this).closest("tr");
    var item = $(grd).data("kendoGrid").dataItem(row);
}

回答1:


This will give you the data pertaining to the row which the button was clicked.

function doStuff(e) {

    var tr = $(e.target).closest("tr");    // get the current table row (tr)
    var item = this.dataItem(tr);          // get the date of this row

    alert(item.PropertyName);
}


来源:https://stackoverflow.com/questions/27112142/kendo-grid-button-click-arguments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!