PDA

View Full Version : How do I get the column name of my grid?



marxan
6 Sep 2012, 12:52 AM
Everything is in the title :-)

Thanks.

Farish
6 Sep 2012, 1:05 AM
the question is where do you want to access it...

marxan
6 Sep 2012, 1:14 AM
Well, what I want to do is the following:

I have a multiselect combo with years's value.

In my grid, I have several columns with the same value so year 2009 is a column, 2010 another and so on...

When I select a value in my combo I want to keep only this column and hide all others.

For the moment what I do is to first hide all columns and then display the one I want to keep.
But as I have many records in the grid, this code is very slow.

So I would to check if the column name is the same as the values selected in the combo as I can display this column and then hide the others.



if (!combo._isClearingValues) {
Global.years = combo.getValue();
var arrayYears = combo.getValue().toString().split(",");
valueSelected = arrayYears[arrayYears.length-1];


var newYears = new Array();
if (valueSelected == 'All years' || combo.getValue() == '')
{
newYears.push('All years');
combo._isClearingValues = true;


Global.years = '';

combo.clearValue();
combo.setValue('All years');
delete combo._isClearingValues;
}
else
{
for (var i = 0; i < arrayYears.length; i++) {
if (arrayYears[i] != 'All years')
{
newYears.push(arrayYears[i]);
}
}

combo._isClearingValues = true;


Global.years = newYears;

combo.clearValue();
combo.setValue(Global.years);
delete combo._isClearingValues;
}




if (Global.indicatorGroup == 'TRAPS')
{ grid = Ext.getCmp('metrSeriesGridId'); //id declared in the grid view
}
else if (Global.indicatorGroup == 'NRR')
{ grid = Ext.getCmp('nrrSeriesGridId');
}



var years = Global.years.toString();


var valueArray = years.split(",");


// I set all the column to be visible



alert(valueArray);
for (var j = 5; j < 15; j++) {
grid.columns[j].setVisible(false);
}
for (var i = 0; i < valueArray.length; i++) {
//for (var j = 5; j<15; j++)
//{


switch (valueArray[i])
{
case 'All years':
for (var i = 5; i < 15; i++) {
grid.columns[i].setVisible(true);
}
break;
case '':
for (var i = 5; i < 15; i++) {
grid.columns[i].setVisible(true);
}
break;
case '2002':
grid.columns[6].setVisible(true);
break;
case '2003':
grid.columns[7].setVisible(true);
break;
case '2004':
grid.columns[8].setVisible(true);
break;
case '2005':
grid.columns[9].setVisible(true);
break;
case '2006':
grid.columns[10].setVisible(true);
break;
case '2007':
grid.columns[11].setVisible(true);
break;
case '2008':
grid.columns[12].setVisible(true);
break;
case '2009':
grid.columns[13].setVisible(true);
break;
case '2010':
grid.columns[14].setVisible(true);
break;
default:
//alert(grid.column.getGridColumns);
for (var i = 5; i < 15; i++) {
grid.columns[5].setVisible(false);

}
break;

// }
}
}
}

Farish
6 Sep 2012, 1:40 AM
you can assign an id to your grid columns e.g.


{ id: 'column_2008', header: '2008', dataIndex: '2008', flex:1, hidden: true }

and then use this id to show or hide columns


for(var i=0; i<selectedYears.length; i++)
{
Ext.getCmp('column_' + selectedYears[i]).show();
}

In this example, selectedYears would be the array containing the selection of your combobox through which you loop and show only the selected years. You can configure the columns to be hidden by default as shown above.

marxan
7 Sep 2012, 6:20 AM
Thanks!

you can assign an id to your grid columns e.g.


{ id: 'column_2008', header: '2008', dataIndex: '2008', flex:1, hidden: true }

and then use this id to show or hide columns


for(var i=0; i<selectedYears.length; i++)
{
Ext.getCmp('column_' + selectedYears[i]).show();
}

In this example, selectedYears would be the array containing the selection of your combobox through which you loop and show only the selected years. You can configure the columns to be hidden by default as shown above.