jQuery JQGrid 分页事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18502551/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 21:47:44  来源:igfitidea点击:

jQuery JQGrid pagination event

jqueryeventsjqgridpagination

提问by Lalita

Am new to jQuery and don't know how to implement jQuery JqGrid pagination event. Actual requirement is ,on change of page i have to get some records from database. So for that i need to know how to implement Jqgrid pagination event.

我是 jQuery 新手,不知道如何实现 jQuery JqGrid 分页事件。实际要求是,在更改页面时,我必须从数据库中获取一些记录。所以为此我需要知道如何实现 Jqgrid 分页事件。

Getting error @ Line:var currentPage = $('#gridData').getGridParam('page'); //get current page

获取错误 @ Line:var currentPage = $('#gridData').getGridParam('page'); //获取当前页面

Error Msg:0x800a01b6 - microsoft jscript runtime error object doesn't support this property or method. Below is the code for reference.

错误消息: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
            });

Please help me out of this.

请帮我解决这个问题。

回答by Pranav Kale

onPagingis the event you are looking for..

onPaging是您正在寻找的事件..

This will help: http://www.trirand.com/jqgridwiki/doku.php?id=wiki:pager

这将有所帮助:http: //www.trirand.com/jqgridwiki/doku.php?id=wiki: pager