I have an XML file having a structure like this:
<products>
<product>
<id>P1</id>
<name>PRODUCT 1</name>
<accessories>
<accessory>
<id>acc_1</id>
<name></name>
</accessory>
<accessory>
<id>acc_2</id>
<name></name>
</accessory>
<accessory>
<id>acc_3</id>
<name></name>
</accessory>
</accessories>
</product>
<product>
<id>P2</id>
<name>PRODUCT 2</name>
<accessories>
<accessory>
<id>acc_1</id>
<name>ACC 1</name>
</accessory>
<accessory>
<id>acc_2</id>
<name>ACC 2</name>
</accessory>
</accessories>
</product>
</products>
I want to have all products in a Grid using jqGrid and the accessories in a subgrid for each product (with the plus icon).
For that I use the following js:
var myGrid = $("#prods").jqGrid({
url: 'products.xml',
datatype: "xml",
colNames:["id", "Name"],
colModel:[
{name:"id", key: true, index:"id", width:90, xmlmap:"id", sortable:true},
{name:"Name", index:"Name", width:100, sortable:true, xmlmap:"name"}}
],
width: 300,
height:480,
ignoreCase: true,
viewrecords: true,
loadonce: true,
sortname: 'Name',
sortorder: "asc",
sortable: true,
pager: "#pager",
xmlReader: {
root: "products",
row: "product",
repeatitems: false,
id: "sku",
subgrid: {
root: "products>product>accessories",
row: "accessory",
repeatitems:false,
id: "id"
}
},
caption: "Products",
subGrid: true,
subGridRowExpanded: function(grid_id, row_id) {
var subgrid_table_id;
subgrid_table_id = grid_id + "_t";
jQuery("#" + grid_id).html("<table id='" + subgrid_table_id + "' class='scroll'></table>");
jQuery("#" + subgrid_table_id).jqGrid( {
colNames: [ 'Id', 'Name'],
colModel: [
{name:"accid",index:"accid",width:80, xmlmap:"id"},
{name:"accname",index:"accname",width:80, xmlmap:"name"}
],
height: 50,
rowNum:10,
});
}
});
It does not shows the subrecords. I tried also to put the same root / row in the subgrid as the parent grid and using the reference like this for the ID: "products>product>accessories>accessory>id" but it does not work as well.
Anybody have already found an example which works (in fact my data source is the same file for both grid/subgrid) like I want.
Hope this is clear enough, otherwise do not hesitate to comment for requesting more details.