jqgrid 載入本地資料local 如何分頁
阿新 • • 發佈:2019-02-06
參考文章: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 }