PDA

View Full Version : I make a function to hide columns which are empty. How can I optimize it?



cloudmonkeypeng
5 Mar 2014, 7:12 PM
I want to hide the columns which is empty. But the code makes ie8 crash sometimes,when the number of columns is more than 20.
How can I optimize it?

Ext.define('Ext.ux.CommonGrid', { extend: 'Ext.grid.Panel',
columnLines: true,
layout:'fit',
autoScroll:true,
closable:true,
loadMask:true,
dockedItems: [{
xtype: 'toolbar',
dock: 'top',
loadMask:true,
items: [
{
xtype: 'button',
text: 'arrange',
handler:function(b){
var myMask = new Ext.LoadMask(this.ownerCt.ownerCt.ownerCt,{
msg:"Arranging...",
removeMask:true
});
myMask.show();
var grid = this.ownerCt.ownerCt;
var columns = grid.getView().getHeaderCt().getGridColumns();
var rowsNum = 5;
if (grid.getStore().data.length<rowsNum)
rowsNum = grid.getStore().data.length;
for(var i=0;i<columns.length;i++){
var hide = true;
for(var m=0;m<rowsNum;m++){
if(grid.getStore().getAt(m).data[columns[i].dataIndex]!=null){
hide = false;
break;
}
}
if(hide) columns[i].hide();
}
myMask.hide();
}
}
]
}]
});

scottmartin
5 Mar 2014, 8:28 PM
I would suggest using reconfigure instead of hiding all of those columns.

You can also try using Ext.suspendLayouts((), Ext.resumeLayouts(true) to see if the helps in your case.