天天看点

kendo实现grid的inline编辑

$(document).ready(function () {

dataSource = new kendo.data.DataSource({

   transport: {

           read:  function(options){//grid初始化时加载数据,由此方法提供

               。。。

               options.success(result);

           },

           update: function(options){。。。。} // 记录编辑完后所做的处理

   },

   batch: true,

   pageSize: 20,

   schema: {

       model: {

           id: "ProductID",

           fields: {

               ProductID: { editable: false, nullable: true },

               ProductName: { validation: { required: true } },

               UnitPrice: { type: "number", validation: { required: true, min: 1} },

               Discontinued: { type: "boolean" },

               UnitsInStock: { type: "number", validation: { min: 0, required: true } }

           }

       }

   }

});

$("#grid").kendoGrid({

   dataSource: dataSource,

   pageable: true,

   height: 430,

   columns: [

       "ProductName",

       { field: "UnitPrice", title: "Unit Price", format: "{0:c}", width: "100px" },

       { field: "UnitsInStock", title:"Units In Stock", width: "100px" },

       { field: "Discontinued", width: "100px" },

       { command: ["edit", "destroy"], title: " ", width: "172px"

   }],

   editable: "inline", // 记录被编辑时会以inline的方式

   edit:function(e){} // 点击编辑按钮时执行的方法