0 Replies Latest reply on May 23, 2010 11:06 PM by snkd

    How to calculate Datagrid column total/Manipulate DataGrid

    snkd Level 1

      click here to visit original example

       

       


      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="init();" layout="horizontal" width="800" height="300" backgroundGradientColors="[#FFFFFF, #acd8f7]" >
             

          <!--width="600" height="300"-->
          <mx:VBox horizontalAlign="left" label="my test component" width="50%">

           <mx:HBox horizontalAlign="right">
                  <mx:DataGrid id="dgDebitNotes" editable="true" showEffect="out" dataProvider="{listCollectionFCurrencies}">
                  </mx:DataGrid>
              </mx:HBox>
           <mx:HBox horizontalAlign="right">       
                  <mx:ComboBox id="cmbColomn" dataProvider="{colomns}"></mx:ComboBox>
                  <mx:Button  label="Calculate" click="countColomn();"/>
                  <mx:Label text="Total" id="txtTotal"/>
                  <mx:TextInput id="txtCount"/>
          </mx:HBox>       
          </mx:VBox>

         

         
          <mx:Style source="css/defaults.css" />
          <mx:XML id="reed" source="assets/reed2.xml" />
                 
          <mx:Script>
          <![CDATA[
              import mx.rpc.xml.SimpleXMLDecoder;
              import mx.utils.ArrayUtil;
              import com.dspl.component.PopUpGrid;
              import mx.utils.ObjectUtil;
              import mx.controls.Alert;
              import mx.collections.ArrayCollection;
              import mx.rpc.events.FaultEvent;
              import mx.rpc.events.ResultEvent;
         
                  [Bindable]
                  private var listCollectionFCurrencies:ArrayCollection;
                  [Bindable]
                  public var colomns:ArrayCollection = new ArrayCollection(
                      [ {label:"id", data:"id"},
                        {label:"units", data:"units"},
                        {label:"points", data:"points"} ]);
                        
                  private function init():void
                  {
                          var xml:XMLDocument = new XMLDocument(reed);
                          var decoder:SimpleXMLDecoder = new SimpleXMLDecoder();
                          var data:Object = decoder.decodeXML( xml );
                          var array:Array = ArrayUtil.toArray(data.coursers.course);
                          listCollectionFCurrencies=new ArrayCollection( array );
                  }
                 
                  private function countColomn():void
                  {           
                          var getData:ArrayCollection=dgDebitNotes.dataProvider as ArrayCollection;
                          var total:Number= new Number(0.0000);
                          for (var i:int=0; i < getData.length; i++)
                          {
                              //total = total + getData[i].id;//id = mean colomn name
                              total = total + getData[i][cmbColomn.selectedLabel];
                          }       
                          txtCount.text=new String(total);           
                  }


                 
          ]]>
      </mx:Script>

          <mx:Zoom id="out"
                   duration="1000"
                   zoomHeightTo="2"
                   zoomWidthTo="2"/>
                  
      </mx:Application>

      you can find many flex DataGrid manipulations from following link

      http://sankadil.blogspot.com/search/label/Flex%20%3A%20How%20to%20calculate%20Datagrid%20c olumn%20total

       

      http://www.box.net/shared/vjxbdrnilg