kendo custom command
by valchev
HTML
<script src="http://cdn.kendostatic.com/2012.1.515/js/kendo.all.min.js"></script>
<link rel="stylesheet" href="http://cdn.kendostatic.com/2012.1.322/styles/kendo.common.min.css">
<link rel="stylesheet" href="http://cdn.kendostatic.com/2012.1.322/styles/kendo.default.min.css">
<div id="grid"></div>
<br />
<div id="display"></div>
JavaScript
var dataSource = new kendo.data.DataSource({
transport: {
read: {
//using jsfiddle echo service to simulate JSON endpoint
url: "/echo/json/",
dataType: "json",
type: "POST",
data: {
// /echo/json/ echoes the JSON which you pass as an argument
json: JSON.stringify([
{"firstname":"John", "lastname": "Smith", "cellphone": "123123123"},
{"firstname":"Jane", "lastname": "Green", "cellphone": "456456456"}
])
}
}
},
schema: {
model: {
fields: {
firstname: {type: "string"},
lastname: {type: "string"},
cellphone: {type: "string"}
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
columns: [
"firstname",
"lastname",
"cellphone",
{ command:{text:"vCard", className:"vCardButton"}, title:"vCard", width:"110px" }
]
});
$("#grid").delegate(".vCardButton", "click", function(e) {
var grid = $("#grid").data("kendoGrid");
//get current dataItem
var myVar = grid.dataItem($(this).closest("tr"));
$("#display").html(JSON.stringify(myVar));
});