用JqGrid做表格查询,总页码一直为1导致不能翻页,为什么?

Rivers.U 2014-07-04 10:24:43
首先,看我的代码配置


jQuery(grid_selector).jqGrid({
//direction: "rtl",
//mtype:'GET',
url: "/v-order2?query2=",
//data: grid_data,
datatype: "json",
height: 250,
colNames:[' ', '订单号','用户ID','状态', '下单日期', '备忘'],
colModel:[
{
name:'myac',index:'', width:80, fixed:true, sortable:false, resize:false,
formatter:'actions',
formatoptions:{
keys:true,
delOptions:{recreateForm: true, beforeShowForm:beforeDeleteCallback}
//editformbutton:true, editOptions:{recreateForm: true, beforeShowForm:beforeEditCallback}
}
},
{name:'id',index:'id', width:100,editable: false,editoptions:{size:"20",maxlength:"9"}},
{name:'userId',index:'userId', width:100,editable: false,editoptions:{size:"20",maxlength:"9"}},
{name:'status',index:'status', width:90, editable: true,edittype:"select",
editoptions:{value:"待付款:待付款;正在出货:正在出货;已发货:已发货"}
},
{name:'datetime',index:'datetime',width:90, editable:true, sorttype:"date",unformat: pickDate},
{name:'memo',index:'memo', width:150, sortable:false,editable: true,edittype:"textarea", editoptions:{rows:"2",cols:"10"}}
],
viewrecords : true,
rowNum:5,
//rowList:[5,10,20],
pager : pager_selector,
//altRows: true,
//toppager: true,
multiselect: true,
//multikey: "ctrlKey",
multiboxonly: true,
loadComplete : function() {
var table = this;
setTimeout(function(){
styleCheckbox(table);
updateActionIcons(table);
updatePagerIcons(table);
enableTooltips(table);
}, 0
);
},
//editurl: "/v-order2?update2=",//nothing is saved
caption: "jqGrid表格",
autowidth: true,
sortName:'id'
});



//navButtons
jQuery(grid_selector).jqGrid('navGrid',pager_selector,
{ //navbar options
edit: true,
editicon : 'icon-pencil blue',
add: true,
addicon : 'icon-plus-sign purple',
del: true,
delicon : 'icon-trash red',
search: true,
searchicon : 'icon-search orange',
refresh: true,
refreshicon : 'icon-refresh green',
view: true,
viewicon : 'icon-zoom-in grey'
},
{
//edit record form
//closeAfterEdit: true,
recreateForm: true,
beforeShowForm : function(e) {
var form = $(e[0]);
form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
style_edit_form(form);
}
},
{
//new record form
closeAfterAdd: true,
recreateForm: true,
viewPagerButtons: false,
beforeShowForm : function(e) {
var form = $(e[0]);
form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
style_edit_form(form);
}
},
{
//delete record form
recreateForm: true,
beforeShowForm : function(e) {
var form = $(e[0]);
if(form.data('styled')) return false;

form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
style_delete_form(form);

form.data('styled', true);
},
onClick : function(e) {
alert(1);
}
},
{
//search form
recreateForm: true,
afterShowSearch: function(e){
var form = $(e[0]);
form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
style_search_form(form);
},
afterRedraw: function(){
style_search_filters($(this));
},
multipleSearch: true
/**
multipleGroup:true,
showQuery: true
*/
},
{
//view record form
recreateForm: true,
beforeShowForm: function(e){
var form = $(e[0]);
form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />')
}
}
)


然后,看截图


可以看到,总条数有16条,但是总页码却只有1页,导致不能翻页。(我设置每页显示5条)

我在网上查到说,json返回的数据应该像下面那样的内容。total用于指定总页码,而rows用于指定查到的数据列表
{
total:X //总页数,
page:XX,
rows:XXX
}

但是,试过以后发现,总页码确实改成total,翻页也能翻了。但是表格中显示的一直是刚查出来的那5条数据。
其实我在后台查出了16条数据传了回来。

我觉得问题在于本来查到了16条数据,但是好像页面上只保存了5条数据用于显示(类似就缓存了5条)

求大侠帮忙解决
...全文
997 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
麦兜仔 2018-08-10
  • 打赏
  • 举报
回复
没有实现分页的话,可以看一下这一点
后台有没有通过pageNo和pageSize分页查询数据,即有没有执行sql的limit语句。
因为当你点击jqGrid的分页的时候,它会传当前页(pageNo)和每页显示数据数(pageSize)给后台,这时候你需要利用这两个参数去数据库分页查出数据,按格式返回给前端,才会实现分页。
qq_34696657 2017-01-20
  • 打赏
  • 举报
回复
jsonReader: { root: 'list', page: 'pageNumber', total: 'pageSize', records: 'totalCount', repeatitems: false }, 这个要和自己返回的json名称匹配
qq_33729696 2016-04-01
  • 打赏
  • 举报
回复
如果为ture则数据只从服务器端抓取一次,之后所有操作都是在客户端执行,翻页功能会被禁用。请教一下,需要配置其他参数么?
Rivers.U 2014-07-04
  • 打赏
  • 举报
回复
引用 1 楼 fangzuli 的回复:
pagination: true,
试了下不对。 我找到问题所在了。 需要加上 loadonce:true. 这样才能把查到所有数据保存在jqgrid的internal data里面。不然的话,它只会保留一页的数据。
万玩完顽完 2014-07-04
  • 打赏
  • 举报
回复
pagination: true,

87,907

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧