【问题标题】:JQGrid Pagination event,getting errorJQGrid分页事件,出现错误
【发布时间】:2013-09-06 17:58:26
【问题描述】:

在 JQGrid 分页方面需要帮助。 下面是一段代码,

错误线:var currentPage = $('#gridData').getGridParam('page');
ERR MSG :0x800a01b6 - microsoft jscript 运行时错误对象不支持此属性或方法。

我还检查了 Jquery 引用。一切都很好。不知道哪里出错了:(

$("#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
});

【问题讨论】:

    标签: jqgrid jquery-pagination


    【解决方案1】:

    与您调用 jqGrid 方法的方式不一致。如果我没记错的话,早期版本的 jqGrid 使用了

    jQuery("#grid_id").jqGridMethod( parameter1,...parameterN );
    

    调用方法的方式,但我相信新的 API 希望您使用 th

    jQuery("#grid_id").jqGrid('method', parameter1,...parameterN );
    

    所以在你的具体情况下,你在最后一行调用 setGridParam 的方式是最好的方式

    jQuery("#gridData").jqGrid("setGridParam", { datatype: "json", data: ...
    

    所以你的代码就像

    $("#gridId").getGridParam('lastpage');
    

    在新 API 中无效。 (即应该是

    jQuery("#gridData").jqGrid("getGridParam", 'lastpage');
    

    现在这个更改是关于 3.6 版的,所以你使用的是什么版本,因为你似乎在混合方法

    参考jqGrid methods

    虽然说实话,我有理由肯定这两种方法都可以,但从你的错误信息来看,$('#gridData').getGridParam('page');正在抛出错误,因为 $('#gridData') 没有方法 getGridParam,所以我会尝试其他方式

    【讨论】:

    • 非常感谢您的回答....我正在使用以下版本
    • 嗨,我已根据您的建议修改了代码。一切正常。唯一的问题是重新加载 Jqgrid,以下行没有触发 jQuery("#gridData").jqGrid("setGridParam ", { datatype: "json", data: "{TableName :'" + tableName + "'}", url: "TablesCoolView.aspx/GetTableData" }).trigger("reloadGrid");请提出一些解决方案。感谢您的帮助。
    • 不完全确定。 if 语句是否评估为 true>(即 if(currentRecordCount
    • 是的,这将是 if 语句。出于测试目的,我添加了两个警报,一个在语句的开头,另一个在语句的结尾。两个警报都在触发,但是这个重新加载没有触发。它也不会进入服务器端方法,用于调试目的。
    • 那么另一点,网址正确吗? (TablesCoolView.aspx/GetTableData)。您确定它没有在请求该 URL 时收到 404 或 500 http 错误(您可以在开发人员工具下,在任何主要浏览器的网络选项卡下检查)
    猜你喜欢
    • 2013-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-17
    • 1970-01-01
    • 2019-07-21
    相关资源
    最近更新 更多