Add refreshCells()
parent
51792b58d8
commit
b619321b12
61
treegrid.js
61
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-05-15
|
||||
* Version: 2016-05-18
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -100,7 +100,10 @@ TreeGrid.prototype.onExpand = function(node)
|
|||
|
||||
TreeGrid.prototype._setProps = function(el, props)
|
||||
{
|
||||
if (typeof props == 'string')
|
||||
if (props === undefined || props === null)
|
||||
for (var j in this.bindProps)
|
||||
el[j] = '';
|
||||
else if (typeof props == 'string')
|
||||
el.innerHTML = props;
|
||||
else
|
||||
for (var j in this.bindProps)
|
||||
|
@ -341,26 +344,7 @@ function TreeGridNode(node, grid, level, insertBefore, startHidden)
|
|||
grid._setProps(td, this.cells[i]);
|
||||
this.tr.appendChild(td);
|
||||
}
|
||||
var collapser = document.createElement('div');
|
||||
if (this.leaf)
|
||||
collapser.className = 'collapser collapser-inactive';
|
||||
else
|
||||
{
|
||||
collapser.className = this.collapsed ? 'collapser collapser-collapsed' : 'collapser collapser-expanded';
|
||||
addListener(collapser, 'click', this._getToggleHandler());
|
||||
}
|
||||
var c0 = this.tr.cells[0];
|
||||
c0.childNodes.length ? c0.insertBefore(collapser, c0.firstChild) : c0.appendChild(collapser);
|
||||
if (grid._initialPadding === undefined)
|
||||
{
|
||||
var p0 = curStyle(c0).paddingLeft || '';
|
||||
if (p0.substr(p0.length-2) == 'px')
|
||||
p0 = parseInt(p0.substr(0, p0.length-2));
|
||||
else
|
||||
p0 = 0;
|
||||
grid._initialPadding = p0;
|
||||
}
|
||||
c0.style.paddingLeft = (grid._initialPadding + grid.levelIndent * level + 20) + 'px';
|
||||
this.addCollapser();
|
||||
insertBefore ? grid.tbody.insertBefore(this.tr, insertBefore) : grid.tbody.appendChild(this.tr);
|
||||
}
|
||||
this.children = [];
|
||||
|
@ -369,6 +353,37 @@ function TreeGridNode(node, grid, level, insertBefore, startHidden)
|
|||
this.children.push(new TreeGridNode(node.children[i], grid, this.level+1, insertBefore, this.collapsed));
|
||||
}
|
||||
|
||||
TreeGridNode.prototype.addCollapser = function()
|
||||
{
|
||||
var collapser = document.createElement('div');
|
||||
if (this.leaf)
|
||||
collapser.className = 'collapser collapser-inactive';
|
||||
else
|
||||
{
|
||||
collapser.className = this.collapsed ? 'collapser collapser-collapsed' : 'collapser collapser-expanded';
|
||||
addListener(collapser, 'click', this._getToggleHandler());
|
||||
}
|
||||
var c0 = this.tr.cells[0];
|
||||
c0.childNodes.length ? c0.insertBefore(collapser, c0.firstChild) : c0.appendChild(collapser);
|
||||
if (this.grid._initialPadding === undefined)
|
||||
{
|
||||
var p0 = curStyle(c0).paddingLeft || '';
|
||||
if (p0.substr(p0.length-2) == 'px')
|
||||
p0 = parseInt(p0.substr(0, p0.length-2));
|
||||
else
|
||||
p0 = 0;
|
||||
this.grid._initialPadding = p0;
|
||||
}
|
||||
c0.style.paddingLeft = (this.grid._initialPadding + this.grid.levelIndent * this.level + 20) + 'px';
|
||||
}
|
||||
|
||||
TreeGridNode.prototype.refreshCells = function()
|
||||
{
|
||||
for (var i = 0; i < this.grid.header.length; i++)
|
||||
this.grid._setProps(this.tr.cells[i], this.cells[i]);
|
||||
this.addCollapser();
|
||||
}
|
||||
|
||||
TreeGridNode.prototype._getToggleHandler = function()
|
||||
{
|
||||
var self = this;
|
||||
|
@ -441,6 +456,7 @@ TreeGridNode.prototype.setChildren = function(isLeaf, newChildren)
|
|||
this.addChildren(newChildren);
|
||||
}
|
||||
|
||||
// experimental
|
||||
TreeGridNode.prototype.syncChildren = function()
|
||||
{
|
||||
var i, j;
|
||||
|
@ -538,4 +554,5 @@ TreeGridNode.prototype.addChildren = function(nodes, insertBefore)
|
|||
e = this.children[insertBefore].tr;
|
||||
for (var i = 0; i < nodes.length; i++)
|
||||
this.children.splice(insertBefore+i, 0, new TreeGridNode(nodes[i], this.grid, this.level+1, e, this.collapsed));
|
||||
return this.children.slice(insertBefore, nodes.length);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue