Not sure, i'll have a play around. Maybe someone else can take a look.
--- In [email protected], "yossi.baram" <yossi.ba...@...> wrote: > > Hi, > > This is my columns: > > var columns:ArrayCollection = new ArrayCollection(); > columns.addItem("parent"); > columns.addItem("cell1"); > columns.addItem("cell2"); > columns.addItem("dummy"); > > > let say 3 rows: > > var data_:ArrayCollection = new ArrayCollection; > > rowData_ = new Map(); > rowData_.put(columns[0],"root1"); > rowData_.put(columns[1],55); > rowData_.put(columns[2],100); > rowData_.put(columns[3],myObject[0]); > data_.addItem(rowData_); > > rowData_ = new Map(); > rowData_.put(columns[0],"root1"); > rowData_.put(columns[1],34); > rowData_.put(columns[2],10); > rowData_.put(columns[3],myObject[1]); > data_.addItem(rowData_); > > rowData_ = new Map(); > rowData_.put(columns[0],"root1"); > rowData_.put(columns[1],6); > rowData_.put(columns[2],60); > rowData_.put(columns[3],myObject[2]); > data_.addItem(rowData_); > > > My Map (which is a HashMap): > > package > > { > > import flash.utils.Dictionary; > > > > public class Map > > { > > private var keysList:Array = new Array(); > > > private var valuesList:Array = new Array(); > > > private var entries:Dictionary = new Dictionary(); > > > public function Map(){ > > } > > > public function get length():uint > > { > > return valuesList.length; > > } > > > public function get(key:Object):Object > > { > > return entries[key]; > > } > > public function getKeyAt(index:uint):Object > > { > > return keysList[index]; > > } > > public function getKeysList():Array > > { > > return keysList.slice(); > > } > > > public function getValueAt(index:uint):Object > > { > > return valuesList[index]; > > } > > > public function getValuesList():Array > > { > > return valuesList.slice(); > > } > > > public function put(key:Object, value:Object):void > > { > > entries[key] = value; > > keysList.push(key); > > valuesList.push(value); > > } > > > public function remove(key:Object):void > > { > > delete entries[key]; > > > > var index:int = keysList.indexOf(key); > > if (index > -1) > > { > > keysList.splice(index, 1); > > valuesList.splice(index, 1); > > } > > } > > } > > } > > > The result is data_ ArrayCollection that holds a list of column/value > hashmap which is good. > > How do I take this array and translate it to a dataProvider for the > DataGrid, or set it differently to the grid? > > Thanks man > > > > > --- In [email protected], "bhaq1972" <mbhaque@> wrote: > > > > > Thanks for your time, realy > > > > thats okay. Can you send an example of column array and data array? > > > > > > > > --- In [email protected], "yossi.baram" <yossi.baram@> > > wrote: > > > > > > Hi man, > > > I am very sorry to say that I was not clear :( > > > myArray is what I need to create, I dont have it (I just gave as > > > example of what I need to create). > > > This is basically my problem, > > > How to build it based on column array and on data array? > > > Only then I will assign it to the DataGrid > > > > > > Thanks for your time, realy > > > > > > --- In [email protected], "bhaq1972" <mbhaque@> wrote: > > > > > > > > > Can I set it dynamically without the need to set > > > > > columnName:columnValue statically? > > > > > > > > Sorry i'm a bit unclear. Another suggestion ... > > > > > > > > You want to create DatgridColumns based on whats in the > > > DataProvider. > > > > > > > > If your dataProvider Array is something like the following > > > > > > > > var myArray:Array = > > > > [{parent:'root1',col1:100,date:myObject[0],col2:33}, > > > > {parent:'root1',col1:5,date:myObject[1],col2:21}, > > > > {parent:'root2',col1:11,date:myObject[2],col2:5}]; > > > > > > > > then why not do something like this > > > > var row:Object = myArray[0]; > > > > > > > > for(var obj1:Object in row) > > > > { > > > > var col:DataGridColumn = new DataGridColumn(); > > > > col.dataField = obj1; > > > > } > > > > > > > > > > > > > > > > --- In [email protected], "yossi.baram" <yossi.baram@> > > > > wrote: > > > > > > > > > > Thanks man, > > > > > > > > > > I am doing something like you mensioned for columns, > > > > > my problem is the dataprovider itself that I set to the > > DataGrid. > > > > > Can I set it dynamically without the need to set > > > > > columnName:columnValue statically? > > > > > To be clear :) > > > > > My current dataprovider is set accornigly in an Array: > > > > > {parent:'root1',col1:100,date:myObject[0],col2:33}, > > > > > {parent:'root1',col1:5,date:myObject[1],col2:21}, > > > > > {parent:'root2',col1:11,date:myObject[2],col2:5} > > > > > > > > > > > > > > > I need to build it dymanically because the column names(the > ones > > > > > before the semicolon) can be different and as I said I get > them > > > and > > > > > the values(objects) from Arrays. > > > > > > > > > > Thanks again > > > > > > > > > > Jo > > > > > > > > > > > > > > > > > > > > --- In [email protected], "bhaq1972" <mbhaque@> > wrote: > > > > > > > > > > > > If you want to add columns dynamically, you need something > > like > > > > this > > > > > > > > > > > > var colNum:int=5 > > > > > > for(var i:int=0;i<colNum;i++) > > > > > > { > > > > > > var col:DataGridColumn = new DataGridColumn(); > > > > > > col.dataField = "some value1"; > > > > > > col.headerText = "some value2"; > > > > > > > > > > > > myDataGrid.columns.push(col); > > > > > > } > > > > > > you'd then generate your dataProvider (could be an > > > > ArrayCollection, > > > > > > Array, XML, whatever) > > > > > > myDataGrid.dataProvider = myDataProvider; > > > > > > > > > > > > hope this helps > > > > > > bh > > > > > > > > > > > > > > > > > > --- In [email protected], "yossi.baram" > > <yossi.baram@> > > > > > > wrote: > > > > > > > > > > > > > > Hi helper, > > > > > > > I have a DataGrid and I need to feed its DataProvider > > > > dynamically, > > > > > > > I have difficulties doing that. > > > > > > > > > > > > > > my columns: > > > > > > > var columns:ArrayCollection = new ArrayCollection(); > > > > > > > columns.addItem("parent"); > > > > > > > > > > columns.addItem("cell1"); > > > > > > > columns.addItem("date"); > > > > > > > columns.addItem("cell2"); > > > > > > > > > > > > > > > > > > > > > and differnt data for each row. > > > > > > > > > > > > > > How do I set all this columns and data (that need to be > feed > > > > into > > > > > > > ArrayCollections as well) into a main ArrayCollection > > > > > > > that will have the following structure? > > > > > > > > > > > > > > parent:'root1',col1:100,date:myObject[0],col2:33 > > > > > > > parent:'root1',col1:5,date:myObject[1],col2:21 > > > > > > > parent:'root2',col1:11,date:myObject[2],col2:5 > > > > > > > > > > > > > > > > > > > > > Here the column name and values are static, I need all to > be > > > > > > dynamic, > > > > > > > to be sent to the DataGrid as the DataProvider, > > > > > > > > > > > > > > Thanks > > > > > > > > > > > > > > Jo > > > > > > > > > > > > > > > > > > > > > > > > > > > >

