jqgrid 没有填充数据
jqgrid not getting populated with data
我正在尝试使用从服务器返回的 JSON 数据填充 jqgrid。
下面是我的 jqgrid 配置代码 -
$(document).ready(function(){
jQuery("#list4").jqGrid({
jsonReader : {
repeatitems: false,
id: "0"
},
url:'/data/scans',
datatype:'json',
colNames:['Scan ID','Scanned Machine', 'Begin Time', 'End Time'],
colModel:[
{name:'scanId',index:'scanId', width:100, jsonmap:"scanId"},
{name:'scannedMachine',index:'scannedMachine', width:150, jsonmap:"scannedMachine"},
{name:'beginTime',index:'beginTime', width:180,jsonmap:"beginTime"},
{name:'endTime',index:'endTime', width:180,jsonmap:"scanId"}
],
rowNum:10,
rowList:[10,20,30],
pager: '#pager4',
sortname: 'scanId',
viewrecords: true,
sortorder: "desc",
caption:"JSON Example"
});
jQuery("#list4").jqGrid('navGrid','#pager4',{edit:false,add:false,del:false});
从服务器返回的 JSON 数据如下所示 -
{ total: '1',
page: '1',
records: '2',
rows:[
{scanId:"123", scannedMachine:"Axbhad", beginTime:"Fri Apr 13 13:02:52 IST 2018", endTime:"Fri Apr 13 13:02:52 IST 2018"},
{scanId:"123", scannedMachine:"Axbhad", beginTime:"Fri Apr 13 13:02:52 IST 2018", endTime:"Fri Apr 13 13:02:52 IST 2018"}]}
但是 html 页面总是显示这样的空网格 -
谁能指出我做错了什么。
我已经开始工作了。我所做的只是正确标点了 JSON 字符串。
现在看起来像这样 -
{ "total": "1", "page": "1", "records": "2", "rows":[ {"scanId":"123", "scannedMachine":"Axbhad", "beginTime":"Fri Apr 13 17:17:30 IST 2018", "endTime":"Fri Apr 13 17:17:30 IST 2018"}, {"scanId":"124", "scannedMachine":"Axbhad", "beginTime":"Fri Apr 13 17:17:30 IST 2018", "endTime":"Fri Apr 13 17:17:30 IST 2018"}]}.
为了避免犯这种愚蠢的错误,我使用了如下的 GSON libabry -
@Override
public String toString() {
return new Gson().toJson(this);
}
我正在尝试使用从服务器返回的 JSON 数据填充 jqgrid。
下面是我的 jqgrid 配置代码 -
$(document).ready(function(){
jQuery("#list4").jqGrid({
jsonReader : {
repeatitems: false,
id: "0"
},
url:'/data/scans',
datatype:'json',
colNames:['Scan ID','Scanned Machine', 'Begin Time', 'End Time'],
colModel:[
{name:'scanId',index:'scanId', width:100, jsonmap:"scanId"},
{name:'scannedMachine',index:'scannedMachine', width:150, jsonmap:"scannedMachine"},
{name:'beginTime',index:'beginTime', width:180,jsonmap:"beginTime"},
{name:'endTime',index:'endTime', width:180,jsonmap:"scanId"}
],
rowNum:10,
rowList:[10,20,30],
pager: '#pager4',
sortname: 'scanId',
viewrecords: true,
sortorder: "desc",
caption:"JSON Example"
});
jQuery("#list4").jqGrid('navGrid','#pager4',{edit:false,add:false,del:false});
从服务器返回的 JSON 数据如下所示 -
{ total: '1',
page: '1',
records: '2',
rows:[
{scanId:"123", scannedMachine:"Axbhad", beginTime:"Fri Apr 13 13:02:52 IST 2018", endTime:"Fri Apr 13 13:02:52 IST 2018"},
{scanId:"123", scannedMachine:"Axbhad", beginTime:"Fri Apr 13 13:02:52 IST 2018", endTime:"Fri Apr 13 13:02:52 IST 2018"}]}
但是 html 页面总是显示这样的空网格 -
谁能指出我做错了什么。
我已经开始工作了。我所做的只是正确标点了 JSON 字符串。 现在看起来像这样 -
{ "total": "1", "page": "1", "records": "2", "rows":[ {"scanId":"123", "scannedMachine":"Axbhad", "beginTime":"Fri Apr 13 17:17:30 IST 2018", "endTime":"Fri Apr 13 17:17:30 IST 2018"}, {"scanId":"124", "scannedMachine":"Axbhad", "beginTime":"Fri Apr 13 17:17:30 IST 2018", "endTime":"Fri Apr 13 17:17:30 IST 2018"}]}.
为了避免犯这种愚蠢的错误,我使用了如下的 GSON libabry -
@Override
public String toString() {
return new Gson().toJson(this);
}