jqGrid with JSON data renders table as empty

By : jgreep
Source: Stackoverflow.com

I'm trying to create a jqgrid, but the table is empty. The table renders, but the data doesn't show.

The data I'm getting back from the php call is:

{"id":"2:1","cell":["1","image","Chief Scout","Highest Award test","0"]},
{"id":"2:2","cell":["2","image","Link Badge","When you are invested as a Scout, you may be eligible to receive a Link Badge. (See page 45)","0"]},
{"id":"2:3","cell":["3","image","Pioneer Scout","Upon completion of requirements, the youth is invested as a Pioneer Scout","0"]},
{"id":"2:4","cell":["4","image","Voyageur Scout Award","Voyageur Scout Award is the right after Pioneer Scout.","0"]},
{"id":"2:5","cell":["5","image","Voyageur Citizenship","Learning about and caring for your community.","0"]},
{"id":"2:6","cell":["6","image","Fish and Wildlife","Demonstrate your knowledge and involvement in fish and wildlife management.","0"]},
{"id":"2:7","cell":["7","image","Photography","To recognize photography knowledge and skills","0"]},
{"id":"2:8","cell":["8","image","Recycling","Demonstrate your knowledge and involvement in Recycling","0"]},
{"id":"2:10","cell":["10","image","Voyageur Leadership ","Show leadership ability","0"]},
{"id":"2:11","cell":["11","image","World Conservation","World Conservation Badge","0"]}

The javascript configuration looks like so:

$("#"+tableId).jqGrid ({
    dataType : 'json',
    colModel : [
        {name:'awardId', width:30, sortable:true, align:'center'},
        {name:'badge', width:40, sortable:false, align:'center'},
        {name:'name', width:180, sortable:true, align:'left'},
        {name:'description', width:380, sortable:true, align:'left'},
        {name:'selected', width:0, sortable:false, align:'center'}
    sortname: "awardId",
    sortorder: "asc",
    pager: $('#'+tableId+'_pager'),
    caption: 'Awards',
    imgpath: 'scripts/jqGrid/themes/green/images',
    jsonReader : { 
        root: "rows", 
        page: "page", 
        total: "total", 
        records: "records", 
        repeatitems: true, 
        cell: "cell", 
        id: "id",
        userdata: "userdata", 
        subgrid: {root:"rows", repeatitems: true, cell:"cell" } 
    width: 700,
    height: 200

The HTML looks like:

<table class="awardsList" id="awardsList2" class="scroll" name="awardsList" />
<div id="awardsList2_pager" class="scroll"></div>

I'm not sure that I needed to define jsonReader, since I've tried to keep to the default. If the php code will help, I can post it too.

By : jgreep


I was working with WAMP 2.4, I was being crazy with this problem, I tried lot of things, like install previous versions of PHP and like 5.2, een I tried in Windows XP, and lots of jqGrid options. Well thank to Oleg finally and Mariusz I find the only line:

$responce = new stdClass(); 

Before the use of $responce could solve all, and now my grid is works Great!!!

Thanks my friends.

By : Alfx2

In my case, the problem was caused by the following line of PHP code (which was taken from jqGrid demo):

$responce->page = $page;

What is wrong here is that: I am accessing property page of object $responce without creating it first. This caused Apache to display the following error message:

Strict Standards: Creating default object from empty value in /home/mariusz/public_html/rezerwacja/apps/frontend/modules/service/actions/actions.class.php on line 35

And finally the error message used to be send to json reader within the script.

I fixed the problem by creating empty object:

$responce = new stdClass();
By : Mariusz

Guys just want to help you in this. I got following worked:


var mydata1 = { "page": "1", "total": 1, "records": "4","rows": [{ "id": 1, "cell": ["1", "cell11", "values1" ] },
    { "id": 2, "cell": ["2", "cell21", "values1"] },
    { "id": 3, "cell": ["3", "cell21", "values1"] },
    { "id": 4, "cell": ["4", "cell21", "values1"] }

//Mark below important line. datatype "jsonstring" worked for me instead of "json".

datatype: "jsonstring",

contentType: "application/json; charset=utf-8",

datastr: mydata1,

colNames: ['Id1', 'Name1', 'Values1'],

colModel: [
      { name: 'id1', index: 'id1', width: 55 },
      { name: 'name1', index: 'name1', width: 80, align: 'right', sorttype: 'string' },
      { name: 'values1', index: 'values1', width: 80, align: 'right', sorttype: 'string'}],


This video can help you solving your question :)
By: admin