How to set number of pages in Jqgrid when using local data

Is it possible to override behaviour of jqgrid when passing data from client side? I know it is when fetching data from the server, but my issue is different. Here is jsfiddle link: http://jsfiddle.net/fott25/wdvsjwrg/

I will post my code here also, my html:

<table id="list"></table>
<div id="pager"></div>

And this is my javascript with data and jqgrid initialization in it:

var myData = [{
    id: 1,
    name: "aaz"
}, {
    id: 2,
    name: "bbz"
}, {
    id: 3,
    name: "ccz"
}, ];

$("#list").jqGrid({
    datastr: myData,
    datatype: "jsonstring",
    jsonReader: {
        page: function(datastr) {
            return 2;
        },
        total: function(datastr) { 
            return 10; 
        },
    }, 
    colNames: ["Id", "Name"],
    colModel: [{
        name: "id",
        index: "id",
        sorttype: "int"
    }, {
        name: "name",
        index: "name"
    }],
    rowNum:1,
    caption: "Viz Test",
    pager: '#pager',
});

This is the result of the code:

enter image description here

As you can see, I tried to set total number of pages to 10 in jsonReader properties, but jqgrid ignores that prop. Setting page to second is working just fine. Is it possible to override total page number?

EDIT #1: i tried setting lastpage to 10, but it is not working

Upvotes: 0

Views: 2140

Answers (1)

Oleg
Oleg

Reputation: 221997

In general the usage of updatepager is very easy. You need just set page records and lastpage options of jqGrid and then call updatepager as

this.updatepager(false, true);

if the code is executing inside of another jqGrid callback or

$("#grid")[0].updatepager(false, true);

It's important to mention that updatepager don't reload the grid. It just set the values in the pager and enables/disables the pager buttons.

It's very important to combine the manual setting of pager values with implementing of onPaging callback. See the old answer for an example of the usage of updatepager.

Be carefully in the usage of onPaging callback, which options are changed multiple times over different versions of jqGrid. You can read in the wiki article more about the problems.

Upvotes: 1

Related Questions