1

我已经设置 jqGrid 来显示我的数据,即使数据来自服务器,数据也不会显示在网格中。这是服务器响应。数据来自这样的服务器

这是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}

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

4

1 回答 1

1

正如 Mostafa 和 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()
    };
}
于 2012-07-12T07:18:11.920 回答