3 Replies Latest reply on Aug 27, 2012 4:43 AM by jfb00

    ADG grouping question

    jfb00 Level 3

      Hi All,

      I want to display data like the next image in a ADG using grouping.

      newData.png

      My dynamic function for grouping is:

       

      private function createGrouping():void{

                      //SUMMARY Fields and Rows

                      var sumAC:ArrayCollection=new ArrayCollection();

                      var i:Number;

                      var nSumm:SummaryField2;

                     

                      for (i=1; i <= yearsLength; i++){

                          nSumm = new SummaryField2("FIELD_" + i);

                          nSumm.dataField = "YEAR_" + i;

                          nSumm.summaryOperation = "SUM";

                          sumAC.addItem(nSumm);

                      }

                      sumAC.refresh();

                     

                      var rSR:SummaryRow = new SummaryRow();

                      rSR.summaryPlacement = "group";

                      rSR.fields = sumAC.toArray();

                     

                      var gc:GroupingCollection2 = null;

                      gc = new GroupingCollection2();

                      gc.source = acSummary;

                     

                      var nGroup:Grouping = new Grouping();

                      var fields:Array = new Array();

                      var nField:GroupingField = new GroupingField();

                      nField.name = "SUMMARY_GROUP";

                      //nField.summaries = [rSR];

                      fields.push(nField);

                     

                      var nField2:GroupingField=new GroupingField();

                      nField2.name = "SUMMARY_PRODUCT_NAME";

                      nField2.summaries = [rSR];

                      fields.push(nField2);

                     

                      nGroup.fields = fields;

                     

                      gc.grouping = nGroup;

                     

                      summary_dg.dataProvider = gc;

                  }

       

      My issue is that products show two lines for the ones that doesn't have subItems (From my data example is Product 1,3, and 4 from group A).

      I am building manually rSR, that is my data ArrayCollection.

      For those products that doesn't have items i am not setting SUMMARY_PRODUCT_NAME field.

      How can I fix this issue?

      Any ideas?

      Thanks

        • 1. Re: ADG grouping question
          jfb00 Level 3

          Bump 1

           

          Forget about the dynamic function, can I display the data as my picture example in advanceddatagrid?

          Thanks

          • 2. Re: ADG grouping question
            jfb00 Level 3

            Bump2...

            I created an example to show my issue. It should be a way not to show the double line of a product when doesn't have items.

            Anyone?

            Thanks

             

            <?xml version="1.0"?>

            <!-- dpcontrols/adg/SummaryGroupADGDefProp.mxml -->

            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init()">

               

                <mx:Script>

                    <![CDATA[

                        import mx.collections.ArrayCollection;

                        import mx.collections.SummaryField2;

                        import mx.collections.SummaryRow;

                        import mx.collections.GroupingCollection2;

                        import mx.collections.GroupingField;

                        import mx.collections.ArrayCollection;

                        import mx.collections.Grouping;

                       

                        [Bindable]

                       

                        private var dpFlat:ArrayCollection = new ArrayCollection([

                            {SUMMARY_GROUP:"TOTAL GROUP A", SUMMARY_PRODUCT:"Product 1", PRODUCT:"Product 1", Value:30},

                            {SUMMARY_GROUP:"TOTAL GROUP A", SUMMARY_PRODUCT:"Product 2 - Total", PRODUCT:"Item 1", Value:10},

                            {SUMMARY_GROUP:"TOTAL GROUP A", SUMMARY_PRODUCT:"Product 2 - Total", PRODUCT:"Item 2", Value:10},

                            {SUMMARY_GROUP:"TOTAL GROUP A", SUMMARY_PRODUCT:"Product 2 - Total", PRODUCT:"Item 3", Value:25},

                            {SUMMARY_GROUP:"TOTAL GROUP A", SUMMARY_PRODUCT:"Product 2 - Total", PRODUCT:"Item 4", Value:25},

                            {SUMMARY_GROUP:"TOTAL GROUP A", SUMMARY_PRODUCT:"Product 3", PRODUCT:"Product 3", Value:20},

                            {SUMMARY_GROUP:"TOTAL GROUP A", SUMMARY_PRODUCT:"Product 4", PRODUCT:"Product 4", Value:20},

                            {SUMMARY_GROUP:"TOTAL GROUP B", SUMMARY_PRODUCT:"Product 1 - Total", PRODUCT:"Item 1", Value:5},

                            {SUMMARY_GROUP:"TOTAL GROUP B", SUMMARY_PRODUCT:"Product 1 - Total", PRODUCT:"Item 2", Value:5},

                            {SUMMARY_GROUP:"TOTAL GROUP B", SUMMARY_PRODUCT:"Product 1 - Total", PRODUCT:"Item 3", Value:6},

                            {SUMMARY_GROUP:"TOTAL GROUP B", SUMMARY_PRODUCT:"Product 1 - Total", PRODUCT:"Item 4", Value:6},

                            {SUMMARY_GROUP:"TOTAL GROUP B", SUMMARY_PRODUCT:"Product 2", PRODUCT:"Product 2", Value:50},

                            {SUMMARY_GROUP:"TOTAL GROUP B", SUMMARY_PRODUCT:"Product 3", PRODUCT:"Product 3", Value:40},

                            {SUMMARY_GROUP:"TOTAL GROUP B", SUMMARY_PRODUCT:"Product 4", PRODUCT:"Product 4", Value:60}

                           

                        ]);

             

                       

                        private function init():void{

                            createGrouping();

                        }

                       

                        private function createGrouping():void{

                            gc.refresh(false);

                        }

                    ]]>

                </mx:Script>

               

                <mx:AdvancedDataGrid id="myADG"

                                     width="100%" height="100%"

                                     displayItemsExpanded="true"

                                     folderClosedIcon="{null}" folderOpenIcon="{null}" defaultLeafIcon="{null}" displayDisclosureIcon="false"

                                     editable="false" headerWordWrap="true" textAlign="left" horizontalScrollPolicy="auto"

                                     sortableColumns="false" sortExpertMode="true" resizableColumns="true"

                                    >       

                    <mx:dataProvider>

                        <mx:GroupingCollection2 id="gc" source="{dpFlat}">

                            <mx:Grouping>

                                <mx:GroupingField name="SUMMARY_GROUP">

                                    <mx:SummaryRow summaryPlacement="group">

                                        <mx:SummaryField2 summaryOperation="SUM" dataField="Value"/>

                                    </mx:SummaryRow>

                                </mx:GroupingField>

                                <mx:GroupingField name="SUMMARY_PRODUCT">

                                    <mx:SummaryRow summaryPlacement="group">

                                        <mx:SummaryField2 summaryOperation="SUM" dataField="Value" />

                                    </mx:SummaryRow>

                                </mx:GroupingField>

                            </mx:Grouping>

                        </mx:GroupingCollection2>

                    </mx:dataProvider>       

                   

                    <mx:columns>

                        <mx:AdvancedDataGridColumn dataField="PRODUCT"/>

                        <mx:AdvancedDataGridColumn dataField="Value"  headerText="Value"/>

                    </mx:columns>

                </mx:AdvancedDataGrid>

            </mx:Application>

            • 3. Re: ADG grouping question
              jfb00 Level 3

              Hi,

              I was able to do it using IList but it is not summaring the product that contains items.

              Any ideas?

               

              Here is my sample code:

               

              <?xml version="1.0"?>

              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="init()">

                  <mx:Script>

                      <![CDATA[

                          import mx.collections.ArrayCollection;

                          import mx.collections.Grouping;

                          import mx.collections.GroupingCollection2;

                          import mx.collections.GroupingField;

                          import mx.collections.IList;

                          import mx.collections.SummaryField2;

                          import mx.collections.SummaryRow;

                          import mx.controls.listClasses.IListItemRenderer;

                         

                          [Bindable]

                          private var dpFlat:ArrayCollection = new ArrayCollection([

                              {SUMMARY_GROUP:"TOTAL GROUP A", SUMMARY_PRODUCT:"Product 1", Value:30},

                              {SUMMARY_GROUP:"TOTAL GROUP A", SUMMARY_PRODUCT:"Product 2 - Total"},

                              {SUMMARY_GROUP:"TOTAL GROUP A", SUMMARY_PRODUCT:"Product 3", Value:20},

                              {SUMMARY_GROUP:"TOTAL GROUP A", SUMMARY_PRODUCT:"Product 4", Value:20},

                              {SUMMARY_GROUP:"TOTAL GROUP B", SUMMARY_PRODUCT:"Product 1 - Total", Value:0},

                              {SUMMARY_GROUP:"TOTAL GROUP B", SUMMARY_PRODUCT:"Product 2", Value:50},

                              {SUMMARY_GROUP:"TOTAL GROUP B", SUMMARY_PRODUCT:"Product 3", Value:40},

                              {SUMMARY_GROUP:"TOTAL GROUP B", SUMMARY_PRODUCT:"Product 4", Value:60}

                          ]);   

                             

                          private var myList:IList = ArrayCollection(dpFlat);

                         

                          private function init():void{

                              createGrouping();

                          }

                         

                          private function createGrouping():void{

                              myList[1].children = new ArrayCollection ([{PRODUCT:"Item1", Value:10}, {PRODUCT:"Item2", Value:10}, {PRODUCT:"Item3", Value:25}, {PRODUCT:"Item4", Value:25}]);

                              myList[4].children = new ArrayCollection ([{PRODUCT:"Item1", Value:5}, {PRODUCT:"Item2", Value:5}, {PRODUCT:"Item3", Value:6}, {PRODUCT:"Item4", Value:6}]);

                              gc.source = myList;

                              gc.refresh();

                          }

                      ]]>

                  </mx:Script>

                  <mx:AdvancedDataGrid id="myADG"

                                       width="100%" height="100%"

                                       displayItemsExpanded="true"

                                       folderClosedIcon="{null}" folderOpenIcon="{null}" defaultLeafIcon="{null}" displayDisclosureIcon="false"

                                       editable="false" headerWordWrap="true" textAlign="left" horizontalScrollPolicy="auto"

                                       sortableColumns="false" sortExpertMode="true" resizableColumns="true" >       

                      <mx:dataProvider>

                          <mx:GroupingCollection2 id="gc" >

                              <mx:Grouping>

                                  <mx:GroupingField name="SUMMARY_GROUP">

                                      <mx:SummaryRow summaryPlacement="group" >

                                          <mx:SummaryField2 summaryOperation="SUM" dataField="Value"/>

                                      </mx:SummaryRow>

                                  </mx:GroupingField>

                              </mx:Grouping>

                          </mx:GroupingCollection2>

                      </mx:dataProvider>       

                      <mx:columns>

                          <mx:AdvancedDataGridColumn dataField="SUMMARY_PRODUCT" headerText="GROUPS"/>

                          <mx:AdvancedDataGridColumn dataField="PRODUCT" headerText="PRODUCTS"/>

                          <mx:AdvancedDataGridColumn dataField="Value"  headerText="Value"/>

                      </mx:columns>

                  </mx:AdvancedDataGrid>

              </mx:Application>