我是 jQuery 新手,不知道如何实现 jQuery JqGrid 分页事件。实际要求是,在更改页面时,我必须从数据库中获取一些记录。所以为此我需要知道如何实现 Jqgrid 分页事件。
出现错误@ Line:var currentPage = $('#gridData').getGridParam('page'); //获取当前页面
错误消息:0x800a01b6 - microsoft jscript 运行时错误对象不支持此属性或方法。以下是供参考的代码。
$("#gridData").jqGrid({
data: selectedTblData.Table.Rows,
datatype: "local",
toppager: true,
height: "100%",
width: (selectedTblData.Table.Width < 1000) ? 985 : "100%",
altRows: true,
altclass: "custom-alt-row",
colNames: selectedTblData.Table.colNames,
colModel: selectedTblData.Table.colModel,
multiselect: false,
rowNum: 25,
rowList: [15, 25, 50, 75, 100],
mtype: 'GET',
pager: '#pager',
sortname: selectedTblData.Table.colNames[0],
sortorder: "asc",
viewrecords: true,
shrinkToFit: (selectedTblData.Table.Width < 1000),
caption: tableName,
secureUri: false,
contentType: "application/json; charset=utf-8",
loadonce: true,
//BS Page start
onPaging: function (pgButton) {
//debugger;
var pagerId = this.p.pager.substr(1); // get paper id like "pager"
var currentPage = $('#gridData').getGridParam('page'); //get current page
var lastPage = $("#gridData").getGridParam("lastpage"); //get last page
if (currentPage - 1 == lastPage - 1)
$("#gridData").setGridParam({ page: lastPage }).trigger("reloadGrid"); // set the requested page to the last page value – then reload
var currentRecordCount = $("#gridData").getGridParam("reccount"); //get the record count
var recordsPerPage = $("#gridData").getGridParam("rowNum"); // get the records per page
var newValue = 0; // new value
if (pgButton === "user") {
newValue = $(".ui-pg-input").val();
}
else {
if (pgButton.indexOf("next") >= 0)
newValue = ++currentPage;
else if (pgButton.indexOf("prev") >= 0)
newValue = --currentPage;
else if (pgButton.indexOf("last") >= 0)
newValue = $("#gridId").getGridParam('lastpage');
else if (pgButton.indexOf("first") >= 0)
newValue = 1;
}
alert(newValue);
$("#gridData").setGridParam({ page: newValue }).trigger("reloadGrid"); // set the requested page to the last page value – then reload
currentRecordCount = $("#gridData").getGridParam("reccount"); // read the current page records
alert('RecordCount: ' + currentRecordCount + ' RecordsPerPage: ' + recordsPerPage);
if (currentRecordCount < recordsPerPage) {
startRange = 1;
endRange += endRange;
jQuery("#gridData").jqGrid("setGridParam", { datatype: "json", data: "{TableName :'" + tableName + "'}", url: "TablesCoolView.aspx/GetTableData" }).trigger("reloadGrid");
}
}
//BS page end
});
请帮我解决这个问题。