从服务器端重新加载数据期间,jqgrid无法加载特定页面 [英] jqgrid can't load specific page during reload data from server side

查看:96
本文介绍了从服务器端重新加载数据期间,jqgrid无法加载特定页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jqgrid 3.8.2, 我正在尝试使用以下代码从服务器端重新加载数据并显示特定页面,例如当前页面. $(#mygrid").setGridParam({datatype:json}).trigger("reloadGrid",[{page:5}]);; 网格可以从服务器正确加载数据,但始终显示第一页而不是第5页. 有人可以帮我吗?

I'm using jqgrid 3.8.2, I'm trying to use below code to reload data from server side and show specific page, like current page. $("#mygrid").setGridParam({datatype:json}).trigger("reloadGrid",[{page:5}]); grid could load data from server properly, but always show first page instead of page 5. anybody could give me a hand on it?

问候 西蒙

推荐答案

我假设您使用loadonce: true参数.要从服务器重新加载数据,请将datatype:设置为'json'(我希望您使用setGridParam({datatype:'json'})而不是setGridParam({datatype:json}),就像问题代码片段中一样).从服务器加载数据后,将显示本地数据的第一页.

I suppose that you use loadonce: true parameter. To reload the data from the server you set datatype: to 'json' (I hope that you use setGridParam({datatype:'json'}) and not setGridParam({datatype:json}) like it is in the code fragment from the question). After the data will be loaded from the server the first page of the local data will be displayed.

要解决该问题,您将不得不在loadComplete中重新加载网格一次,但是现在您应该重新加载本地网格.为了没有重新加载循环并允许本地分页,您应该验证当前datatype是否为'json':

To solve the problem you will have to reload the grid one more time inside of loadComplete, but now you should reload the local grid. To have no reloading loop and to allow local paging you should verify whether the current datatype is 'json':

var myGrid = $("#mygrid"), currentPage = 1;
...
myGrid.jqGrid({
    // all grid parameters and additionally the following
    loadComplete: function() {
        if (this.p.datatype === 'json' && currentPage !== 1) {
            setTimeout(function() {
                myGrid.trigger("reloadGrid",[{page:currentPage}]);
            }, 50);
        }
    }
});
....
currentPage = 5;
myGrid.setGridParam({datatype:'json'}).trigger("reloadGrid",[{page:currentPage}]);

此处中查看演示.

这篇关于从服务器端重新加载数据期间,jqgrid无法加载特定页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆