1

i have a problem in my jqgrid table: i load the json, i have my table but i can only see the last page of the table, without the possibility of changing the page.

the js code:

$("#list").jqGrid(
        {
            url:'test.json',
            datatype: "json",
            mtype: 'GET',
            colNames:['id','model','cc','nation','prod'],
            colModel:[
                      {name:'id', index:'id', jsonmap:"id", width:25},
                      {name:'model', index:'model', jsonmap:"model", width:50},
                      {name:'cc', index:'cc', jsonmap:"cc", width:25},
                      {name:'nation', index:'nation', jsonmap:"nation", width:50},
                      {name:'prod', index:'prod', jsonmap:"prod", width:50}
                     ],
            rowNum: "2",
            page: "1",
            rowList: [2,4,6],
            autowidth: true,
            pager: '#pager',
            height: "100%",
            sortname: 'id',
            caption: "Elenco delle Moto",
            jsonReader: {root: 'rows',page: 'page',total: 'total',records: 'records',repeatitems: false,id: 'id'},

            loadComplete: function() {
                grid.setGridHeight('auto');
            }
        });
        $("#list").jqGrid('navGrid','#pager',{edit:false,add:false,del:false,search:false});
        $("#visual").hide();

and my json file:

{
"total": "3",
"page": "1",
"records": "5",
"rows": 
[
    {
        "Id": "1",
        "model": "shiver",
        "cc": "750",
        "nation": "italy",
        "prod": "aprilia"
    },
    {
        "Id": "2",
        "model": "monster",
        "cc": "696",
        "nation": "italy",
        "prod": "ducati"
    }
],
"page":"2",
"rows":
[
    {
        "Id": "3",
        "model": "z750",
        "cc": "750",
        "nation": "japan",
        "prod": "kawasaki"
    },
    {
        "Id": "4",
        "model": "hornet",
        "cc": "700",
        "nation": "japan",
        "prod": "honda"
    }
],
"page":"3",
"rows":
[
    {
        "Id": "5",
        "model": "speedtriple",
        "cc": "1000",
        "nation": "england",
        "prod": "buell"
    }
]

}

I've tried many times, but always the same result.. Can someone help me?

1 Answers1

0

Your response should contain only one page at once (with the proper page value saying which page is this), so the JSON for first page should look like this:

{
    "total": "3",
    "page": "1",
    "records": "5",
    "rows": [
        { "Id": "1", "model": "shiver", "cc": "750", "nation": "italy", "prod": "aprilia" },
        { "Id": "2", "model": "monster", "cc": "696", "nation": "italy", "prod": "ducati" }
    ]
}

jqGrid will make further request for next pages, you should inspect page and rows parameters of the request. The first will tell you which page you should send back and the second will tell what is the current page size (this is important because you have used rowList option, so the page size can be changed).

tpeczek
  • 23,867
  • 3
  • 74
  • 77
  • Thanks a lot! I'm a newbie with jqgrid... Can i ask you how i can tell jqgrid to make multiple requests for the other pages? 'Cause i've used your type of json, and now the first pages is loaded, but inspecting the "page" parameter of the request it never became 2, or 3.. – zibibbalibbo Oct 12 '12 at 09:03
  • @user1740490 You don't have the controls to change page in your pager? – tpeczek Oct 12 '12 at 09:06
  • I have the 2 arrow near the page number.. !re you talking about them? – zibibbalibbo Oct 12 '12 at 09:17
  • @user1740490 Yes, some of them (depending on which page you are) should be enabled. If you click it jqGrid should generate a GET request with URL similiar to this: `test.json?_search=false&nd=1350033533559&rows=2&page=2&sidx=id&sord=desc` this is where you should get your parameters from. Please check what is the URL generated in your case when you are trying to change the page with those arrows. – tpeczek Oct 12 '12 at 09:23
  • I have them active on the first page (only the ones for the "next page" and "last page") but if i click them nothing is happening.. But i noticed that the "Loading..." popup of jqgrid never disappear, also when the data of my first json are displayed.. Could it be the reason? – zibibbalibbo Oct 12 '12 at 09:26
  • @user1740490 Yes, in this case your `loadComplete` callback is to be suspected (there might be an exception there). You have a `grid` variable there, how is it defined? – tpeczek Oct 12 '12 at 09:30
  • Perfect! Now it runs! You were right, the problem was in the grid variable! Thanks a lot for the help!! – zibibbalibbo Oct 12 '12 at 09:37