Hi all,

I am using Advanced Data grid for the first time. It is editable in nature. I 
am unable to display the 'SUM' of the grouped collections corrected after i 
edit the Text Inputs in the grid.

This is my code:

MainFile.mxml:

<?xml version="1.0" encoding="utf-8" ?> 
 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; layout="vertical" 
initialize="init()">
 
 <mx:Script>
        <![CDATA[
                import mx.collections.ArrayCollection;
                import mx.events.AdvancedDataGridEvent;
                import mx.events.DataGridEvent;
                import mx.events.ListEvent;
                import mx.controls.List;
                import mx.events.ItemClickEvent;
                import mx.collections.IViewCursor;
                import mx.controls.Alert;
                import mx.controls.TextInput;
                
                [Bindable]public var num1:Number;
                [Bindable]public var num2:Number;
[Bindable]public var num3:Number;
[Bindable]public var num4:Number;
[Bindable]public var num5:Number;
[Bindable]public var num6:Number;

                public var newVal:String;
                [Bindable]
                public var myArrayCollection:ArrayCollection;
                
                private function func(itr:IViewCursor,field:String, 
str:String=null):Object
                        {
                                myArrayCollection.refresh();
                        var sum:Number=0;
                        while(!itr.afterLast)
                        {
                        //trace(itr.current)
                        var value:Number = Number(itr.current.Profit);
                        //Alert.show(Number(itr.current.Profit)+"");
                        if(!isNaN(value))
                        {
                        sum+= value;
                        //Alert.show(sum+"");
                        }
                        itr.moveNext()
                        }
                        //Alert.show(sum+"sum");
                        return sum;
                        }
                        
                        public function init():void {
                                myArrayCollection = new ArrayCollection(arr);
                        }
                
                 private function getCellInfo(event:AdvancedDataGridEvent):void 
{
                
               myArrayCollection.refresh();
               summaryField.summaryFunction=func;// i m trying to call the 
function to update the sum(total) of the grouped collection after user edits it.
          }
          

        ]]>
 </mx:Script>
 <mx:Array id="arr">
  <mx:Object From="a1" Subject="a" Date="12/08/06" Profit="{num1}"/> 
  <mx:Object From="b1" Subject="b" Date="12/08/06" Profit="{num2}"/ 
  <mx:Object From="c1" Subject="c" Date="12/08/06" Profit="{num3}"/>
  <mx:Object From="d1" Subject="d" Date="12/08/06" Profit="{num4}"/> 
 <mx:Object From="a1" Subject="e" Date="12/07/06"Profit="{num5}"/> 
  <mx:Object From="f1" Subject="f" Date="12/07/06" ="{num6}"/>
  </mx:Array>
 <mx:AdvancedDataGrid id="adg" displayItemsExpanded="true" 
creationComplete="gc.refresh();" 
        height="300" editable="true" itemEditEnd="getCellInfo(event);">
         <mx:dataProvider>
                 <mx:GroupingCollection id="gc" source="{myArrayCollection}">
                         <mx:Grouping>
                                 <mx:GroupingField name="From">
                                         <mx:SummaryRow summaryPlacement="last">
                                                 <mx:fields>
                                                  <mx:SummaryField 
dataField="Profit" label="summary" summaryFunction="func" id="summaryField"/> 
                                                 </mx:fields>
                                          </mx:SummaryRow>
                                  </mx:GroupingField>
                          </mx:Grouping>
                  </mx:GroupingCollection>
          </mx:dataProvider>
 <mx:columns>
  <mx:AdvancedDataGridColumn id="col1" dataField="From"/> 
  <mx:AdvancedDataGridColumn dataField="Subject" /> 
  <mx:AdvancedDataGridColumn dataField="Date" /> 
  <mx:AdvancedDataGridColumn dataField="CC" /> 
  <mx:AdvancedDataGridColumn dataField="Profit"/> 
  </mx:columns>
 <mx:rendererProviders>
  <mx:AdvancedDataGridRendererProvider column="{col1}" columnSpan="0" depth="2" 
dataField="summary" renderer="SummaryRenderer" /> 
  </mx:rendererProviders>
  </mx:AdvancedDataGrid>
  </mx:Application>

SummaryRenderer.mxml:

<?xml version="1.0" encoding="utf-8" ?> 
<mx:Label xmlns:mx="http://www.adobe.com/2006/mxml"; textAlign="center">
<mx:Script>
<![CDATA[
        import mx.controls.Alert; 
                        import mx.collections.GroupingCollection;
                        import mx.collections.IHierarchicalCollectionView;
                        import mx.controls.AdvancedDataGrid;
                        
                        override public function set data(value:Object):void
                        {
                                super.data = value;
                                
                                var userName:String = "";
                                
                                if (this.listData)
                                {
                                        //  get the owner AdvnacedDataGrid
                                        var listOwner:AdvancedDataGrid = 
AdvancedDataGrid(this.listData.owner);
                                        
                                        // get the parent of this item
                                        var parent:Object = 
IHierarchicalCollectionView(listOwner.dataProvider).getParentItem(value);
                                        
                                        // the default label is "GroupLabel"
                                        var groupLabel:String = "GroupLabel";
                                        
                                        // get the GroupingCollection
                                        var gc:GroupingCollection = 
IHierarchicalCollectionView(listOwner.dataProvider).source as 
GroupingCollection;
                                        
                                        // get the groupLabel specified in 
GroupingCollection
                                        if (gc && gc.grouping)
                                                groupLabel = gc.grouping.label;
                                        
                                        // get the value for the groupLabel 
property
                                        if (parent && 
parent.hasOwnProperty(groupLabel))
                                                userName = parent[groupLabel];
                                }
                                
                                // set the html text
                                this.htmlText = "<u>Total Profit for User <font 
color='#FF0000'>" + userName + "</font>: " + value["summary"] + "</u>";
                        }
                

  ]]> 
  </mx:Script>
  </mx:Label>

Please HELP me.........

Thanx in advance,
sam

Reply via email to