-1

I have json like

{
    "total": 7,
    "rows": [ 
        {"ID": "1","Code": "Code1" },
        { "ID": "2","Code": "Code2"},
        { "ID": "3", "Code": "Code3" },
        { "ID": "4", "Code": "Code4"},
        {"ID": "5","Code": "Code5"},
        {"ID": "6","Code": "Code6"},        
        {"ID": "7","Code": "Code7" }  
    ]
}

and I want to read this in jqGrid

I used in grid with

colNames: ['Code'], 
    colModel: [
        { name: 'Code', width: 100 }],


jsonReader: { repeatitems: false, id: "rows", root: function (obj) { return obj; } }.

but it dosn't work

3 Answers3

0

root shoud be rows, not object.

root: "rows"

or

root: function(obj) { return obj.rows; }
STO
  • 10,390
  • 8
  • 32
  • 32
0

Your json reader will be like this:

jsonReader: { repeatitems: false, id: "ID", root: "rows",cell:"code" }
Ashirvad
  • 2,367
  • 1
  • 16
  • 20
0

In general the usage of

jsonReader: { repeatitems: false, id: "ID"}

should be enough if you use loadonce: true additionally (see the demo). From the other side if you try to implement server side data paging you should extend the JSON data. By the way the current value of total corresponds to records input property. The total property should have the value of the total pages and not the total record number.

You don't posted the whole code which defines the grid. So you can has more errors as you posted. In any way I would recommend you to use loadError callback. See the answer for more details.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798