Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4031
  • Last Modified:

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

1 Solution
I think you need a total field in dataGrid.

This should help i feel.

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.

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now