anish
anish

Reputation: 1033

how to set next page option in jqgrid

Json data which i receive from webservice is

{"meta": {"limit": 20, "next": "/api/un_bn_in/?offset=20&limit=20&format=json", "offset": 0, "previous": null, "total_count": 439603}, "objects": [{"id": 1, "phrase": "this is bengali test", "resource_uri": "/api/un_bn_in/1/", "verified_by_admin": true, "verified_by_usr": true}] }

To go next page url is "/api/un_bn_in/?offset=20&limit=20&format=json"

My jsonreader function is as follows:-

jsonReader{
    id : "id",
    repeatitems: false,
    root: function (obj) { return obj.objects; },
    records: function (obj) { 
          return 20; },
    total: function (obj) { return obj.meta.total_count; 
}

The real problem here is when i press next page button url generated by jqgrid is /api/un_bn_in/?format=json&_search=false&nd=1383576507420&rows=20&page=1&sidx=id&sord=asc

But i want "/api/un_bn_in/?offset=20&limit=20&format=json" this url to be generated so that i can get next page

Any help on this issue will be appreciated

Upvotes: 0

Views: 364

Answers (1)

Oleg
Oleg

Reputation: 221997

You can use prmNames option of jqGrid to rename standard jqGrid options or to remove some other. For example the option

prmNames: {nd: null, search: null, sort: null, order: null, rows: "limit" }

will remove some parameters which you don't need and rename rows option to limit. You will get the URL like /api/un_bn_in/?format=json&limit=20&page=2. The last step would be replacing limit and page options to /api/un_bn_in/?format=json0&limit=20&offset=20. In the case you can use serializeGridData additionally. The resulting options could be about the following

url: "/api/un_bn_in/?format=json",
prmNames: {nd: null, search: null, sort: null, order: null, rows: "limit" },
serializeGridData: (postData) {
    return {
        limit: postData.limit,
        offset: (parseInt(postData.page, 10) - 1) * postData.limit
    };
}

Upvotes: 1

Related Questions