如何在单击编辑按钮时在 jqgrid 中保留当前页面

how to keep current page in jqgrid on clicking edit button

我有一个包含五列的 jqgrid 以及 edit 列,在编辑列的每一行中都有一个编辑按钮。

假设我在jqgrid中有一些记录,我在jqgrid的第4页。单击第 4 页上某行的编辑按钮时,将调用执行某些功能并重新加载页面的操作方法。

jqgrid 也重新加载并从第 4 页转到第 1 页,如何在重新加载后保留同一页面。

我无法在互联网上找到这个确切场景的答案。

请帮忙!!

提前致谢。

$("#productvariationListGrid").jqgrid(
   {

       url: '../Product/GetAllProductType',
       sortname: 'Name',
       sortorder: 'asc',
       colNames: ['Id', 'Product Name', 'Product Type Name', 'Description', 'Edit'],
       colModel: [
           { name: 'Id', key: true, hidden: true },
           {
               name: 'ProductName',  index: 'ProductName', searchoptions: { sopt: ['cn'] }, resizable: false
           },
           {
               name: 'productTypeName',  index: 'productTypeName', searchoptions: { sopt: ['cn'] }, resizable: false
           },
            {
                name: 'Description',  index: 'Description', searchoptions: { sopt: ['cn'] }, resizable: false
            },
            {
                name: 'Edit',  index: 'Edit',  sortable: false, search: false,
                formatter: actionFormatterEdit

            }
       ],
       rowNum: 5,
       autowidth: true,
       width: '100%'
   });


    function actionFormatterEdit(cellvalue, options, rowObject) {
        return '<a href="../Product/EditProductType?ProductTypeId=' + options.rowId + '" class="editIcon"></a>';

您当前的编辑操作只会打开新的 HTML 页面。在这种情况下,您会丢失有关网格状态的所有信息。您应该考虑使用 Ajax 与服务器通信。这是jqGrid中实现的标准编辑方式。

或者,您可以将当前页面保存在网络浏览器的 localStorage 中或 cookie 中。要获取网格的当前页面,您可以使用 $("#productvariationListGrid").jqgrid("getGridParam", "page")。在创建网格之前 执行的代码中 您应该尝试从 localStorage (或从 cookie)获取页码。可以使用 jqGrid 的 page: oldPage 选项来创建网格并加载 oldPage 而不是第一页。

, this one and the oldest one shows how to persist the page number and many other information about the state of the grid. You can try the demo比如换页,到select一行,改变列的宽度或者列的顺序等等。之后,您可以按 F5重新加载页面。你会看到重新加载的页面看起来和重新加载之前一模一样,因为它保存然后恢复 localStorage 内部的状态。您可以根据相同的想法进行简化实施。