Hi Akhil, I saw your code. You will have to convert your data to object type which is currently as a string.
Why are your getting the data as a string from backend why not as a list of objects. That'll make your life a lot easier. -Ravi On Mar 23, 11:12 am, Akhil Agrawal <[email protected]> wrote: > this the complete sample code for the work i want to do > i have data as string from that i have to identify column and then > display corresponding data in a grid > > <?xml version="1.0"?> > <!-- dpcontrols/DataGridPassData.mxml --> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" > initialize="initData()"> > <mx:Script> > <![CDATA[ > import mx.collections.*; > import mx.controls.Alert; > import mx.collections.ArrayCollection; > import mx.controls.DataGrid; > import mx.controls.dataGridClasses.DataGridColumn; > > //data to be display in grid > private var str:String="{'Artist Name':'Pavement', 'Album':'Slanted > and Enchanted', 'Price':'11.99'}*{'Artist Name':'Pavement', > 'Album':'Brighten the Corners', 'Price':'11.99'}"; > > // Alert.show(str,"string"); > private var DGArray:Array =str.split("*"); > // Alert.show(DGArray[0].toString(),"array"); > [Bindable] > public var initDG:ArrayCollection; > //Initialize initDG ArrayCollection variable from the Array. > //You can use this technique to convert an HTTPService, > //WebService, or RemoteObject result to ArrayCollection. > public function initData():void { > initDG=new ArrayCollection(DGArray); > var dcolumn:DataGridColumn=new DataGridColumn(); > Alert.show(DGArray[0].toString(),"dg"); > var row:Array=DGArray[0].toString().split(","); > Alert.show(row.length.toString()+row[0].toString(),"row"); > var colName:String; > var gridcolumns:Array=new Array(); > for(var i:int=0;i<row.length;i++) > { > > colName=row[i].toString().substr(1,row[i].toString().indexOf > (":")-1); > > colName=colName.substring(1,colName.length-1); > Alert.show(colName,"col name"); > dcolumn=new DataGridColumn(); > dcolumn.dataField=colName; > // > Alert.show(dcolumn.dataField.toString(),"field"); > dcolumn.resizable=true; > dcolumn.minWidth=200; > gridcolumns.push(dcolumn); > > } > myGrid.columns=gridcolumns; > myGrid.dataProvider=initDG; > } > ]]> > </mx:Script> > > <mx:DataGrid id="myGrid" width="350" height="200"> > > </mx:DataGrid> > </mx:Application> > > for this i am trying to parse the string to idengtify column Now plz > help me to do this > thank > > Regards > Akhil Agrawal > > On Mar 22, 6:06 pm, Ravi Mishra <[email protected]> wrote: > > > send me the complete file....may be i can do something with that. > > > -Ravi > > > On Mar 22, 5:38 pm, Akhil Agrawal <[email protected]> wrote: > > > > @ravi > > > it is not working . columns is an array that provide field name in > > > arraycollection for providing data to grid > > > > On Mar 21, 11:17 am, Ravi Mishra <[email protected]> wrote: > > > > > Dont declare the dcolumn as a global variable.....declare it locally > > > > in the function where you are running the for loop and then push this > > > > dcolumn to gridcolumns array and then finally assign this array to the > > > > columns property of datagrid. > > > > > BTW what is columns in the for loop? > > > > > -Ravi > > > > On Mar 20, 7:14 pm, Akhil Agrawal <[email protected]> wrote: > > > > > > [Bindable] > > > > > private var queryResult:ArrayCollection=new > > > > > ArrayCollection(); > > > > > [Bindable] > > > > > private var gridcolumns:Array=new Array(); > > > > > private var grid:DataGrid=new DataGrid(); > > > > > [Bindable] > > > > > private var dcolumn:DataGridColumn=new > > > > > DataGridColumn(); > > > > > > for(var i:int=0;i<columns.length;i++) > > > > > { > > > > > > // Alert.show(colName,"col > > > > > name"); > > > > > dcolumn=new > > > > > DataGridColumn(colName.toUpperCase()); //colname is > > > > > a string which is same as field in array collection > > > > > dcolumn.dataField=colName; > > > > > dcolumn.resizable=true; > > > > > dcolumn.minWidth=200; > > > > > gridcolumns.push(dcolumn); > > > > > > } > > > > > this.grid.columns=gridcolumns; > > > > > var temp:ArrayCollection=new > > > > > ArrayCollection(rows); // rows is an > > > > > array of rows as shown in previous post > > > > > queryResult=temp; > > > > > this.grid.dataProvider=queryResult; > > > > > > this is the code how i m doing now plz help me in this regard > > > > > > On Mar 20, 6:23 pm, Ravi Mishra <[email protected]> wrote: > > > > > > > Can you pls send your complete code.....as I am not able to > > > > > > understand > > > > > > what is gridColumns? > > > > > > > GridColumns should be an Array and you should loop through each > > > > > > property of a row like this > > > > > > > for each(var str:string in rowObject){ > > > > > > // your code of creating and pushing the columns in GridColumns > > > > > > array > > > > > > > } > > > > > > > then assign GridColumns to grid.columns > > > > > > > HTH, > > > > > > > -Ravi > > > > > > > On Mar 20, 5:42 pm, Akhil Agrawal <[email protected]> wrote: > > > > > > > > Hi all, > > > > > > > I have many rows in a arraycollection in tha form > > > > > > > {'Category ID':'null', 'Software Feature ID':'null', 'Event > > > > > > > Date':'Tue > > > > > > > Mar 17 11:40:13 IST 2009', 'Event Type ID':'2102006'} > > > > > > > > where category id and other are columns and creating > > > > > > > datagridcolumn > > > > > > > like this > > > > > > > > dcolumn=new DataGridColumn(colName.toUpperCase()); > > > > > > > dcolumn.dataField=colName; > > > > > > > > grid.columns=this.gridcolumns; // grid is an object of datagrid > > > > > > > type > > > > > > > > var temp:ArrayCollection=new ArrayCollection(rows); > > > > > > > > this.grid.dataProvider=temp; > > > > > > > > it is not displaying the data properply and displaying complete > > > > > > > row as > > > > > > > written above in each column > > > > > > > how to fix it > > > > > > > > thank you > > > > > > > > regards > > > > > > akhil agrawal --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Flex India Community" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/flex_india?hl=en -~----------~----~----~----~------~----~------~--~---

