Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix addChiledNode not to expand rows if it is not set as such

  • Loading branch information...
commit ca304f1e4a06cb248ea8f25d67a7603f40f02413 1 parent c8dc112
@tonytomov authored
Showing with 41 additions and 41 deletions.
  1. +41 −41 js/grid.treegrid.js
View
82 js/grid.treegrid.js
@@ -551,7 +551,7 @@ $.jgrid.extend({
}
});
},
- addChildNode : function( nodeid, parentid, data ) {
+ addChildNode : function( nodeid, parentid, data, expandData ) {
//return this.each(function(){
var $t = this[0];
if(data) {
@@ -565,7 +565,7 @@ $.jgrid.extend({
right = $t.p.treeReader.right_field,
loaded = $t.p.treeReader.loaded,
method, parentindex, parentdata, parentlevel, i, len, max=0, rowind = parentid, leaf, maxright;
-
+ if(expandData===undefined) {expandData = false;}
if ( typeof nodeid === 'undefined' || nodeid === null ) {
i = $t.p.data.length-1;
if( i>= 0 ) {
@@ -574,48 +574,48 @@ $.jgrid.extend({
nodeid = max+1;
}
var prow = $($t).jqGrid('getInd', parentid);
- leaf = false;
- // if not a parent we assume root
- if ( parentid === undefined || parentid === null || parentid==="") {
- parentid = null;
- rowind = null;
- method = 'last';
- parentlevel = $t.p.tree_root_level;
- i = $t.p.data.length+1;
+ leaf = false;
+ // if not a parent we assume root
+ if ( parentid === undefined || parentid === null || parentid==="") {
+ parentid = null;
+ rowind = null;
+ method = 'last';
+ parentlevel = $t.p.tree_root_level;
+ i = $t.p.data.length+1;
+ } else {
+ method = 'after';
+ parentindex = $t.p._index[parentid];
+ parentdata = $t.p.data[parentindex];
+ parentid = parentdata[$t.p.localReader.id];
+ parentlevel = parseInt(parentdata[level],10)+1;
+ var childs = $($t).jqGrid('getFullTreeNode', parentdata);
+ // if there are child nodes get the last index of it
+ if(childs.length) {
+ i = childs[childs.length-1][$t.p.localReader.id];
+ rowind = i;
+ i = $($t).jqGrid('getInd',rowind)+1;
} else {
- method = 'after';
- parentindex = $t.p._index[parentid];
- parentdata = $t.p.data[parentindex];
- parentid = parentdata[$t.p.localReader.id];
- parentlevel = parseInt(parentdata[level],10)+1;
- var childs = $($t).jqGrid('getFullTreeNode', parentdata);
- // if there are child nodes get the last index of it
- if(childs.length) {
- i = childs[childs.length-1][$t.p.localReader.id];
- rowind = i;
- i = $($t).jqGrid('getInd',rowind)+1;
- } else {
- i = $($t).jqGrid('getInd', parentid)+1;
- }
- // if the node is leaf
- if(parentdata[isLeaf]) {
- leaf = true;
- parentdata[expanded] = true;
- //var prow = $($t).jqGrid('getInd', parentid);
- $($t.rows[prow])
- .find("span.cell-wrapperleaf").removeClass("cell-wrapperleaf").addClass("cell-wrapper")
- .end()
- .find("div.tree-leaf").removeClass($t.p.treeIcons.leaf+" tree-leaf").addClass($t.p.treeIcons.minus+" tree-minus");
- $t.p.data[parentindex][isLeaf] = false;
- parentdata[loaded] = true;
- }
+ i = $($t).jqGrid('getInd', parentid)+1;
+ }
+ // if the node is leaf
+ if(parentdata[isLeaf]) {
+ leaf = true;
+ parentdata[expanded] = true;
+ //var prow = $($t).jqGrid('getInd', parentid);
+ $($t.rows[prow])
+ .find("span.cell-wrapperleaf").removeClass("cell-wrapperleaf").addClass("cell-wrapper")
+ .end()
+ .find("div.tree-leaf").removeClass($t.p.treeIcons.leaf+" tree-leaf").addClass($t.p.treeIcons.minus+" tree-minus");
+ $t.p.data[parentindex][isLeaf] = false;
+ parentdata[loaded] = true;
}
- len = i+1;
+ }
+ len = i+1;
- data[expanded] = false;
- data[loaded] = true;
+ if( data[expanded]===undefined) {data[expanded]= false;}
+ if( data[loaded]===undefined ) { data[loaded] = false;}
data[level] = parentlevel;
- data[isLeaf] = true;
+ if( data[isLeaf]===undefined) {data[isLeaf]= true};
if( $t.p.treeGridModel === "adjacency") {
data[parent] = parentid;
}
@@ -669,7 +669,7 @@ $.jgrid.extend({
$($t).jqGrid('addRowData', nodeid, data, method, rowind);
$($t).jqGrid('setTreeNode', i, len);
}
- if(parentdata && !parentdata[expanded]) {
+ if(parentdata && !parentdata[expanded] && expandData) {
$($t.rows[prow])
.find("div.treeclick")
.click();
Please sign in to comment.
Something went wrong with that request. Please try again.