Is it possible to add DataGrid columns dynamically, after DataGrid has
been initialized?
I have the following scenario:
User loads swf file with DataGrid component in it, and passes a url as
parameter. ActionScript code makes an HttpRequest call to this url,
receives Xml data, parses it into columns and displays it in the DataGrid.
I do not know in advance, how many columns there will be. I tried to
make 'columns' array bindable and add instances of DataGridColumn into
it on the fly, but that has no effect on the DataGrid.
While DataGrid is able to figure out itself, how many columns there
are in a data provider, it sorts them in alphabetical order. I need to
set my own order.
Here's a code snippet:
MXML:
<mx:DataGrid dataProvider="{dataGrid_data}" id = "m_dataGrid"
columns="{dataGrid_columns}" initialize="makeCall()">
</mx:DataGrid>
<mx:script>
[Bindable]
public var dataGrid_data:ArrayCollection = new ArrayCollection();
[Bindable]
public var dataGrid_columns:Array = new Array();
public function makeCall() {
// code snipped
... populateData(dataGrid_data, dataGrid_columns);
// code snipped
}
public function populateData() {
// code snipped
dataGrid_columns.push(new DataGridColumn("col1"));
dataGrid_columns.push(new DataGridColumn("col2"));
...
// add data to provider
}
While provider works perfectly, columns array does not affect the
DataGrid at all. Is there any workaround for this?
Thanks a lot.