2010-09-24 45 views
2

我們的jqGrid運行良好 - 如果我們返回> 1行一切正常。jqGrid不顯示單行

但是..如果我們只返回一行,網格不會顯示任何數據,導航欄中會顯示NaN中的1。非常奇怪 - 任何想法?

這是返回的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 
} 
}); 
+1

JSON看起來不錯,您可以包含2行的JSON對象,設置jqGrid的JS或輸出的HTML。我用單行jqGrid就好了 – 2010-09-24 14:51:05

+0

更新後的thx。 – 2010-09-24 14:57:22

+0

同樣的問題發生在我身上 http://stackoverflow.com/questions/12702106/jqgrid-not-displaying-single-row – user1671219 2012-10-03 04:55:44

回答

3

確定的JSON爲1沒有把行中的ARRAY它只是把一個OBJECT

1行

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

2排

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

第二JSON塊具有[{},{}]

檢查您的伺服器輸出JSON的er端代碼。

+0

應該看到 - 謝謝Bobby。 – 2010-09-24 15:06:04

+0

沒問題,jqGrid擊敗了我幾次,總是很簡單;) – 2010-09-24 15:07:32