Search code examples
jqgridpaginationreload

jqgrid can't load specific page during reload data from server side


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?

Regards Simon


Solution

  • 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.

    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}]);
    

    See the demo here.