jqgrid加载本地数据分页

datatype必须是local才能加载本地数据;
demo地址: http://download.csdn.net/detail/zhaohuijiadelu/9895196#
jQuery("#list2").jqGrid({
                    datatype: 'local',
                    colModel:[
                        {name:"age",index:"age",label:'年龄',align:'center', width: '25%', sortable:false},
                        {name:"id",index:"id",label:'学号',align:'center', width: '25%', sortable:false},
                        {name:"name",index:"name",label:'姓名',align:'center', width: '50%', hidden:false}
                    ],
                    shrinkToFit : true,
                    rownumbers: true,
                    width :'600',
                    height: '100',
                    pager: 'pager2',
                    rowNum: 2
            });

    var rows = [{'age':'12','id':'1','name':'张三'},{'age':'22','id':'2','name':'李四'},
                {'age':'12','id':'3','name':'王五'},{'age':'22','id':'5','name':'马六'}];       
    var localData = {page: 1, total: 2, records: "2", rows: rows};
    localData.rows = rows;
    localData.records = rows.length;
    localData.total = (rows.length % 2 == 0) ? (rows.length / 2) : (Math.floor(rows.length / 2) + 1); 
    var reader = {  
                  root: function(obj) { return localData.rows; },  
                  page: function(obj) { return localData.page; },   
                  total: function(obj) {  return localData.total; },  
                  records: function(obj) { return localData.records; },  repeatitems : false};
    $("#list2").setGridParam({data: localData.rows, reader: reader}).trigger('reloadGrid');    

你可能感兴趣的:(jqgrid,jqgrid,分页,jquery)