0

I ran into a problem with jqGrid and JSON data. Basically the grid will not display any of the data, but instead outputs [object Object] into the first column of the table. Below is a snippet of the data I am using. It is valid JSON.

{
    "currpage": "1",
    "totalpages": "3",
    "totalrecords": "70",
    "rows": [
    {
        "id": "uid\u003dAndrewBryant",
        "cells": [
            {
                "HOURS_ENTITLED": "203",
                "HOURS_TAKEN": 0,
                "NAME": "uid\u003dAndrewBryant",
                "SICKNESS_TAKEN": 0,
                "TAKEN_TOIL": 0,
                "TOTAL_TOIL": 0,
                "YEAR_ENTILEMENT": "2011"
            }
        ]
    },

Below is the code I am using to call the jqGrid functionality:

$(document).ready(function() {
    $("#statsTable").jqGrid({
        url: "http://cw-epuip-d01.tm-gnet.com:10040/wps/PA_Resource_Manager_1/JSONServlet",
        datatype: "json",
        mtype: "get",
        jsonReader : {
            root: "rows",
            cell:"cells",
            page: "currpage",
              total: "totalpages",
              records: "totalrecords",
               id: "id"
        },
        colNames: ['NAME', 'HOURS ENTITLED', 'HOURS TAKEN'  ],
        colModel: [
                  {name:'NAME', index:'NAME'},
                  {name:'HOURS_ENTITLED', index:'HOURS_ENTITLED'},
                  {name:'HOURS_TAKEN', index:'HOURS_TAKEN'}
            ]
    }
    );
});

What am I missing?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
jonnyhitek
  • 1,521
  • 4
  • 17
  • 31

1 Answers1

0

First of all I would not recommend you to use "uid=AndrewBryant" as id value. You should understand that it will follows to the <tr id="uid=AndrewBryant"> which is really bad. See here for the description of correct ids.

Next you can read the JSON file which server currently produce with small changes in the jsonReader (additional repeatitems:false) and additional jsonmap property for every column

jsonReader : {
    root: "rows",
    page: "currpage",
    total: "totalpages",
    records: "totalrecords",
    repeatitems: false
},
colModel: [
          {name:'NAME', index:'NAME',jsonmap:'cells.0.NAME'},
          {name:'HOURS_ENTITLED', index:'HOURS_ENTITLED',
           jsonmap:'cells.0.HOURS_ENTITLED'},
          {name:'HOURS_TAKEN', index:'HOURS_TAKEN',jsonmap:'cells.0.HOURS_TAKEN'}
]

after the changes the grid will be displayed: see here.

Nevertheless I would recommend you better to make some changes in server code and produce more standard JSON which can be read without jsonmap. See the jqGrid documentation.

Oleg
  • 220,925
  • 34
  • 403
  • 798