我是JQGrid的新手,目前正在学习分页。我正在尝试实现服务器端分页。
考虑我有45条记录。因为,服务器端根据页面大小(例如10)返回指定页面的请求记录,所以我的寻呼机在单击下一个按钮后立即更改为1。由于现在总页数为1,我无法继续浏览更多页面。根据存在的记录自动计算总页数。那么在这种情况下如何管理总页数值呢?
shell=True
映射到数据类型的函数是GetDataOutBox()
$("#jqGridOutbox").jqGrid({
datatype: 'json',
mtype: 'POST',
colNames: ['Title', 'Submitted By', 'Assigned To', 'Submitted On', 'History', 'WorkFlow Name'],
colModel: [
{ name: 'TitleOut', index: 'Title', width: 173, sortable: true, search: true, formatter: ShowItemFormatterOutbox },
{ name: 'CreatedByOut', index: 'CreatedBy', width: 173, sortable: true, searchoptions: {} },
{ name: 'PendingOnOut', index: 'PendingOn', width: 173, sortable: true, searchoptions: {} },
{ name: 'CreatedOnOut', index: 'CreatedOn', width: 173, sortable: true, searchoptions: {} },
{ name: 'HistoryOut', index: 'History', width: 80, sortable: false, search: false, formatter: ViewHistoryFormatter },
{ name: 'WorkFlowNameOut', index: 'WorkFlowName', width: 170, sortable: true, search: true }
],
datatype: function (postData) { getDataOutBox(postData, OutMode, OutPageNumber); },
ajaxGridOptions: { contentType: "application/json" },
loadonce: 'false',
viewrecords: 'true',
width: 987,
viewsortcols: [true, 'vertical', true],
height: 250,
rowList: [2, 5, 10, 20, 30, 100],
hidegrid: 'false',
rowNum: 2,
autowidth: true,
gridview: true,
shrinkToFit: false,
showQuery: 'true',
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
cell: "cell",
id: "Title",
userdata: "userdata",
repeatitems: true
},
gridComplete: function () {
$("#load_jqGridOutbox").hide();
$("tr.jqgrow:odd").css("background", "white");
$("tr.jqgrow:even").css("background", "#f7f7f7");
},
pager: '#jqGridOutboxPager',
pagerpos: 'center'
});
返回的模型是
function getDataOutBox(pdata, mode, pageNumber) {
var params = new Object();
params.page = pdata.page;
params.pageSize = pdata.rows;
params.sortIndex = pdata.sidx;
params.sortDirection = pdata.sord;
params.Title = $("#gs_TitleOut").val() == undefined ? '' : $("#gs_TitleOut").val();
params.CreatedBy = $("#gs_CreatedByOut").val() == undefined ? '' : $("#gs_CreatedByOut").val();
params.PendingOn = $("#gs_PendingOnOut").val() == undefined ? '' : $("#gs_PendingOnOut").val();
params.CreatedOn = $("#gs_CreatedOnOut").val() == undefined ? '' : $("#gs_CreatedOnOut").val();
params.WorkFlowName = $("#gs_WorkFlowNameOut").val() == undefined ? '' : $("#gs_WorkFlowNameOut").val();
params.mode = mode;
params.pageNumber = pageNumber;
$("#load_jqGridOutbox").show();
$.ajax({
url: 'ClaySysWorkFlowDashBoard.aspx/GetOutboxData',
type: "POST",
contentType: "application/json; charset=utf-8",
data: JSON.stringify(params),
dataType: "json",
success: function (data, st) {
if (st == "success") {
var grid = $("#jqGridOutbox")[0];
grid.addJSONData(data.d);
//$("#jqGridOutbox")[0].updatepager(false, true);
}
},
error: function () {
alert("An error has occured retrieving the data!");
}
});
}
根据页码,我只选择相应的10个记录集。因此,在返回之后,总页数变为1。