jqgrid 加载本地数据,格式为json

1 var grid = $('#table').jqGrid({
 2   datatype: 'local',
 3   altRows: true,
 4   colModel: [
 5     {name: '0', label: "Name"},
 6     {name: '1', label: "Color"},
 7   ],
 8   pager: "#pager",
 9   rowNum: 15,
10   sortname: '0',
11   viewrecords: true,
12   gridview: true,
13   height: '100%',
14   autowidth: '100%'
15 });
16 
17 var reader = {
18   root: function(obj) { return results.rows; },
19   page: function(obj) { return results.page; },
20   total: function(obj) { return results.total; },
21   records: function(obj) { return results.records; }
}
22 
23 grid.setGridParam({data: results.rows, localReader: reader}).trigger('reloadGrid');

这样的设置,加载速度没问题,还有另外一种方法,使用addRowData方法,速度有点慢,附上代码

1 $(function(){
 2     
 3     
 4     $("#gridTable").jqGrid({
 5         width:930,
 6         dataType:'local',        
 7         colNames:["国家/地区/组织代码","国家/地区/组织名称","操作","国家/地区/组织代码","国家/地区/组织名称","操作"],
 8         colModel:[
 9                     {name:"code",index:"code",align:'center'},
10                     {name:"name",index:"name",align:'center'},
11                     {name:"operation",index:"operation",align:'center'},
12                     {name:"code1",index:"code1",align:'center'},
13                     {name:"name1",index:"name1",align:'center'},
14                     {name:"operation1",index:"operation1",align:'center'},
15                 ],
16         viewrecords:true,
17         rowNum:15,
18         //autoHeight:true,
19         rowList:[15,20,25,30],
20         jsonReader:{
21             root: "rows", 
22             page: "page", 
23             total: "total", 
24             records: "records", 
25             repeatitems: false 
26 
27         },
28         pager:"#gridPager",            
29     });
30     
31     var rows = [
32                 {"code":"CN","name":"中国","operation":"<span style='color:blue;cursor:pointer;'>应用</span>","code1":"US","name1":"美国","operation1":"<span style='color:blue;cursor:pointer;'>应用</span>"},
33                 {"code":"JP","name":"日本","operation":"<span style='color:blue;cursor:pointer;'>应用</span>","code1":"KR","name1":"韩国","operation1":"<span style='color:blue;cursor:pointer;'>应用</span>"},
34                 {"code":"RU","name":"俄罗斯联邦","operation":"<span style='color:blue;cursor:pointer;'>应用</span>","code1":"EP","name1":"欧洲专利局","operation1":"<span style='color:blue;cursor:pointer;'>应用</span>"},
35                 {"code":"WO","name":"世界知识产权组织","operation":"<span style='color:blue;cursor:pointer;'>应用</span>","code1":"AD","name1":"安道尔","operation1":"<span style='color:blue;cursor:pointer;'>应用</span>"},
36                 {"code":"AE","name":"阿拉伯联合酋长国","operation":"<span style='color:blue;cursor:pointer;'>应用</span>","code1":"AF","name1":"阿富汗","operation1":"<span style='color:blue;cursor:pointer;'>应用</span>"},
37                 {"code":"AG","name":"安提瓜和巴布达","operation":"<span style='color:blue;cursor:pointer;'>应用</span>","code1":"AI","name1":"安圭拉","operation1":"<span style='color:blue;cursor:pointer;'>应用</span>"},
38                 {"code":"AL","name":"阿尔巴尼亚","operation":"<span style='color:blue;cursor:pointer;'>应用</span>","code1":"AM","name1":"亚美尼亚","operation1":"<span style='color:blue;cursor:pointer;'>应用</span>"},
39                 {"code":"AN","name":"荷属安的列斯群岛","operation":"<span style='color:blue;cursor:pointer;'>应用</span>","code1":"AO","name1":"安哥拉","operation1":"<span style='color:blue;cursor:pointer;'>应用</span>"},
40                 {"code":"AP","name":"非洲地区工业产权组织(ARIPO)","operation":"<span style='color:blue;cursor:pointer;'>应用</span>","code1":"AR","name1":"阿根廷","operation1":"<span style='color:blue;cursor:pointer;'>应用</span>"},
41                 {"code":"AS","name":"美属萨摩亚","operation":"<span style='color:blue;cursor:pointer;'>应用</span>","code1":"AT","name1":"奥地利","operation1":"<span style='color:blue;cursor:pointer;'>应用</span>"},
42                 
43                 ];
44     for(var i=0;i<rows.length;i++){
45         $("#gridTable").jqGrid('addRowData',i+1,rows[i]);
46     }
47     
48     
49     
50 });