0

jqGrid的显示了,但它没有显示数据我检查了 json 源,没关系

 $(document).ready(function () {
    $("#grid").jqGrid(
    {
        url: 'GetDepartment',
        datatype: 'json',
        mtype: 'GET',
        colNames: ['Department ID', 'Department Name'],
        colModel: [
            { name: 'DepartmentID', index: 'DepartmentID' },
            { name: 'DepartmentName', index: 'DepartmentName'}
        ],
        pager: $("#GridPager"),
        rowNum: 2,
        rowList: [5, 10, 15, 20],
        width: 'auto',
        sortname: 'DepartmentID',
        sortorder: "ASC"
    })
    $("#grid").jqGrid('navGrid', '#GridPager', { add: false, edit: false, del: false, search: false})
})
4

1 回答 1

0

我认为您缺少 jsonReader,请将以下代码添加到您的网格中

            jsonReader: {
            repeatitems: false
            id: "DepartmentID"

        },

查看 wiki 以了解预期的 json 格式

http://www.trirand.com/jqgridwiki/doku.php?id=wiki:retrieving_data#json_data

所以在你的情况下,json响应应该是

{  "rows":[{"DepartmentID":2,"DepartmentName":"Asset Mgmt Group "},{"DepartmentID":16,"DepartmentName":"Business Solutions Group"},{"DepartmentID":8,"DepartmentName":"CBMG"}] } 
于 2013-01-22T07:30:18.073 回答