0

我尝试了很多让 jqgrid 工作但它不起作用,问题是没有错误或警告,如何找出我错在哪里。gd 设置是这样的。它只显示空白网格,即网格中没有行。我认为 jqgrid 无法加载 json 数据。网格代码如下。

$(document).ready(function(){
                    $("#datagrid").jqGrid({
                       url:'jqgrid.htm',
                       dataType:'json',
                       colNames:['Name','Rollno','Year'],
                       colModel:[
                           {name:'Name',width:100,align:'center'},
                           {name:'Rollno',width:100,align:'center'},
                           {name:'Year',width:100,align:'center'}
                       ],
                       jsonReader: {
                        rows: "rows",
                        page: "page",
                        total: "total",
                        records: "records",
                        repeatitems: true,
                        cell: "cell",
                        id: "id"
                        },
                       rowNum:10,
                       rowList:[10,15,20,25,30,45,40],
                       pager:"#navGrid",
                       sortname:'no',
                       sortorder:"asc",
                       viewrecords:true,
                       caption:"Test"
                    });
                    $("#datagrid").jqGrid('navGrid','#navGrid',{edit:true,add:true,del:true});
            });

HTML

<body>
        <table id="datagrid"></table>
        <div id="navGrid"></div>
    </body>

响应数据 - 我使用 gson 将这些数据作为字符串发送。回应是

{"total":6,"page":1,"records":64,"rows":[{"id":1,"cell":["adeeb","1201",1]},{" id":3,"cell":["Adeeb","1202",1]},{"id":4,"cell":["Adeeb","1203",1]},{"id" :5,"cell":["Adeeb","1204",1]},{"id":6,"cell":["Adeeb","1205",1]},{"id":7 ,"cell":["Adeeb","1206",1]},{"id":8,"cell":["Adeeb","1207",1]},{"id":9,"单元格":["Adeeb","1208",1]},{"id":10,"cell":["Adeeb","1209",1]},{"id":11,"cell" :["Adeeb","1210",1]},{"id":12,"单元格":["Adeeb","1211",1]},{"id":13,"cell":["Adeeb","1212",1]},{"id":14,"cell" :["Adeeb","1213",1]},{"id":15,"cell":["Adeeb","1214",1]},{"id":16,"cell":[ "Adeeb","1215",1]},{"id":17,"cell":["Adeeb","1216",1]},{"id":18,"cell":["Adeeb ","1217",1]},{"id":19,"cell":["Adeeb","1218",1]},{"id":20,"cell":["Adeeb", "1219",1]},{"id":21,"cell":["Adeeb","1220",1]},{"id":22,"cell":["Adeeb","1221 ",1]},{"id":23,"cell":["Adeeb","1222",1]},{"id":24,"cell":["Adeeb","1223",1]},{"id":25,"cell":["Adeeb" ,"1224",1]},{"id":26,"cell":["Adeeb","1225",1]},{"id":27,"cell":["Adeeb"," 1226",1]},{"id":28,"cell":["Adeeb","1227",1]},{"id":29,"cell":["Adeeb","1228" ,1]},{"id":30,"cell":["Adeeb","1229",1]},{"id":31,"cell":["Adeeb","1230",1 ]},{"id":32,"cell":["Adeeb","1231",1]},{"id":33,"cell":["Adeeb","1232",1]} ,{"id":34,"cell":["Adeeb","1233",1]},{"id":35,"cell":["Adeeb","1234",1]},{"id":36,"cell":["Adeeb","1235" ,1]},{"id":37,"cell":["Adeeb","1236",1]},{"id":38,"cell":["Adeeb","1237",1 ]},{"id":39,"cell":["Adeeb","1238",1]},{"id":40,"cell":["Adeeb","1239",1]} ,{"id":41,"cell":["Adeeb","1240",1]},{"id":42,"cell":["Adeeb","1241",1]},{ "id":43,"cell":["Adeeb","1242",1]},{"id":44,"cell":["Adeeb","1243",1]},{"id ":45,"cell":["Adeeb","1244",1]},{"id":46,"cell":["Adeeb","1245",1]},{"id":47,"cell":["Adeeb","1246",1]},{"id" :48,"cell":["Adeeb","1247",1]},{"id":49,"cell":["Adeeb","1248",1]},{"id":50 ,"cell":["Adeeb","1249",1]},{"id":51,"cell":["Adeeb","1250",1]},{"id":52,"单元格":["Adeeb","1251",1]},{"id":53,"cell":["Adeeb","1252",1]},{"id":54,"cell" :["Adeeb","1253",1]},{"id":55,"cell":["Adeeb","1254",1]},{"id":56,"cell":[ "Adeeb","1255",1]},{"id":57,"单元格":["Adeeb","1256",1]},{"id":58,"cell":["Adeeb","1257",1]},{"id":59,"cell" :["Adeeb","1258",1]},{"id":60,"cell":["Adeeb","1259",1]},{"id":61,"cell":[ "Adeeb","1260",1]},{"id":62,"cell":["Adeeb","1261",1]},{"id":63,"cell":["Adeeb ","1262",1]},{"id":64,"cell":["Adeeb","1263",1]},{"id":65,"cell":["Adeeb", "1264",1]}]}{"id":60,"cell":["Adeeb","1259",1]},{"id":61,"cell":["Adeeb","1260",1]},{" id":62,"cell":["Adeeb","1261",1]},{"id":63,"cell":["Adeeb","1262",1]},{"id" :64,"cell":["Adeeb","1263",1]},{"id":65,"cell":["Adeeb","1264",1]}]}{"id":60,"cell":["Adeeb","1259",1]},{"id":61,"cell":["Adeeb","1260",1]},{" id":62,"cell":["Adeeb","1261",1]},{"id":63,"cell":["Adeeb","1262",1]},{"id" :64,"cell":["Adeeb","1263",1]},{"id":65,"cell":["Adeeb","1264",1]}]}单元格":["Adeeb","1264",1]}]}单元格":["Adeeb","1264",1]}]}

我还缺少什么?

谢谢并恭祝安康

4

1 回答 1

1

您的主要错误是选项中使用了错误的大小写

dataType:'json'

代替

datatype:'json'

我建议您另外删除jsonReader默认值并更改sortname:'no'为一些正确的值(sortname: 'Rollno'例如)。此外,我建议您使用gridview: true选项来提高性能,autoencode: true以确保您可以在网格中显示任何文本,用于height: "auto"获得最佳的网格高度。此外,在我看来,您应该将其包含loadonce: true在网格中,因为服务器返回所有数据,而不是仅返回一个只有 10 行的请求页面。

结果,您将拥有演示中的网格。

于 2013-06-09T15:43:50.840 回答