jqgrid 加载本地数据local 如何分页

参考文章:http://stackoverflow.com/questions/5537728/jqgrid-pager-not-working-with-local-datatype

这个人的解答写的很好,只需要这么写

var grid = $('#table').jqGrid({
  datatype: 'local',
  altRows: true,
  colModel: [
    {name: '0', label: "Name"},
    {name: '1', label: "Color"},
  ],
  pager: "#pager",
  rowNum: 15,
  sortname: '0',
  viewrecords: true,
  gridview: true,
  height: '100%',
  autowidth: '100%'
});

var reader = {
  root: function(obj) { return results.rows; },
  page: function(obj) { return results.page; },
  total: function(obj) { return results.total; },
  records: function(obj) { return results.records; },

grid.setGridParam({data: results.rows, localReader: reader}).trigger('reloadGrid');

数据

{page: "1", total: "70", records: "1045", rows:[.....]}

参考这个人的解答,发现

只要这么写就行了

把我门的jsonReader 改成localReader.代码如下

    localReader:{
	            //id: "id",//设置返回参数中,表格ID的名字为blackId
				rows:function(object){ return mydata[0].rows},
				page:function(object){ return mydata[0].page},
				total:function(object){ return mydata[0].total},
				records:function(object){ return mydata[0].records},
	            repeatitems : false
	        }




你可能感兴趣的:(jqGrid)