目前这个jq树网格能够通过单击树图标来展开节点。是否可以通过使用onSelectRow来增强网格以扩展节点?
任何帮助,不胜感激。
$("#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');
});
这是可能的,但是代码是在Guriddo jqGrid中测试的,我不知道这是否适用于您使用的free-jqgrid。你可以试一试。
-
请确保选项"展开ColClick"设置为 false。
-
使用以下代码:
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]); } } } },
享受