jqgrid json不加载数据
Posted
技术标签:
【中文标题】jqgrid json不加载数据【英文标题】:jqgrid json not loading data 【发布时间】:2013-06-09 14:54:02 【问题描述】:我尝试了很多让 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,"cell":["Adeeb","1208",1],"id":10,"cell":["Adeeb","1209",1],"id":11, "cell":["Adeeb","1210",1],"id":12,"cell":["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","12 27",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,"cell":["Adeeb","1251",1],"id":53,"cell":["Adeeb"," 1252",1],"id":54,"cell":["Adeeb","1253",1],"id":55,"cell":["Adeeb","1254" ,1],"id":56,"cell":["广告eeb","1255",1],"id":57,"cell":["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]]
我还缺少什么?
感谢和问候
【问题讨论】:
【参考方案1】:您的主要错误是the option 中使用了错误的大小写
dataType:'json'
而不是
datatype:'json'
我建议您另外删除带有默认值的jsonReader
,并将sortname:'no'
更改为某个正确的值(例如sortname: 'Rollno'
)。此外,我建议您使用gridview: true
选项来提高性能,autoencode: true
以确保您可以在网格中显示任何文本,使用height: "auto"
以获得最佳的网格高度。此外,在我看来,您应该在网格中包含loadonce: true
,因为服务器返回所有数据,而不是仅返回一个只有 10 行的请求页面。
因此,您将拥有the demo 上的网格。
【讨论】:
嘿,非常感谢,问题是数据类型。但是我的分页不起作用,我该如何实现 @user2003821:您应该在服务器代码中实现分页并仅返回请求的页面,或者您应该像我在回答中建议的那样添加loadonce: true
选项。以上是关于jqgrid json不加载数据的主要内容,如果未能解决你的问题,请参考以下文章