jqgrid json没有加载数据

时间:2013-06-09 14:54:02

标签: json jqgrid gson jsonreader

我尝试了很多让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将此数据作为字符串发送。回复是

  

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

我更缺少什么?

谢谢和问候

1 个答案:

答案 0 :(得分:1)

您的主要错误是在the option

中使用了错误的案例
dataType:'json'

而不是

datatype:'json'

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

结果您将在the demo上显示网格。