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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
<div class="sfcode"> 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 } ); });</div> |
1 |
<br /> |
1 |
Please suggest me the solution for how to load json data when it has nested object in it. |
1 |
<br /> |
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top