At init time, the size of the DG is not known so you get to dictate it
with the column widths, then all columns get resized proportionally.
After that it is sort of locked in so columns sizes are honored except
those at the end that will get squished to fit.  If you set
horizontalScrollPolicy="on" it won't resize the columns.
 
Why are you multiplying by 10?

________________________________

From: [email protected]
[mailto:[EMAIL PROTECTED] On Behalf Of akhilesh_iet
Sent: Sunday, December 09, 2007 11:16 PM
To: [email protected]
Subject: [flexcomponents] Dynamically rendering the data grid



In my project i have a requirement where i need to render the 
datagrid, the number( and names) of columns that need to be 
displayed will be provided at run time. I have created a sample 
application to acheive the same, but i am facing the problem ( last 
3-4 columns do not show up properly ) while rendring the grid for 
second time. Here is the code :'
<?xml version="1.0"?>
<!-- DataGrid control example. -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml
<http://www.adobe.com/2006/mxml> " 
initialize="initializeHandler(event)">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection; 
private function initializeHandler
(event:Event):void {

var arrayList:ArrayCollection = new 
ArrayCollection();
var fieldData:Array = new Array();
for ( var i:int = 0 ; i < 8 ; i ++){
fieldData = new Array(8);
for ( var j:int = 0 ; j < 
8 ; j++){
fieldData[j]
= "column " + i + ", " + j;
}
arrayList.addItem(fieldData);
}
kapil.dataProvider = arrayList;
kapil.invalidateDisplayList();

for ( j = 0 ; j < 8 ; j++){


kapil.columns
[j].headerText = "ColumnHeaderText " + j;
kapil.columns
[j].width = kapil.columns[j].headerText.toString().length * 10;
}

}

private function kapili(event:Event):void{
var arrayList:ArrayCollection = new 
ArrayCollection();
kapil.dataProvider = arrayList;
var fieldData:Array = new Array();
for ( var i:int = 0 ; i < 8 ; i ++){
fieldData = new Array(8);
for ( var j:int = 0 ; j < 
8 ; j++){
fieldData[j]
= "column " + i + ", " + j;
}
arrayList.addItem(fieldData);
}
kapil.dataProvider = arrayList; 
kapil.invalidateDisplayList(); 

for ( j = 0 ; j < 8 ; j++){
kapil.columns[j].headerText 
= "ColumnHeaderText " + j;
kapil.columns[j].width = 
kapil.columns[j].headerText.toString().length * 10;
} 

}
]]>
</mx:Script>

<mx:DataGrid id="kapil" />
<mx:Button label="Button" click="kapili(event)"/>
</mx:Application> 

please provide your comments ASAP.

regards
Akhilesh 



 

Reply via email to