I guess using a labelFunction would be easier approach, also it would be more dynamic approach. Say if the data is changing regularly you do not have to run the entire loop again for computation.
-Aasim On Sep 10, 12:50 pm, "Venkat Viswanathan" <[EMAIL PROTECTED]> wrote: > Hi, > > See this code. This is a working sample of how you can use calculations: > > <?xml version="1.0" encoding="utf-8"?> > <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" > creationComplete="init()"> > <mx:Script> > <![CDATA[ > import mx.collections.ArrayCollection; > [Bindable] private var marksCollection:ArrayCollection = new > ArrayCollection(); > > private function init():void{ > > marksCollection.addItem({"Maths":84,"Science":90,"English":75}); > > marksCollection.addItem({"Maths":82,"Science":89,"English":71}); > > marksCollection.addItem({"Maths":78,"Science":80,"English":65}); > > marksCollection.addItem({"Maths":65,"Science":60,"English":52}); > > marksCollection.addItem({"Maths":98,"Science":99,"English":91}); > > marksCollection.addItem({"Maths":90,"Science":92,"English":87}); > } > > private function calc():void{ > for each (var item:Object in marksCollection){ > var total:Number = item.Maths + item.Science + > item.English; > var perc:Number = Math.round((total/300)*100); > item.Total = total; > item.Percentage = perc + "%"; > } > marksCollection.refresh(); > } > ]]> > </mx:Script> > <mx:Button label="Calculate" click="calc()"/> > <mx:DataGrid width="100%" height="100%" > dataProvider="{marksCollection}"> > <mx:columns> > <mx:DataGridColumn dataField="Maths" headerText="Maths"/> > <mx:DataGridColumn dataField="Science" headerText="Science"/> > <mx:DataGridColumn dataField="English" headerText="English"/> > <mx:DataGridColumn dataField="Total" headerText="Total"/> > <mx:DataGridColumn dataField="Percentage" > headerText="Percentage"/> > </mx:columns> > </mx:DataGrid> > > </mx:Application> > > Regards, > Venkatwww.venkatv.com > > On Wed, Sep 10, 2008 at 12:58 PM, jeroen <[EMAIL PROTECTED]> wrote: > > > Thanks for the reply....appreciate it > > > Do you a sample array collection for loop....? > > > On Sep 10, 9:18 am, "Venkat Viswanathan" <[EMAIL PROTECTED]> > > wrote: > > > Hi, > > > > The best way to do this is to loop through the arrayCollection and > > perform > > > the action required for each of the items in every row. So probably you > > can > > > run a "for each" loop and then do the calculation inside the loop. And > > after > > > completing the loop, do arrayCollection.refresh(). > > > > Let me know if this wont work out in your case. > > > > Regards, > > > Venkat > > > > On Wed, Sep 10, 2008 at 12:38 PM, jeroen <[EMAIL PROTECTED]> wrote: > > > > > On Sep 10, 8:45 am, jeroen <[EMAIL PROTECTED]> wrote: > > > > > Hi Guys and Girls > > > > > > Maybe someone can help > > > > > > I have a advanced datagrid lets say with one row with 4 columns, > > > > > column 3 data is determined by column 1 data mulplied by 30 for > > > > > example....now is easy to do with one row but I have 40 odd rows of > > > > > data, is there a easy way to loop through the data and calculate this > > > > > values on the fly or should each cell be calculated seperatly > > > > > > Thanks > > > > > Here is a sample with calculations... > > > > >http://spreadsheets.google.com/ccc?key=pFk_smnTF1XI7Z5URAX3gAw&hl=en --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

