jqGrid没有填充数据?

时间:2012-07-12 06:57:05

标签: javascript jqgrid

我已经设置了jqGrid来显示我的数据,即使数据来自服务器,数据也不会显示在网格中。 这是服务器响应。Data is coming from the server like this

这是JavaScript。

<table id="Grid1" class="scroll"></table>
<div id="pager" class="scroll" style="text-align:center;">

<script>
$(document).ready(function () {
    jQuery("#Grid1").jqGrid({
            url: 'api/matchingservicewebapi/getuser',
            datatype: 'json',
            mtype: 'GET',
            colNames: ['Id', 'Account', 'Ref', 'BDate'],
            colModel: [
                { name: 'Id', index: 'Id', width: 200 },
                { name: 'Account', index: 'Account', width: 300 },
                { name: 'Ref', index: 'Ref', width: 300 },
                { name: 'BDate', index: 'BDate', width: 300 }

            ],
            rowNum: 10,
            rowList: [10, 20, 30],
            pager: '#pager',
            sortname: 'Id',
            viewrecoreds: true,
            sortorder: "desc",
            imgpath: 'Themes/images'
        }).navGrid(pager, { edit: true, add: true, del: true, refresh: true, search: true });
});

以下是数据的JSON格式

{"Data":{"rows":[{"id":200.0,"cell":["100","AMX.Data.Account","200","1/10/2010 12:00:00 AM"]},{"id":14726632.0,"cell":["600146","AMX.Data.Account","14726632","1/8/2010 12:00:00 AM"]},{"id":6633000.0,"cell":["668152","AMX.Data.Account","6633000","1/8/2010 12:00:00 AM"]},{"id":2053178.0,"cell":["600146","AMX.Data.Account","2053178","1/8/2010 12:00:00 AM"]},{"id":753550.0,"cell":["668152","AMX.Data.Account","753550","1/8/2010 12:00:00 AM"]},{"id":121774.0,"cell":["600146","AMX.Data.Account","121774","1/8/2010 12:00:00 AM"]},{"id":37900.0,"cell":["600146","AMX.Data.Account","37900","1/8/2010 12:00:00 AM"]},{"id":6569.0,"cell":["668152","AMX.Data.Account","6569","1/8/2010 12:00:00 AM"]},{"id":-1124870617.0,"cell":["668152","AMX.Data.Account","-1124870617","1/8/2010 12:00:00 AM"]},{"id":-813658270.0,"cell":["668152","AMX.Data.Account","-813658270","1/8/2010 12:00:00 AM"]}]},"JsonRequestBehavior":0}

但是数据没有被加载。我做错了什么?

1 个答案:

答案 0 :(得分:1)

正如Mostafa&amp; amp; txominpelu。尝试格式化JSON结果,如下所示

{"total":1123,
 "page":1,
 "records":1123,
 "rows":[{"id":1174,
          "cell":["1174","4","",...]
        }]
 }

并在服务器端

public ActionResult GridData(int page, int rows, string searchField = "",
       string searchString = "", string searchOper = "", string sidx = "MY_ID",
       string sord = "desc")
{
    //...
    var jsonData = new {
        total = totalPages,
        page,
        records = totalRecords,
        rows = (from item in items.ToList()
                select new {
                    id = item.MY_ID,
                    cell = new[] {
                        #region items
                        ToSafeString(item.MY_ID), 
                        ToSafeString(item.ShiftID), 
                        //... 
                        #endregion
                    }
                }).ToArray()
    };
}