Jquery jqgrid property with dot operator

I have json with a property having a dot "." operator in it. When I try to make my grid, it becomes empty (no error).

Here is 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:

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

Please help, what am I missing here?

Thanks!

+1
source share
2 answers

I find you an interesting question. This is close to the problem described here , but in the case of JSON instead of XML.

The problem is that jqGrid is trying to read rows relative to obj.cell.function.code instead of obj.cell['function.code'] . To allow jqGrid to read data correctly, you can use functions like 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']; } } ] 

As you can see on the demo , the approach work.

+1
source

try it

 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"]' }], 
0
source

Source: https://habr.com/ru/post/971223/


All Articles