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

Posted on 2009-04-21
Last Modified: 2013-11-11
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

Question by:aduvall
    LVL 11

    Accepted Solution

    I think you need a total field in dataGrid.

    This should help i feel.

    LVL 12

    Expert Comment


    Author Comment

    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

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
    This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
    In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
    The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now