Save existing groups when adding a grouping

rel-1.0
Vitaliy Filippov 2016-05-15 11:16:50 +03:00
parent 1bc8a8a13d
commit 2ba72731fc
1 changed files with 24 additions and 8 deletions

View File

@ -1,7 +1,7 @@
/** /**
* Very simple and fast tree grid/table, compatible with dynamic loading and jQuery fixedHeaderTable * Very simple and fast tree grid/table, compatible with dynamic loading and jQuery fixedHeaderTable
* License: MPL 2.0+, (c) Vitaliy Filippov 2016+ * License: MPL 2.0+, (c) Vitaliy Filippov 2016+
* Version: 2016-04-13 * Version: 2016-05-15
*/ */
/** /**
@ -347,8 +347,7 @@ function TreeGridNode(node, grid, level, insertBefore, startHidden)
else else
{ {
collapser.className = this.collapsed ? 'collapser collapser-collapsed' : 'collapser collapser-expanded'; collapser.className = this.collapsed ? 'collapser collapser-collapsed' : 'collapser collapser-expanded';
var self = this; addListener(collapser, 'click', this._getToggleHandler());
addListener(collapser, 'click', function(e) { self._toggleHandler(); });
} }
var c0 = this.tr.cells[0]; var c0 = this.tr.cells[0];
c0.childNodes.length ? c0.insertBefore(collapser, c0.firstChild) : c0.appendChild(collapser); c0.childNodes.length ? c0.insertBefore(collapser, c0.firstChild) : c0.appendChild(collapser);
@ -370,6 +369,14 @@ function TreeGridNode(node, grid, level, insertBefore, startHidden)
this.children.push(new TreeGridNode(node.children[i], grid, this.level+1, insertBefore, this.collapsed)); this.children.push(new TreeGridNode(node.children[i], grid, this.level+1, insertBefore, this.collapsed));
} }
TreeGridNode.prototype._getToggleHandler = function()
{
var self = this;
if (!self._toggleHandlerClosure)
self._toggleHandlerClosure = function(e) { self._toggleHandler(); };
return self._toggleHandlerClosure;
}
TreeGridNode.prototype._toggleHandler = function() TreeGridNode.prototype._toggleHandler = function()
{ {
if (!this.grid.onExpand(this)) if (!this.grid.onExpand(this))
@ -409,18 +416,27 @@ TreeGridNode.prototype.toggle = function()
TreeGridNode.prototype.setChildren = function(isLeaf, newChildren) TreeGridNode.prototype.setChildren = function(isLeaf, newChildren)
{ {
this.leaf = isLeaf;
if (!this.tr) if (!this.tr)
this.grid.tbody.innerHTML = ''; this.grid.tbody.innerHTML = '';
else else
{ {
while (this.tr.nextSibling && this.tr.nextSibling._node.level > this.level) while (this.tr.nextSibling && this.tr.nextSibling._node.level > this.level)
this.grid.tbody.removeChild(this.tr.nextSibling); this.grid.tbody.removeChild(this.tr.nextSibling);
if (this.leaf) if (this.leaf != isLeaf)
this.tr.cells[0].firstChild.className = 'collapser collapser-inactive'; {
else if (isLeaf)
this.tr.cells[0].firstChild.className = this.collapsed ? 'collapser collapser-collapsed' : 'collapser collapser-expanded'; {
this.tr.cells[0].firstChild.className = 'collapser collapser-inactive';
removeListener(this.tr.cells[0].firstChild, 'click', this._getToggleHandler());
}
else
{
this.tr.cells[0].firstChild.className = this.collapsed ? 'collapser collapser-collapsed' : 'collapser collapser-expanded';
addListener(this.tr.cells[0].firstChild, 'click', this._getToggleHandler());
}
}
} }
this.leaf = isLeaf;
this.children = []; this.children = [];
this.addChildren(newChildren); this.addChildren(newChildren);
} }