2 Replies Latest reply on Nov 12, 2010 9:46 AM by jfb00

    Advanced DataGrid SUM

    jfb00 Level 3

      Hi All,

      I'm trying to SUM columns and display the total column at the end of each group using:


      <mx:GroupingCollection id="groupedData" source="{acData}" >


                                      <mx:GroupingField name="SERIES" >


                                              <mx:SummaryRow summaryPlacement="last group">


                                                      <mx:SummaryField dataField="Field01" operation="SUM" />

                                                      <mx:SummaryField dataField="Field03" operation="SUM" />








      with summaryPlacement="group"  shows at the top.

      with summaryPlacement="last group" It shows the top and the last.

      with summaryPlacement="last" Doesn't show anything. How can I fix this? It's a way to change this total ROW color as RED and display the word TOTAL.

      Thanks !



        • 1. Re: Advanced DataGrid SUM
          VRPDeveloper Level 3

          Question is not clear... specify complete code and elaborate it...

          • 2. Re: Advanced DataGrid SUM
            jfb00 Level 3

            I got the solution:


            <?xml version="1.0"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
                        import mx.collections.ArrayCollection;
                        import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
                        import mx.collections.IViewCursor;    
                        import mx.collections.SummaryObject;
                        private var dpFlat:ArrayCollection = new ArrayCollection([
                            {Territory:"Arizona", Territory_Rep:"Barbara Jennings", Actual:38865, Estimate:40000},
                            {Territory:"Arizona", Territory_Rep:"Dana Binn", Actual:29885, Estimate:30000}, 
                            {Territory:"Central California", Territory_Rep:"Joe Smith", Actual:29134, Estimate:30000}, 
                            {Territory:"Nevada", Territory_Rep:"Bethany Pittman", Actual:52888, Estimate:45000}, 
                            {Territory:"Northern California", Territory_Rep:"Lauren Ipsum", Actual:38805, Estimate:40000},
                            {Territory:"Northern California", Territory_Rep:"T.R. Smith", Actual:55498, Estimate:40000}, 
                            {Territory:"Southern California", Territory_Rep:"Alice Treu", Actual:44985, Estimate:45000},
                            {Territory:"Southern California", Territory_Rep:"Jane Grove", Actual:44913, Estimate:45000}
                        // Callback function to create
                        // the SummaryObject used to hold the summary data.
                        private function summObjFunc():SummaryObject {
                            // Define the object containing the summary data.
                            var obj:SummaryObject = new SummaryObject();
                            // Add a field containing a value for the Territory_Rep column.
                            obj.Territory_Rep = "Total:";
                            return obj;
                        // Callback function to summarizes
                        // every other row of the Actual sales revenue for the territory.
                        private function summFunc(cursor:IViewCursor, dataField:String, operation:String):Number {
                            var sumRows:Number = 0;
                            while (!cursor.afterLast)
                                if (dataField == "Actual")
                                    sumRows += Number(cursor.current["Actual"]);
                            return sumRows;
                        private function formatSummary(data:Object, col:AdvancedDataGridColumn):Object{
                            if ( data["Territory_Rep"] == "Total:") 
                                return { color:0xFF0000, fontWeight:"bold"}
                            return {};
                <mx:AdvancedDataGrid id="myADG" editable="true" width="100%" height="100%"
                                     initialize="gc.refresh();" styleFunction="formatSummary">       
                        <mx:GroupingCollection id="gc" source="{dpFlat}">
                                <mx:GroupingField name="Territory">
                                        <mx:SummaryRow summaryObjectFunction="summObjFunc" summaryPlacement="last">
                                                <mx:SummaryField dataField="Actual" summaryFunction="summFunc"/>
                        <mx:AdvancedDataGridColumn dataField="Territory" editable="false"/>
                        <mx:AdvancedDataGridColumn dataField="Territory_Rep" headerText="Territory Rep" editable="false"/>
                        <mx:AdvancedDataGridColumn dataField="Actual" editable="true"/>
                        <mx:AdvancedDataGridColumn dataField="Estimate" editable="true"/>