2011-09-13 41 views
1

当我刚开始使用的jqGrid,但是当我尝试最简单的例子(加载JSON数据),它不工作(没有行加在TBODY)没有行添加使用的jqGrid JSON格式

我已经加载这些文件头部分

<link rel="stylesheet" type="text/css" href="http://192.168.3.9/wavinet2-permana/application/themes/default/css/jqueryui/jquery-ui-1.8.8.custom.css"> 

<script src="http://192.168.3.9/wavinet2-permana/application/themes/default/js/jquery-1.4.4.min.js" type="text/javascript"></script> 

<script src="http://192.168.3.9/wavinet2-permana/application/themes/default/js/jquery-ui-1.8.8.custom.min.js" type="text/javascript"></script> 

<link rel="stylesheet" type="text/css" href="/wavinet2-permana/application/assets/css/jqgrid/ui.jqgrid.css"> 

<script src="/wavinet2-permana/application/assets/js/jqgrid/i18n/grid.locale-id.js" type="text/javascript"></script> 

<script src="/wavinet2-permana/application/assets/js/jqgrid/jquery.jqGrid.min.js" type="text/javascript"></script> 

而且我的JavaScript加载和配置的jqGrid

<script type="text/javascript"> 
$('#list2').jqGrid({ 
url: SITE_URL+'/account/test/jqgrid_ajax', 
dataType: 'json', 
mtype: 'GET', 
colNames: ['Username', 'Nama Person'], 
colModel: [ 
{name:'username', index: 'username', width:200, key:true}, 
{name:'nama_person', index: 'nama_person', width:200} 
], 
rowNum: 10, 
rowList: [10, 20, 30], 
pager: '#pager2', 
sortname: 'username', 
sortorder: 'ASC', 
caption: 'Account Example', 
viewrecords: true, 
jsonReader: {repeatitems: false} 
}); 
$('#list2').jqGrid('navGrid','#pager2',{edit:false,add:false,del:false}); 
</script> 

<table id="list2" width="100%"></table> 
<div id="pager2"></div> 

JSON响应

{ 
    "page":"1", 
    "total":"2", 
    "records":"13", 
    "rows":[ 
     { 
     "id":"Oke1", 
     "cell":[ 
      "Oke1", 
      "Deh" 
     ] 
     }, 
     { 
     "id":"Oke2", 
     "cell":[ 
      "Oke2", 
      "Deh" 
     ] 
     }, 
     { 
     "id":"Oke3", 
     "cell":[ 
      "Oke3", 
      "Deh" 
     ] 
     }, 
     { 
     "id":"Oke4", 
     "cell":[ 
      "Oke4", 
      "Deh" 
     ] 
     }, 
     { 
     "id":"Oke5", 
     "cell":[ 
      "Oke5", 
      "Deh" 
     ] 
     }, 
     { 
     "id":"Oke6", 
     "cell":[ 
      "Oke6", 
      "Deh" 
     ] 
     }, 
     { 
     "id":"Oke7", 
     "cell":[ 
      "Oke7", 
      "Deh" 
     ] 
     }, 
     { 
     "id":"Oke8", 
     "cell":[ 
      "Oke8", 
      "Deh" 
     ] 
     }, 
     { 
     "id":"Oke9", 
     "cell":[ 
      "Oke9", 
      "Deh" 
     ] 
     }, 
     { 
     "id":"Oke10", 
     "cell":[ 
      "Oke10", 
      "Deh" 
     ] 
     } 
    ] 
} 

我尝试在Firefox的Windows,Ubuntu的火狐和Internet Explorer 8中打开,它返回相同的结果。网格渲染但也有TBODY

回答

1

没有数据我看到你的代码的两个小错误:

  • 你应该使用datatype: 'json'而不是dataType: 'json'你可能从jQuery.ajax知道。
  • 您应该删除​​参数。

请参阅the demo

我建议你另外使用jQuery 1.6.2而不是现在已经是“复古”版本的jQuery 1.4.4。对于版本1.6.3,您应该更明智一些(请参阅here)。以同样的方式,jQuery UI 1.8.8也是一个旧版本。我建议你使用jQuery UI 1.8.16。

+0

感谢您创建演示页面。但是,什么是multiCol.js?因为我无法在jqgrid上找到我下载的文件 – Permana

+0

@Permana:这是剪切和粘贴错误。您可以改为使用标准的'jquery.jqGrid.min.js'或'jquery.jqGrid.src.js'。我现在修复了演示。当时我只是想改变jqGrid的一些建议,以允许支持多个列标题(标题组),如[here](http://www.ok-soft-gmbh.com/jqGrid/SimpleLocalGridHeadersWithFirstRow4.htm)所述在[答案](http://stackoverflow.com/questions/7341339/jqgrid-column-group/7351638#7351638)。我只是忘了改变'jquery.jqGrid.src.js'的名字。 – Oleg

+0

是的,它也工作没有jqGrid.src.multicol.js。谢谢 – Permana