1

我是 jqgrid 的新手,正在尝试使用 json 加载数据。我尝试使用 jqgrid 演示作为基础,然后从那里构建。json 数据看起来不错,但我无法将任何内容加载到网格中。有任何想法吗?我希望使用 loaderror 或 loadcomplete 至少能给我洞察力,但我无法检索到为什么网格无法加载的任何消息。

json数据:

{
    "page": "1",
    "total": 1,
    "records": "12",
    "rows": [
        [
            "67",
            "3 - Sandbox: Appointment Set"
        ],
        [
            "68",
            "1 - Sandbox: Email requested"
        ],
        [
            "69",
            "2 - Sandbox: Questions not answered"
        ],
        [
            "74",
            "1 - TenPointSix: Email requested for more information"
        ],
        [
            "75",
            "2 - TenPointSix: Registered for webinar2"
        ],
        [
            "76",
            "3 - TenPointSix: Webinar registration confirmed"
        ],
        [
            "93",
            "5-Test Entry"
        ],
        [
            "94",
            "test3"
        ],
        [
            "95",
            "test2"
        ],
        [
            "97",
            "Jeff"
        ],
        [
            "103",
            "sortorder"
        ],
        [
            "106",
            "reload"
        ]
    ]
}

我的网格代码:

<table id="jsonmap"></table>
<div id="pjmap"></div>       

    <script language="JavaScript" type="text/javascript">


 jQuery("#jsonmap").jqGrid({        
    url:'sampleLoad.php?client=<?=$clientId5?>',
    datatype: "json",
        ajaxGridOptions: { contentType: 'application/json; charset=utf-8' },
    colNames:['Inv No','Name'],
    colModel:[
        {name:'id',index:'id', width:55},
        {name:'name',index:'name', width:100}

    ],
    rowNum:15,
    rowList:[15,30,45],
    pager: '#pjmap',
    sortname: 'id',

    viewrecords: true,
    sortorder: "asc",
    jsonReader: {
        root: "Rows",
        cell: "",
        page: "Page",
        total: "Total",
        records: "Records",
        repeatitems: false,
        id: "0"
    },
    loadComplete: function() {

        alert("Load Complete");
    },
    loadError: function(xhr,st,err) { $("#jsonmapMessage").html("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText); },



    caption: "JSON Mapping",
        width: '900',
                height: '300'

});


jQuery("#jsonmap").jqGrid('navGrid','#pjmap',{edit:true,add:false,del:false});

任何帮助,将不胜感激。

谢谢,

杰夫

4

1 回答 1

2

问题是jsonReader您使用的错误。例如,您rows在 JSON 数据中使用,但使用root: "Rows". 数据的格式对应默认repeatitems: true属性,但你使用repeatitems: false等等。

正确jsonReader的是

jsonReader: {
    cell: "",
    id: "0"
}

此外,我建议您添加gridview: true和使用height: 'auto',而不是height: '300'简化height.

演示显示了修改。

于 2012-03-05T06:24:54.947 回答