PDA

View Full Version : GridView fitColumnsToContainer should ignore hidden columns



jarrod
27 Oct 2006, 11:10 PM
Bug as above, probably happens to other similar functions as well.

jack.slocum
28 Oct 2006, 6:28 AM
I'll go through them. I'll let you know when it's corrected.

jarrod
30 Oct 2006, 10:48 PM
Additionally, is it possible to add support for fixed width columns?

Typically, these columns will contain just an icon image or a checkbox and should not be resizable.

Animal
31 Oct 2006, 12:43 AM
Yes, good point. I'm going to be adding checkboxes to a lot of my grids. The req's here are to be able to apply operations to groups of entities.

I suppose I could use regular multi-select, but they like checkboxes.

Could a custom SelectionModel add a "phantom" column containing a checkbox? I suppose the ColumnModel would have to co-operate with any new CheckboxSelectionModel implementation. I'll think about this.

jarrod
31 Oct 2006, 6:09 AM
Just wrote a method for the grid, similar to GridView's fitColumnsToContainer().

It proportionately distributes the excess (or shortage) of width across columns which are neither hidden nor fixed width.


fitColumns : function(){
var view = this.getView();
var colModel = this.colModel;
var colCount = colModel.getColumnCount();
var wrap = view.wrap;
var cols = [];
var width = 0;
var i, w;

for (i = 0; i < colCount; i++){
var config = colModel.config[i];
if (!config.fixed && !config.hidden){
w = colModel.getColumnWidth(i);
cols.push(i);
cols.push(w);
width += w;
}
}
var frac = (wrap.clientWidth - colModel.getTotalWidth())/width;
while (cols.length){
w = cols.pop();
i = cols.pop();
colModel.setColumnWidth(i, Math.floor(w + w*frac), true);
}
view.updateColumns();
}

jack.slocum
31 Oct 2006, 1:49 PM
Cool Jarrod, thanks. I will add it in. I will have to change the direct config access to method calls to support extended ColumnModels.

jack.slocum
31 Oct 2006, 2:13 PM
Here's what I ended up adding (I added it to GridView not the grid):



fitColumns : function(){
var cm = this.grid.colModel;
var colCount = cm.getColumnCount();
var cols = [];
var width = 0;
var i, w;
for (i = 0; i < colCount; i++){
if(!cm.isHidden(i) && !cm.isFixed(i)){
w = cm.getColumnWidth(i);
cols.push(i);
cols.push(w);
width += w;
}
}
var frac = (this.wrap.clientWidth - cm.getTotalWidth())/width;
while (cols.length){
w = cols.pop();
i = cols.pop();
cm.setColumnWidth(i, Math.floor(w + w*frac), true);
}
this.updateColumns();
},


And:



YAHOO.ext.grid.GridView.prototype.fitColumnsToContainer =
YAHOO.ext.grid.GridView.prototype.fitColumns;


The isFixed method is new in .33 beta 2 and disables adding the splitter. It's probably similar to what you seem to have already. :)

jack.slocum
31 Oct 2006, 2:26 PM
To explain a little further:

There's are two new properties "resizable" and "fixed". resizable is less restrictive.

resizable simply limits the user from being able to resize to column. fixed limits the user from resizing AND prevents autosizing operations from resizing the column as well.

jarrod
31 Oct 2006, 6:57 PM
Cool, will switch over to these new features when I get hold of the updated beta 2 build... :D

Btw, it maybe useful to have a repository page for downloading interim builds?