1.transport

标准的DataSource格式,默认get请求:



var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "https://demos.telerik.com/kendo-ui/service/products",
dataType: "jsonp"
},
update: {
url: "https://demos.telerik.com/kendo-ui/service/products/update",
dataType: "jsonp"
}
}
});


设置为post请求:



var dataSource = new kendo.data.DataSource({
transport: {
update: {
type: "POST"
}
}
});


自己写ajax请求:

注意:如果transport中有一个方法是自己写的ajax请求,则其他方法也需要使用自己写的ajax请求,需保持一致。



var dataSource = new kendo.data.DataSource({
transport: {
read: function(options) {
},
update: function(options) {
$.ajax({
url: "https://demos.telerik.com/kendo-ui/service/products/update",
dataType: "jsonp",
data: {
models: kendo.stringify(options.data.models)
},
success: function(result) {
options.success(result);
},
error: function(result) {
options.error(result);
}
});
}
}
});


需要传递的其他参数data:



//作为对象发送
var dataSource = new kendo.data.DataSource({
transport: {
update: {
cache: true, //是否缓存请求结果
contentType: "application/json", //发送到服务器的内容表头
dataType: "json", //发送服务器的数据类型
data: {
name: "Jane Doe",
age: 30
}
}
}
})
//从函数返回发送其他参数
var dataSource = new kendo.data.DataSource({
transport: {
update: {
data: function() {
return {
name: "Jane Doe",
age: 30
}
}
}
}
});


2.schema

 model



var dataSource = new kendo.data.DataSource({
schema:{
model:{
id:'',
fields:{
name: { type: "number",defaultValue:0, editable: false, nullable: true, validation: {
required: true, min: 1,
NoValidation:function(input){
if (input.is("[name='UnitPrice']") && input.val() != "") {
if(input.val() > 30){
input.attr("data-NoValidation-msg", "请输入小于30数字");
return false;
}
}
return true;
}
}}
}
}
}
});


注意:

  • editable:初始化的时候,控制该列是否可编辑;
  • defaultValue:默认值,只适用于新建的单元格,比如:新增;
  • validation:单元格的验证,可以写自定义事件;