I have the local json string as follows:
var jsonObj = {
"page": "1",
"records": "2",
"rows": [
{"id":"1","firstName":"ABC","lastName":"XYZ","city":"blr","state":"Karnataka","arr":[
{"arr1":"value1","arr2":"value2"},{"arr1":"value3","arr2":"value4"}]},
{"id":"2","firstName":"DEF","lastName":"PQR","city":"Mumbai","state":"Maharashtra","arr":[{"arr1":"result1","arr2":"result2"},{"arr1":"result3","arr2":"result4"}]}]};
Using jqgrid
i would like to show the above json string in two rows, having id1 and id2, however for nested array (i.e. arr in above string) i would like to show them as sub rows of their parent row but not as a sub grid.
The other columns in the sub row should contain duplicate data as parent row except for two columns i.e. arr1 and arr2. The sub rows should not be visible on load. There should be a plus/traingle icon on click of which the sub row should expand.
This is the code i used to display jqgrid
.
$("#list").jqGrid({
datastr : jsonObj,
datatype : "jsonstring",
colNames : [ 'Id', 'FirstName', 'LastName', 'City', 'State', 'Array1', 'Array2' ],
colModel : [ {
name : 'id',
index : 'id',
width : 100,
key : true
}, {
name : 'firstName',
index : 'firstName',
width : 150
}, {
name : 'lastName',
index : 'lastName',
width : 150
}, {
name : 'city',
index : 'city',
width : 100
}, {
name : 'state',
index : 'state',
width : 100
}, {
name : 'arr1',
index : 'arr1',
width : 100,
jsonmap : "arr.0.arr1"
}, {
name : 'arr2',
index : 'arr2',
width : 100,
jsonmap : "arr.0.arr2"
} ],
pager : '#pager',
rowNum : 10,
rowList : [ 10, 20, 30 ],
sortname : 'id',
sortorder : 'desc',
viewrecords : true,
gridview : true,
caption : 'JSON Array',
jsonReader : {
repeatitems : false, root: "rows"
}
});