PDA

View Full Version : Little improvement of the TreeGrid: autoExpandTreeColumn



Qtx
1 Feb 2010, 12:47 PM
The TreeGrid is a super thing, but I missed the feature autoExpandTreeColumn that allows expanding the first column (tree column) to take all free space.

I made the following adjustments. I copied the logics from the normal Grid. I hope it will be helpful for somebody and it will be taken into the next release.

TreeGrid.js

updateColumnWidths : function() {
var cols = this.columns,
colCount = cols.length,
groups = this.outerCt.query('colgroup'),
groupCount = groups.length,
c, g, i, j;

if(!this.userResized && this.autoExpandTreeColumn)
{
var other_width = 0;
for(i = 1; i<colCount; i++) {
c = cols[i];
other_width += (c.hidden ? 0 : c.width);
}

cols[0].width = this.getInnerWidth() - other_width - 1 - (this.scrollOffset || 0);
}

for(i = 0; i<colCount; i++) {
c = cols[i];
for(j = 0; j<groupCount; j++) {
g = groups[j];
g.childNodes[i].style.width = (c.hidden ? 0 : c.width) + 'px';
}
}

for(i = 0, groups = this.innerHd.query('td'), len = groups.length; i<len; i++) {
c = Ext.fly(groups[i]);
if(cols[i] && cols[i].hidden) {
c.addClass('x-treegrid-hd-hidden');
}
else {
c.removeClass('x-treegrid-hd-hidden');
}
}

var tcw = this.getTotalColumnWidth();

Ext.fly(this.innerHd.dom.firstChild).setWidth(tcw + (this.scrollOffset || 0));
this.outerCt.select('table').setWidth(tcw);
this.syncHeaderScroll();
},
TreeGridColumnResizer.js

onEnd : function(e){
var nw = this.proxy.getWidth(),
tree = this.tree;

this.proxy.remove();
delete this.dragHd;

tree.columns[this.hdIndex].width = nw;

tree.userResized = true;
tree.updateColumnWidths();

setTimeout(function(){
tree.headersDisabled = false;
}, 100);
}