Grid绑定后台来自sql的数据
1、通过ajax同步请求(注意:同步)
$.ajax({
async: false,
url: "@Url.Action("Search", "ErrorTable")",
data: { ValueFactory: factory, ValueStartDate: start, ValueEndDate: end },
success: function (data) {
jsonObj = $.parseJSON(data);
alert(typeof (jsonObj));
}
});
$("#grid").kendoGrid({
columns: [
{ field: "MC_CODE", title: "故障代码", template: "<strong>#: MC_CODE # </strong>" },
{ field: "SumHours", title: "累计时间" },
{ field: "SumTimes", title: "累计次数" }
],
sortable: true,
dataSource: {
data: jsonObj,
schema: {
model: {
fields: {
MC_CODE: { type: "string" },
SumHours: { type: "number" },
SumTimes: { type: "number" }
}
}
}
}
});
2、DataSource直接请求(还存在小问题,SumHours和SumTimes并没有已number排序,而是string)
var DataSource = new kendo.data.DataSource({
transport: {
read: {
type: "post",
url: "@Url.Action("Search", "ErrorTable")",
data: { ValueFactory: factory, ValueStartDate: start, ValueEndDate: end },
dataType: "json",
},
schema: {
model: {
fields: {
MC_CODE: { type: "string" },
SumHours: { type: "number" },
SumTimes: { type: "number" }
}
}
}
}
});
$("#grid").kendoGrid({
columns: [
{ field: "MC_CODE", title: "故障代码", template: "<strong>#: MC_CODE # </strong>" },
{ field: "SumHours", title: "累计时间" },
{ field: "SumTimes", title: "累计次数" }
],
sortable: true,
dataSource: DataSource
});