jqGrid绑定Json数据

json: var jsonData = new
            {
                total = totalPages,
                page = page,
                records = totalRecords,
                rows = new
                {

                    city = "bj",
                    district = "bj",
                    telphone = "010-8888888",
                    createTime = "2011-1-1",
                    address = "everywhere in beijing",
                    name = "KFC"
                }
            };

 

 

Controller:public JsonResult GetJsonData(string sidx, string sord, int page, int rows)
        {
            string json = Request["sp"] == null ? "" : Request["sp"].ToString();
            JqGridModel jqGridModel = new JqGridModel();

            Object obj = jqGridModel.GridData(sidx, sord, page, rows);
           
           
            return Json(obj, JsonRequestBehavior.AllowGet);
           
        }

 

 

js:jQuery().ready(
        function () {
            jQuery("#list1").jqGrid(
                    {
                        url: '/Home/GetJsonData',
                        datatype: "json",
                        mtype:"GET",
                        colNames: ['姓名', '地区', '城市', '地址', '电话', '创建时间'],
                        colModel: [
                            { name: 'name', index: 'name', width: 75 },
                            { name: 'district', index: 'district', width: 90 },
                            { name: 'city', index: 'city', width: 100 },
                            { name: 'rows.address', index: 'address', width: 160 },
                            { name: 'telphone', index: 'telphone', width: 80 },
                            { name: 'createTime', index: 'createTime', width: 150, sortable: true }
                        ],
                        rowNum: 10,
                        autowidth: true,
                        height: 'auto',
                        pager: jQuery('#pager1'),
                        sortname: 'name',
                        viewrecords: true,
                        sortorder: "desc",
                        caption: "商户列表",
                        jsonReader: {
                            total: "total",
                            page: "page",
                            records: "records",
                            //root: function (obj) {
                               
                            //    var jsondata = eval('(' + obj + ')');
                                
                            //    return jsondata.rows;
                            //},
                            root:"rows",
                            repeatitems: false,
                        },
                        multiselect: true
                    });
        });

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值