2011-05-24 125 views
1

任何人都可以幫我使用jQuery插件jqGrid嗎?我下載jqGrid 4.4.5,我把代碼JQuery網格不顯示數據 - 顯示空網格

<script> 
     $(document).ready(function() { 
      jQuery("#list2").jqGrid({ url:'test.json', datatype: "json", colNames:['Inv No','Date'], colModel:[ {name:'id',index:'id', width:55}, {name:'date',index:'date', width:90}], rowNum:10, rowList:[10,20,30], pager: '#pager2', sortname: 'id', viewrecords: true, sortorder: "desc", caption:"USERS" }); jQuery("#list2").jqGrid('navGrid','#pager2',{edit:true,add:true,del:true}); 

     }); 
    </script> 

我在我的HTML表格

<table id="list2"></table> 
    <div id="pager2"></div> 

,我已經test.json像

[ 
    { 
     "id": 3, 
     "date": "" 
    }, 
    { 
     "id": 2, 
     "date": "1" 
    }, 
    { 
     "id": 3, 
     "date": "" 
    } 
] 

但是當我打開網頁我不在網格中獲取任何數據,就像在圖片enter image description here上一樣。

有人可以指出我做錯了什麼嗎?

回答

1

JQgrid太棒了!但文件不是很好...

在你的情況下,問題是Json數據...如果你在JSON數據部分看here,那麼你意識到你試圖使用的Json無效對於jqGrid的...

必須尊重這種格式:

{ 
    "total": "xxx", 
    "page": "yyy", 
    "records": "zzz", 
    "rows" : [ 
    {"id" :"1", "cell" :["cell11", "cell12", "cell13"]}, 
    {"id" :"2", "cell":["cell21", "cell22", "cell23"]}, 
     ... 
    ] 
} 

檢查鏈接和讀東陽是不是太簡單......