How do I sum a datagrid column after a lable function?

I need a grand total of the Avg. Cost field.  Using the code below I have an Avg. Cost per item using a label function.  SInce there is no true data coming fron the arraycollection I cannot get a grand total of the avgcost column(that I know of).
My attempt at trying to have grand total function and have it return to a text field is below.  So far I have failed at my attempts. As You will see I have tried to recalc using a function similar to the label function.

//This returns the avg.cost for each item.
 private function avgCost(item : Object, column : DataGridColumn ) : String { 
            	var total:Number;
            	var a = (item.slen * item.swid/144) * (item.ordqty)
            	var b = item.tcost;
            	total = b/a*1000;
            	
            	return currencyFormatter.format(total);
            }
 
// try to sum the avgcost column.
  public function totalavgCost():void{
var total:Number = 0
var totala:Number = 0
var totalb:Number = 0
var totalc:Number = 0
var totald:Number = 0
for(var i:int = 0; i < ac.length; i++)
{
totalb += ac.getItemAt(i).slen * pos.getItemAt(i).swid/144;
totala += ac.getItemAt(i).ordqty;
totalc += ac.getItemAt(i).tcost;
totald = (totalc*1000)/(totalb*totala);
total = totald/(ac.length);
tottxta.text = numberFormatter.format(total);
  }         
  }

Open in new window

aduvallAsked:
Who is Participating?
 
vindys80Connect With a Mentor Commented:
Hi,
I think you need a total field in dataGrid.
http://flex-apollo.blogspot.com/2007/05/adding-total-row-at-end-of-datagrid.html

This should help i feel.

Thanks,
Vindys
0
 
lexxwernCommented:
0
 
aduvallAuthor Commented:
This does not work for me.  That int n is null .  I suppose this is because I am loading the arraycollection from xml.  Also the column that has avg. cost is a calulated column so it is not in the arraycollection.  It is only in the DG.  I need a total avg. of the avgcost column which as I said is calculated and not in the arraycollection.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.