jeudi 12 janvier 2017

Display total sum of rows values in arraycollection - Adobe Flex

I want to display total sum of rows values in an arraycollection. For example:

Definition     Value
Product 1      20.00
Product 2      50.00
Product 3      30.00

Total          100.00

I have this code:

    <mx:DataGrid id="srcgrid">
            <mx:DataGridColumn dataField="Definition"/>
            <mx:DataGridColumn dataField="Value"/>

        <s:FormItem label="Total">
            <s:Label text="{total()}"/>

And the script:

public function total():String {
    var i:Number = 0;
    for each(var obj:Object in ArrayCollection(DataGrid(srcgrid).dataProvider)){
        i = i + obj.Valor;

    return i.toString();

Any idea?

Thanks in advance

Aucun commentaire:

Enregistrer un commentaire