jqGrid 不显示单行

发布于 2024-09-24 15:46:14 字数 2157 浏览 6 评论 0原文

我们的 jqGrid 运行良好 - 如果我们返回 > 1 行一切正常。

但是..如果我们只返回一行,网格不会显示任何数据,并且导航栏显示 1 of NaN。很奇怪-有什么想法吗?

这是为单行返回的 JSON:

{"records":"1","page":"1","total":"1","rows":{"cell":["ECS","D","201009","","0","ABCD","0","0","","201009"],"id":"692334"}}

对于两行:

{"records":"2","page":"1","total":"1","rows":[{"cell":["BJL","F","201008","","0","ABCD","0","0","","201008"],"id":"724588"},{"cell":["BJL","F","201008","","0","ABCD","15","10","","201008"],"id":"728676"}]}

要加载/重新加载网格,我们有:

function reloadGrid(u, grid) {
  if (u!= null) {
      grid.setGridParam({url:u});
  }

  grid.setGridParam({page:'1', datatype:'json', loadonce:'true'}); 
  grid.trigger("reloadGrid");
}

以及网格本身:

$("#list").jqGrid({
url:'NoData.json',
datatype: 'json',
mtype: 'GET',
colNames:['Product', 'Type','Expiry', 'Put Call', 'Strike', 'Account','Long','Short', 'Open Qty', 'LTD', 'Operations'],
colModel :[
  {name:'product', index:'product', width:75},
  {name:'type', index:'type', width:50, align:'right'},
  {name:'expiry', index:'expiry', width:60, align:'right'},
  {name:'putCall', index:'putCall', width:65},
  {name:'strike', index:'strike', sorttype: 'float', width:70},
  {name:'account', index:'account', width:70},
  {name:'long', index:'long', sorttype: 'int', width:55, align:'right'},
  {name:'short', index:'short', sorttype: 'int', width:55, align:'right'},
  {name: 'openQty', index:'openQty', width:80, align:'center', sortable:false, search:false, formatter:closeoutFormatter},
  {name:'LTD', index:'LTD', width:65, align:'right'},
  {index:'operations', width:105, title:false, search:false, align: 'center', formatter:opsFormatter, sortable:false}
],
pager: '#pager',
scrollOffset:0, //No scrollbar
rowNum:15,
width:'100%',
viewrecords: true ,
caption: 'Positions',
height: '360',
hidegrid: false //Don't show the expand/collapse button on the top right
}).navGrid("#pager",{edit:false,add:false,del:false,
beforeRefresh: function(){
    reloadPositionGrid();  //Required so that we go to the server and not reload local data
}
});

Our jqGrid is working well - if we return > 1 row everything works.

But.. if we return just one row, the grid does not display any data and the nav bar says 1 of NaN. Very weird - any ideas??

This is the JSON being returned for the single row:

{"records":"1","page":"1","total":"1","rows":{"cell":["ECS","D","201009","","0","ABCD","0","0","","201009"],"id":"692334"}}

For two rows:

{"records":"2","page":"1","total":"1","rows":[{"cell":["BJL","F","201008","","0","ABCD","0","0","","201008"],"id":"724588"},{"cell":["BJL","F","201008","","0","ABCD","15","10","","201008"],"id":"728676"}]}

To load/reload the grid we have:

function reloadGrid(u, grid) {
  if (u!= null) {
      grid.setGridParam({url:u});
  }

  grid.setGridParam({page:'1', datatype:'json', loadonce:'true'}); 
  grid.trigger("reloadGrid");
}

And the grid itself:

$("#list").jqGrid({
url:'NoData.json',
datatype: 'json',
mtype: 'GET',
colNames:['Product', 'Type','Expiry', 'Put Call', 'Strike', 'Account','Long','Short', 'Open Qty', 'LTD', 'Operations'],
colModel :[
  {name:'product', index:'product', width:75},
  {name:'type', index:'type', width:50, align:'right'},
  {name:'expiry', index:'expiry', width:60, align:'right'},
  {name:'putCall', index:'putCall', width:65},
  {name:'strike', index:'strike', sorttype: 'float', width:70},
  {name:'account', index:'account', width:70},
  {name:'long', index:'long', sorttype: 'int', width:55, align:'right'},
  {name:'short', index:'short', sorttype: 'int', width:55, align:'right'},
  {name: 'openQty', index:'openQty', width:80, align:'center', sortable:false, search:false, formatter:closeoutFormatter},
  {name:'LTD', index:'LTD', width:65, align:'right'},
  {index:'operations', width:105, title:false, search:false, align: 'center', formatter:opsFormatter, sortable:false}
],
pager: '#pager',
scrollOffset:0, //No scrollbar
rowNum:15,
width:'100%',
viewrecords: true ,
caption: 'Positions',
height: '360',
hidegrid: false //Don't show the expand/collapse button on the top right
}).navGrid("#pager",{edit:false,add:false,del:false,
beforeRefresh: function(){
    reloadPositionGrid();  //Required so that we go to the server and not reload local data
}
});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

假扮的天使 2024-10-01 15:46:14

好的,1 的 JSON 不会将行放入 ARRAY 中,它只是放入一个 OBJECT

1 Row

{"":"", "rows":{"cell":["",""], "id": "111"}

2 Rows

{"":"", "rows":[{"cell":["",""], "id": "111"}, {"cell":["",""], "id": "222"}]}

第二个 JSON 块的行位于 [{ },{}]

检查输出 JSON 的服务器端代码。

Ok the JSON for 1 is not putting the rows in an ARRAY it is just putting one OBJECT

1 Row

{"":"", "rows":{"cell":["",""], "id": "111"}

2 Rows

{"":"", "rows":[{"cell":["",""], "id": "111"}, {"cell":["",""], "id": "222"}]}

The second JSON block has the rows in [{},{}]

Check your server-side code that is outputting the JSON.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文