【JqGrid】JqGrid关于loadonce:true后trigger("reloadGrid")无效,loadonce:false后无法翻页的问题

简单的来说就是在setGridParam中加上参数datatype:'json',因为loadonce:true后,jqGrid只会加载一次数据,并把datatype改为local。

这样就无法完成于Server的交互通信进行数据搜索和刷新操作,因为全部数据都是提取的本地的。

解决办法:

1、在刷新的时候重新将datatype重新定位到json,也就是指向服务器后,jqGrid就会像服务器发起请求。

例如:

$("#contentGroupOrderTable").setGridParam({datatype:'json', page:1}).trigger('reloadGrid');

以上方法亲测可用

 

也就是说在点击按钮事件这你可以这样写:

function searchBtn() {
        $("#contentGroupOrderTable").setGridParam({datatype:'json', page:1}).trigger('reloadGrid');
        $("#contentGroupOrderTable").jqGrid('setGridParam', {page:1, postData: opGrid.getParam()}).trigger("reloadGrid");
    }


但是这样的两句代码在点击按钮事件时需要点击两次才能得到结果,故需要将两行代码整合成一行代码,如下:

function searchBtn() {
        $("#contentGroupOrderTable").setGridParam({datatype:'json', page:1}).jqGrid('setGridParam', {page:1, postData: opGrid.getParam()}).trigger("reloadGrid");
    }


2、或者在jqGrid version 4.8之后,在trigger中加上参数fromServer:true,

例如:

$("#contentGroupOrderTable").trigger("reloadGrid", { fromServer: true, page: 1 });


此方法未测试,只是原文中提到了。


附送原文:

原文地址:http://stackoverflow.com/questions/5397671/jqgrid-reloadgrid-with-loadonce-set-to-true/5398136#5398136

If you use loadonce:true jqGrid change the datatype parameters to 'local' after the first load of data from the grid. All next grid reloading (sorting, paging, filtering) works local. If you want refresh the grid data from the server one more time you should set datatype to its original value ('json' or 'xml'). For example:

$("#list").setGridParam({datatype:'json', page:1}).trigger('reloadGrid');

UPDATED: Free jqGrid supports fromServer: true option of reloadGrid starting with the first release (starting with version 4.8). So one can use the code like

$("#list").trigger("reloadGrid", { fromServer: true, page: 1 });

to do the same as above. The main advantage: such code works fine with any initial value of datatype ("json""jsonp""xml" and so on). Free jqGrid saves original value of datatype inside of internal dataTypeOrg before changing it to "local".

One more helpful option of free jqGrid is the parameter reloadGridOptions of navGrid, which allows to specify default options of reloadGrid. Thus one can use for example

loadonce: true, navOptions: { reloadGridOptions: { fromServer: true } }

options of jqGrid, which set defaults for navGrid additionally. As the result the click on "Reload" button of navigator bar will reload the grid from the server instead of local reloading。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张思全

实践,方能出真知!打赏博主吧!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值