diff --git a/treegrid.js b/treegrid.js index 9ef19ad..684c539 100644 --- a/treegrid.js +++ b/treegrid.js @@ -1,7 +1,7 @@ /** * Very simple and fast tree grid/table, compatible with dynamic loading and jQuery fixedHeaderTable * License: MPL 2.0+, (c) Vitaliy Filippov 2016+ - * Version: 2016-03-10 + * Version: 2016-03-25 */ /** @@ -401,7 +401,14 @@ TreeGridNode.prototype.setChildren = function(isLeaf, newChildren) this.tr.cells[0].firstChild.className = this.collapsed ? 'collapser collapser-collapsed' : 'collapser collapser-expanded'; } this.children = []; + this.addChildren(newChildren); +} + +TreeGridNode.prototype.addChildren = function(newChildren) +{ var insertBefore = this.tr && this.tr.nextSibling; + while (insertBefore && insertBefore.nextSibling && insertBefore._node.level > this.level) + insertBefore = insertBefore.nextSibling; for (var i = 0; i < newChildren.length; i++) this.children.push(new TreeGridNode(newChildren[i], this.grid, this.level+1, insertBefore, this.collapsed)); }