I am working on an app, where a certain part of the application
requires a data grid have dynamic columns. This part of the issue is
easy. The hard part of my issue is creating the dataField for these
dynamic columns out of a dynamic array that I get back from coldfusion.
So with out further ado the code.
This is where I am building my array. That I will use to create and
populate my datagrid. As you can see it is fairly simply, a 2d array
with multiple objects. This array is built and display correctly.
private function dailyResult(event:ResultEvent):void{
stockInfo = new Array();
for(var i:int = 0; i < event.result.length;i++){
// top level of stock array
stockInfo.push({symbol:event.result[i].SYMB,uuid:event.result[i].STOCKUUID,
dailyData:[]});
// create stock daily items
var itemArr:Array = new Array();
for(var k:String in event.result[i].WHEN){
itemArr.push({adcl:event.result[i].ADCL[k],clam:event.result[i].CLAM[k],clvo:event.result[i].CLVO[k],when:event.result[i].WHEN[k]})
}
stockInfo[i].dailyData = itemArr;
}
Debug.show(stockInfo);
buildDG()
}
Here is my buildDG() method. Again fairly simple, I am using the
lenght of my previously created array to build the datagrid columns.
However it is when I get to this part dgc.dataField = 'open'; is when
I get into trouble. The data for the dataField is held in the
stockInfo.dailyData.adcl object. And for the life of me I can't see to
figure out how to get it to work.
private function buildDG():void{
var dgc:DataGridColumn;
var aColumnsNew:Array = dg.columns;
for(var i:int = 0; i < stockInfo.length;i++){
dgc = new DataGridColumn();
dgc.dataField = 'open';
dgc.width = 30;
dgc.headerText = stockInfo[i].symbol;
aColumnsNew.push(dgc);
//this.addChild(dg);
}
dg.columns = aColumnsNew;
dg.dataProvider = stockInfo;
Debug.show(aColumnsNew);
}
Any help with this would be greatly appreciated.