1

I have a json with a property having dot "." operator in it. When im trying to render my grid, it comes up as blank (without any errors).

Here's my JSON:

{
            "total":1,
        "page":1,
        "records":2,
        "rows":[{
                "id":2110040,
                "cell":{
                "function.code":"dsadad",
                        "service.name":"dsadasda"

                }
            },
            {
                "id":2115040,
                "cell":{
                 "function.code":"iuiyuiy",
                     "service.name":"iyuiyuiy"

                }
            }
        ]
    }

this is my colModel

colModel : [ {
        name : 'service.name',
        search : 'true',
        editable : true,
        //index : 'service.name',
        width : 200,
        jsonmap : "cell.service.name"           
    },
    {
        name : 'function.code',
        search : 'true',
        editable : true,
        sortable:true,
        //index : 'function.code',
        width : 200,
        jsonmap : "cell.function.code"          
    }],

JSON reader is:

jsonReader : {
        repeatitems : false,
        root : "rows",
        cell : "cell",
        id : "id",
        page : "page",
        records : "records"
    },

Please help,what am i missing here ??

Thanks!

user620339
  • 851
  • 3
  • 20
  • 42

2 Answers2

2

I find you question interesting. It's close to the problem described here, but in case of JSON instead of XML.

The problem is that jqGrid try to read rows with respect of obj.cell.function.code instead of obj.cell['function.code']. To let jqGrid to read the data correctly you can use functions as the jsonmap:

colModel: [
    {
        name: 'service_name',
        search: 'true',
        editable: true,
        width: 200,
        jsonmap: function (obj) {
            return obj.cell['service.name'];
        }
    },
    {
        name: 'function_code',
        search: 'true',
        editable: true,
        sortable: true,
        width: 200,
        jsonmap: function (obj) {
            return obj.cell['function.code'];
        }
    }
]

How you can see on the demo the approach work.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • @user620339: By the way [another demo](http://www.ok-soft-gmbh.com/jqGrid/user620339_old.htm) from [your old answer](http://stackoverflow.com/questions/6853457/jquery-jqgrid-renders-empty-table/6905206#6905206) works also. – Oleg Aug 04 '11 at 13:48
0

Try this

colModel : [ {
        name : 'service.name',
        search : 'true',
        editable : true,
        //index : 'service.name',
        width : 200,
        jsonmap : 'cell["service.name"]'           
    },
    {
        name : 'function.code',
        search : 'true',
        editable : true,
        sortable:true,
        //index : 'function.code',
        width : 200,
        jsonmap : 'cell["function.code"]'          
    }],
ShankarSangoli
  • 69,612
  • 13
  • 93
  • 124
  • Then I think you cannot use dot in property name of a json object. You might use underscore or someother character like $. Take a look at this [link](http://google-styleguide.googlecode.com/svn/trunk/jsoncstyleguide.xml?showone=Property_Name_Format#Property_Name_Format) – ShankarSangoli Aug 01 '11 at 19:19
  • Not sure if JSON itself is the reason or is it JqGrid, because I was using flexigrid before this with same JSON format. Anyways, thanks for your help Shankar. – user620339 Aug 01 '11 at 19:47