系列索引
Web jquery表格組件 JQGrid 的使用 - 從入門到精通 開篇及索引
Web jquery表格組件 JQGrid 的使用 - 4.JQGrid參數、ColModel API、事件及方法
Web jquery表格組件 JQGrid 的使用 - 5.Pager翻頁、搜索、格式化、自定義按鈕
Web jquery表格組件 JQGrid 的使用 - 6.准備工作 & Hello JQGrid
Web jquery表格組件 JQGrid 的使用 - 7.查詢數據、編輯數據、刪除數據
Web jquery表格組件 JQGrid 的使用 - 8.Pager、新增數據、查詢、刷新、查看數據
Web jquery表格組件 JQGrid 的使用 - 全部代碼
Web jquery表格組件 JQGrid 的使用 - 11.問題研究
使用Jqgrid時突然發現 數據類型為local時,
datatype: 'local', data:datas,
rowNum: 10,
rowList: [10],
指定data的datas長度大於rowNum時,pager點擊下一頁最后一頁都是無效的
使用
$(grid)[0].addJSONData(jsongrid);
也一樣無效。
搜索發現不少使用
http://stackoverflow.com/questions/5537728/jqgrid-pager-not-working-with-local-datatype
localReader或者jsonReader
但我測試無效
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');
My "results" is an object like this:
{page: "1", total: "70", records: "1045", rows:[.....]}
jsonReader格式如下:
jQuery("#gridid").jqGrid({
... jsonReader :
{
root: "rows", //數據模型
page: "page",//數據頁碼
total: "total",//數據總頁碼
records: "records",//數據總記錄數
repeatitems: true,//如果設為false,則jqGrid在解析json時,會根據name(colmodel 指定的name)來搜索對應的數據元素(即可以json中元素可以不按順序)
cell: "cell",//root 中row 行
id: "id",//唯一標識
userdata: "userdata",
subgrid: {
root:"rows", repeatitems: true, cell:"cell"
}
},
... });
示例json 數據格式;
{
"total": "xxx", "page": "yyy", "records": "zzz",
"rows" : [
{"id" :"1", "cell" :["cell11", "cell12", "cell13"]},
{"id" :"2", "cell":["cell21", "cell22", "cell23"]},
... ]
}
注意到加載json數據時
$(grid)[0].addJSONData(jsongrid);
是$(grid)[0]而不是$(grid)
推測[0]表示第一頁,也就是數據全部加載到第一頁了,但第一頁數據數量受rowNum的限制
jqGrid獲得所有行數據
var obj=$("#tablename").jqGrid("getRowData");
獲取到的數據也是第一頁的
建議解決辦法:
1.使用后台返回的json數據,參考Web jquery表格組件 JQGrid 的使用 - 6.准備工作 & Hello JQGrid
url: "WebService/UserHandler.ashx", datatype: "json",
2.自定義數據分頁
在onPaging事件里處理 參考Web jquery表格組件 JQGrid 的使用 - 4.JQGrid參數、ColModel API、事件及方法 事件
未嘗試,感覺比較麻煩
3.數據量不是太大時,本地數據一般數據量不會太大
rowNum: 1000, rowList: [1000],
修改這兩個不讓翻頁,改成拉滾動條吧
4.其他
歡迎高手給建議解決這個問題
