$("#grid").kendoGrid({
dataSource:{
transport: {
read: {
url: crudServiceBaseUrl + "/Products",
dataType: "jsonp"
},
update: {
url: crudServiceBaseUrl + "/Products/Update",
dataType: "jsonp"
},
destroy: {
url: crudServiceBaseUrl + "/Products/Destroy",
dataType: "jsonp"
},
create: {
url: crudServiceBaseUrl + "/Products/Create",
dataType: "jsonp"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
},
schema:{
model:{
id:'id',
fields:{ }
}
},
pageSize:20,
batch: true,
serverPaging: true,
serverFiltering: true,
serverSorting: true
},
// 导出excel
toolbar:['excel','create'],
persistSelection:true, //checkbox多选的时候,必须添加,否则获取不到选中的数据
noRecords:true, //当表格中没有数据,显示的信息
excel:{
fileName:'input.xlsx',
filterable:true , //显示过滤
allPages: true //导出所有页的数据
},
editable: {
createAt: "bottom" //每次新增的时候,从底部新增 bottom/top
},
pageable: {
pageSizes: true,
buttonCount: 5,
refresh: true //刷新按钮
},
columns:[
{
field:'b', //返回数据字段
title:'物料名称',
locked:true, //冻结列
filterable:{
cell:{
operator:'contains', //包含
suggestionOperator:'contains', //显示查询出来的数据
showOperators:false //去掉右侧过滤按钮
}
},
attributes: {
"class": "table-cell", //添加类名
style: "text-align: right; font-size: 14px" //添加样式
},
template:'', //模板
width:200
},
{
title:'操作',
// 按钮,控制是否显示
command:[{ name: "destroy", visible: function(dataItem) { return !dataItem.isDisabled === true }}]
},
{ title:'行号', template:'#= ++record #', width:50, attributes: { style: "text-align: center;"} },
// checkbox框
{ selectable:true, width:50 },
],
dataBinding:function(){
// 显示行号,必须要有pageSize
record = (this.dataSource.page() - 1) * this.dataSource.pageSize();
}
})