$(document).ready(function () {
var crudServiceBaseUrl = "http://demos.telerik.com/kendo-ui/service";
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl + "/Products",
dataType: "jsonp",
cache: false
},
update: {
url: crudServiceBaseUrl + "/Products/Update",
dataType: "jsonp"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
},
batch: true,
pageSize: 5,
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true } },
UnitsInStock: { type: "number", validation: { min: 0, required: true } }
}
}
}
});
$("#grid").kendoGrid({
editingCell: -1,
dataSource: dataSource,
pageable: {
buttonCount : 2
},
toolbar: ["save"],
columns: [
"ProductName",
{ field: "UnitsInStock", title:"Stock", width: "120px" }
],
editable: "incell",
edit:function(e){
console.log("edit", this.options.editingCell);
if (this.options.editingCell >= 0) {
this.options.editingCell = -1;
} else {
console.log("forceRead");
this.options.editingCell = this.tbody.find("td").index(e.container);
this.dataSource.read();
e.preventDefault();
}
},
dataBound: function(e) {
if (this.options.editingCell >= 0) {
this.editCell($("#grid td:eq("+ this.options.editingCell + ")"));
}
}
});
});
#grid {
width: 400px;
}
<style>html { font-size: 12px; font-family: Arial, Helvetica, sans-serif; }</style>
<title></title>
<link href="http://cdn.kendostatic.com/2014.2.1008/styles/kendo.common.min.css" rel="stylesheet" />
<link href="http://cdn.kendostatic.com/2014.2.1008/styles/kendo.default.min.css" rel="stylesheet" />
<script src="http://cdn.kendostatic.com/2014.2.1008/js/jquery.min.js"></script>
<script src="http://cdn.kendostatic.com/2014.2.1008/js/kendo.all.min.js"></script>
<div id="grid"></div>