Currently this jq tree grid able to expand the nodes by clicking the treeIcons. Is it possible to enhance the grid able to expand the nodes by using onSelectRow?
Any help is appreciated.
$("#Grid1").jqGrid({
datatype: "jsonstring",
height: "auto",
loadui: "disable",
colNames: ['Category', 'ID', 'Name'],
colModel: [
{
name: 'Category', index: 'Category', width: 450, sortable: false
},
{
name: 'ID', index: 'ID', width: 200, align: "center", sortable: false
},
{ name: 'Name', index: 'Name', width: 200, align: "center", sortable: false },
],
jsonReader: {
repeatitems: false,
root: "root"
},
rowattr: function (rd) {
if (rd.parent === null) {
return { "class": "myParentClass" };
}
},
treeIcons: { leaf: 'ui-icon-blank' },
treeGrid: true,
treeGridModel: "adjacency",
ExpandColumn: "Period",
viewrecords: true,
loadonce: false,
search: false,
multiSort: false,
loadComplete: function () {
$("#Grid1 .ui-jqgrid .ui-widget-header").addClass('myheaderclass');
$("#Grid1 tr.jqgrow:odd").addClass('myOddAltRowClass');
$("#Grid1 tr.jqgrow:even").addClass('myAltRowClass');
}
});
$("#Grid1").jqGrid('setGridParam', { datastr: totalValue });
$("#Grid1").trigger('reloadGrid');
});
This is possible, but the code is tested in Guriddo jqGrid and I do not know if this will work on free-jqgrid you use. You can give it a try.
Be a sure that the option ExpandColClick is set to false.
Use the following code:
onSelectRow : function( rowid ) {
if(rowid)
{
var ind =$.jgrid.stripPref(this.p.idPrefix,rowid),
pos = this.p._index[ind],
isLeaf = this.p.treeReader.leaf_field,
expanded = this.p.treeReader.expanded_field;
if(!this.p.data[pos][isLeaf]){
if(this.p.data[pos][expanded]){
$(this).jqGrid("collapseRow",this.p.data[pos]);
$(this).jqGrid("collapseNode",this.p.data[pos]);
} else {
$(this).jqGrid("expandRow",this.p.data[pos]);
$(this).jqGrid("expandNode",this.p.data[pos]);
}
}
}
},
Enjoy