关于Kendo Grid数据绑定后台的问题

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
});
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值