PDA

View Full Version : How to figure out which columns are hidden? [Solved]



crxtech
18 Jun 2009, 6:46 AM
I have a grid with the custom filters plugin, and an export to excel feature. I want to the excel export to look exactly like the grid. I have it all working perfect, except I don't know how to figure out which columns are hidden, so I can pass which column not to export to excel...

This is what I am doing now:

buttons: [{
text: "Export",
id:'export-btn1',
icon:'images/excel.gif',
iconCls:'x-btn-text-icon',
tooltip: "Click here to export to Excel",
handler : function(){
window.open('logExport.cfm?report=log&'+Ext.urlEncode(filters.buildQuery(filters.getFilterData()))+'&dir='+logGrid.store.getSortState().direction+'&sort='+logGrid.store.getSortState().field);
}
}]

Animal
18 Jun 2009, 6:50 AM
Loop through them, testing the isHidden method:-/

Condor
18 Jun 2009, 6:52 AM
Something like:

'&columns=' + grid.getColumnModel().findColumnsBy(function(c){return !c.hidden;}).join(',')

crxtech
18 Jun 2009, 12:16 PM
Thank you both for you help. The code below works perfect for my usage:

I ended up using this code posted by mjlecomte:

Ext.override(Ext.grid.ColumnModel, {

/**
* Returns an array of column config objects for the visibility given.
* @param {Boolean} hidden True returns visible columns; False returns hidden columns (defaults to True).
* @param {String} cfg Specify the config property to return (defaults to the config).
* @return {Array} result
*/
getColumnsVisible : function(visibility, cfg){
var visible = (visibility === false) ? false : true;
var r = [];
for(var i = 0, len = this.config.length; i < len; i++){
var c = this.config[i];
var hidden = c.hidden ? true : false;
if(hidden !== visible){
r[r.length] = c[cfg] || c;
}
}
return r;
}
});

usage:

Grid.getColumnModel().getColumnsVisible(true, 'dataIndex')