PDA

View Full Version : dynamically setting the width of columns of grid



Vamshi Barana
13 Sep 2013, 3:43 AM
Hi,

Please do anybody help me in setting the width of grid columns in extjs 3.4,

grid.getColumnModel().setColumnWidth(j,temp[j]);
alert(grid.getColumnModel().getColumnWidth(j));

if i give getColumnWidth ,its showing "100"...

Regards,
Vamshi

willigogs
13 Sep 2013, 4:23 AM
What is "j"?

You need to send the columnIndex - so this would be a number (0 = column 1, 1 = column 2, etc).

Example:
http://jsfiddle.net/Whinters/c7Hd3/

Vamshi Barana
13 Sep 2013, 5:01 AM
Hi,

'j ' is column No. and 'temp[j] ' is column width where trying to sset d column width in loop.


for (var k=0,j=0; k < tempArray.length,j < columns.length; k++,j++) {
if(columns[j].header==tempArray[k])
{
alert(temp[j]+'show'+j);
grid.getColumnModel().setHidden(j,false);
grid.getColumnModel().setColumnWidth(j,temp[j]);
//columns[k].width=temp[j];
alert(grid.getColumnModel().getColumnWidth(j));
}

else if(columns[j].header!=tempArray[k])
{

//grid.getColumnModel().setHidden(j,true);
//grid.getColumnModel().setColumnWidth(j,0);
}


}
}
Regards,
Vamshi

willigogs
13 Sep 2013, 6:36 AM
I've already shown in my example above that it works as anticipated, therefore the issue must lie in your code.

I would start by debugging all your values to check they are as you expect, and that you are correctly getting the columnModel, etc...