aduvall
asked on
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.
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);
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ah see this: http://blogs.adobe.com/aharui/2007/04/datagrid_footers.html
ASKER
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.