Thanks Ben,
  I already use similar code with a labelFunction to do sub-totals
within the grid and it works very well.  However, that code will only
do calculations on a single row and not on an entire column.  The code
I wrote for totaling a column works as well but not on a new form
where the model has no data yet.  I would also like to run the code
after the data model is populated (run the function last after all
other code has run).  How can I iterate through a dataGrid when it
holds the data and my model or the array doesn't have any data yet?



--- In flexcoders@yahoogroups.com, "bsdensmore" <[EMAIL PROTECTED]> wrote:
>
> a labelfunction will do the calculations as you tab through the fields
> or as change rows on the grid.
> 
> I use this to do some calculations and it works great.
> 
> private function
calcAdjAmount(item:Object,column:DataGridColumn):String {
>                
>                var adjustedAmt:Number;
>                var emptyField:String = "";
>                
>  if (item['Num_Cases_Claimed'] != null) {
>     adjustedAmt = item['Num_Cases_Claimed'] *
> Number(removeFormatting.format(item['Net_Promo_Amt']));
>                        
>                        return 
> basicCurrencyFormat.format(adjustedAmt.toString());
>                        
>                }
>                else {
>                       return emptyField;
>                }
>           }
> Ben
> 
> --- In flexcoders@yahoogroups.com, "nall_daniel" <daniel.nall.ctr@>
> wrote:
> >
> > No one has an answer to this? Or suggestions?
> > 
> > --- In flexcoders@yahoogroups.com, "nall_daniel" <daniel.nall.ctr@>
> > wrote:
> > >
> > > I am using the CF/Flex Application Wizard to generate a basic form
> > > based application.  I have a Master datagrid that list all the
> > > purchase requests a user has submitted and a Detail form for
editing a
> > > request or submitting a new request.  The detail form has a datagrid
> > > as a subform. I pass the mx:model the wizard created of the
subform's
> > > data to this function:
> > > 
> > > [Bindable]
> > > public var purchaseTotal:Number;
> > > 
> > > private function grandTotal(myArray:Array):void
> > > {
> > >    purchaseTotal = 0;
> > >    var length:int = myArray.length;
> > >    for (var i:int = 0; i < length; i++)
> > >    {
> > >       purchaseTotal += Number(myArray[i].Quantity *
> myArray[i].UnitCost)
> > >    }
> > > }
> > > 
> > > I assign purchaseTotal variable to the text property of a label and
> > > run the function on the subform's datagrid.itemFocusOut event.  Now
> > > when a user is editing a purchase request, the grand total updates
> > > when the user changes either the Quantity or the UnitCost. 
Couple of
> > > problems with what I'm doing:
> > > 
> > > 1. No grand total in the label until the user tabs or clicks through
> > > the datagrid subform.  How can I get my function to run after the
> > > mx:model is created and populated with data?
> > > 
> > > 2.  New requests never show a grand total.  Where's the model's
data? 
> > > 
> > > My apologies for being so long winded but I wanted to make sure
what I
> > > was doing is clear.
> > > 
> > > Cheers,
> > > 
> > > Dan
> > >
> >
>


Reply via email to