Forum
23:12
09/04/2014
I have following JSON object format.
{"success":true,"message":[null],"page":0,"total":0,"records":0,"rows":[ {"userid":8,"username":"XYZ","userdetails":{"detailid":84,"city":"SDFE","state":"OPUY"}}, {"userid":9,"username":"ABCD","userdetails":{"detailid":85,"city":"QWSDF","state":"PLKJH"}} }
I want to display Username,City,State from the JSON data. It only shows the usename field, other fields are not able to display as userdetails is nested JSON object.
My JQgrid Model is as follows.
jq("#grid").jqGrid({ url:'${pageContext.servletContext.contextPath}/grid/load.action', datatype: 'json', mtype: 'GET', colNames:['Id', 'User Name', 'City','State'], colModel:[ {name:'userid',index:'userid', width:55,editable:true,editoptions:{readonly:false,size:10},hidden:true}, {name:'username',index:'username', width:100,editable:true,edittype:'text', editoptions: { dataInit: function (elem) { myAutocomplete(elem, "${pageContext.servletContext.contextPath}/grid/autocomplete.action"); } }}, {name:'city',index:'city', width:100,editable:true, editrules:{required:true}, editoptions:{size:10}}, {name:'state',index:'state', width:100,editable:true, editrules:{required:true}, editoptions:{size:10}} ], postData: { }, rowNum:20, rowList:[20,40,60], height: 200, autowidth: true, rownumbers: true, pager: '#pager', sortname: 'id', viewrecords: true, sortorder: "asc", caption:"Users", emptyrecords: "Empty records", loadonce: false, editurl:'${pageContext.servletContext.contextPath}/grid/edit.action', loadError : function(xhr,st,err) { console.log('display error : '+err); jq("#rsperror").html("Type: "+st+"; Response: "+ xhr.status + " "+xhr.statusText); }, loadComplete: function() { }, jsonReader : { root: "rows", page: "page", total: "total", records: "records", repeatitems: false, cell: "cell", id: "id" } }); jq("#grid").jqGrid('navGrid','#pager', {edit:true,add:true,del:false,search:false}, { }, { }, { }, { sopt:['eq', 'ne', 'lt', 'gt', 'cn', 'bw', 'ew'], closeOnEscape: true, multipleSearch: true, closeAfterSearch: true } ); });
Please suggest me the solution for how to load json data when it has nested object in it.
15:02
Moderators
30/10/2007
Hello,
You will need to configure jsonmap in colModel. See docsumentation and online demo. we have such examples.
Regards
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
Most Users Ever Online: 715
Currently Online:
41 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66