tags:

views:

16

answers:

1

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
}
});
+2  A: 

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.

Bobby Borszich
Should have seen that - thanks Bobby.
Marcus
No problem, jqGrid has beat me to death several times and it is always something simple ;)
Bobby Borszich