10 Replies Latest reply on Jul 27, 2007 5:32 AM by Rafael Magalhães

    AdvancedDataGrid Summary

    Rafael Magalhães
      Hello Everyone,

      I'm using Flex 3 ADG in an application and i need to use the summaryFunction to return a String... the problem is that everytime i try it returns NaN.

      What should i do?

      Thanks for your help!


      Rafael
        • 1. Re: AdvancedDataGrid Summary
          mxschiff Level 1
          Could you show a simplified version of some of your code, or be more explicit about what you are trying to do?

          Also, in case it helps, you might check out this example:

          http://flexgeek.wordpress.com/2007/06/14/tips-tricks-advanceddatagrid-grouping-summary-row s/
          • 2. Re: AdvancedDataGrid Summary
            Rafael Magalhães Level 1
            Hello mxschiff,

            I want that in the root line it shows not only numbers but texts too...
            below is the link for the picture that contains the result i want:

            http://moldsoft.com.br/here.gif

            What should i do?

            Thanks for your help!


            Rafael


            • 3. AdvancedDataGrid Summary
              Rafael Magalhães Level 1
              Please, help me!
              • 4. Re: AdvancedDataGrid Summary
                SwaroopAdobe
                Hi Rafael,

                Can you please provide some sample code of what you are trying to do?

                It's hard to help without knowing what the problem is.
                • 5. AdvancedDataGrid Summary
                  Rafael Magalhães Level 1
                  SwaroopAdobe,

                  Thanks for help... below is the code... the problem is that everytime i try it returns NaN.

                  What should i do?


                  <?xml version="1.0" encoding="utf-8"?>
                  <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" >
                  <mx:Script>
                  <![CDATA[
                  import mx.controls.advancedDataGridClasses.AdvancedDataGridColumn;
                  import mx.collections.ArrayCollection;
                  import mx.collections.Grouping;
                  import mx.collections.GroupingCollection;
                  import mx.collections.GroupingField;
                  import mx.collections.ICollectionView;
                  import mx.collections.IViewCursor;

                  public function Agrupar(CampoGrupo:String):void
                  {
                  if (CampoGrupo != ""){

                  var gc:GroupingCollection = new GroupingCollection();
                  gc.source = new ArrayCollection(TesteArray);

                  var gf01:GroupingField = new GroupingField("Sobrenome");
                  var gf02:GroupingField = new GroupingField("Estado");

                  var sLinha01:SummaryRow = new SummaryRow();
                  var sLinha02:SummaryRow = new SummaryRow();

                  var sCampo01:SummaryField = new SummaryField();
                  sCampo01.dataField = "Estado";
                  sCampo01.summaryFunction = func;

                  sLinha01.fields = [sCampo01];
                  sLinha01.summaryPlacement = "group";
                  gf01.summaries = [sLinha01];

                  var g:Grouping = new Grouping();
                  g.fields = [gf01];

                  gc.grouping = g;
                  gc.refresh();

                  adg.dataProvider = gc;
                  } else {
                  adg.dataProvider = TesteArray;
                  }
                  }

                  private function func(itr:IViewCursor,field:String, str:String=null):Object
                  {
                  var sum:String = "";
                  while(!itr.afterLast) {
                  var value:String = String(itr.current.Estado);
                  sum = value;
                  itr.moveNext()
                  }
                  return sum;
                  }
                  ]]>
                  </mx:Script>
                  <mx:Array id="TesteArray">
                  <mx:Object Cod="1" Nome="Rafael" Sobrenome="Magalhães" Cidade="Fortaleza" Estado="CE" Qtd="1" />
                  <mx:Object Cod="2" Nome="Daniel" Sobrenome="Credidio" Cidade="São Paulo" Estado="SP" Qtd="1" />
                  <mx:Object Cod="3" Nome="Daniel" Sobrenome="Fernandes" Cidade="Fortaleza" Estado="CE" Qtd="1"/>
                  <mx:Object Cod="4" Nome="Roberto" Sobrenome="Coelho" Cidade="Sobral" Estado="CE" Qtd="1"/>
                  <mx:Object Cod="5" Nome="Jocelio" Sobrenome="Pereira" Cidade="Fortaleza" Estado="CE" Qtd="1"/>
                  <mx:Object Cod="6" Nome="José Leonel" Sobrenome="Credidio" Cidade="São Paulo" Estado="SP" Qtd="1"/>
                  <mx:Object Cod="7" Nome="Eliane" Sobrenome="Credidio" Cidade="Presidente Prudente" Estado="SP" Qtd="1"/>
                  <mx:Object Cod="8" Nome="André" Sobrenome="Credidio" Cidade="São Paulo" Estado="SP" Qtd="1"/>
                  <mx:Object Cod="9" Nome="Alexandre" Sobrenome="Coelho" Cidade="Recife" Estado="CE" Qtd="1"/>
                  </mx:Array>

                  <mx:Panel x="0" y="0" width="731" height="592" layout="absolute" title="Teste de Advanced DataGrid">
                  <mx:Canvas x="0" y="0" width="711" height="552">
                  <mx:AdvancedDataGrid variableRowHeight="true"
                  wordWrap="true" id="adg" initialize="gc.refresh(); Agrupar('Estado');" left="10" top="10" right="10" bottom="40">

                  <mx:dataProvider>
                  <mx:GroupingCollection id="gc" source="{new mx.collections.ArrayCollection(TesteArray)}">
                  <mx:Grouping>
                  <mx:GroupingField name="Estado">
                  <mx:SummaryRow summaryPlacement="last">
                  <mx:fields>
                  <mx:SummaryField operation="SUM" dataField="Qtd" label="summary"/>
                  </mx:fields>
                  </mx:SummaryRow>
                  </mx:GroupingField>
                  </mx:Grouping>
                  </mx:GroupingCollection>
                  </mx:dataProvider>
                  <mx:groupedColumns>
                  <mx:AdvancedDataGridColumn dataField="Cod"/>
                  <mx:AdvancedDataGridColumnGroup headerText="Nome Completo">
                  <mx:AdvancedDataGridColumn dataField="Nome"/>
                  <mx:AdvancedDataGridColumn dataField="Sobrenome"/>
                  </mx:AdvancedDataGridColumnGroup>
                  <mx:AdvancedDataGridColumn dataField="Cidade"/>
                  <mx:AdvancedDataGridColumn dataField="Estado"/>
                  </mx:groupedColumns>

                  </mx:AdvancedDataGrid>
                  <mx:Button x="571" y="520" label="Agrupar por Estado" click="Agrupar('Estado')"/>
                  <mx:Button x="400" y="520" label="Agrupar por Sobrenome" click="Agrupar('Sobrenome')"/>
                  <mx:Button x="299" y="520" label="Desagrupar" click="Agrupar('')"/>
                  </mx:Canvas>
                  </mx:Panel>

                  </mx:Application>
                  • 6. Re: AdvancedDataGrid Summary
                    Rafael Magalhães Level 1
                    Please, help me!

                    I'm lost! :(
                    • 7. Re: AdvancedDataGrid Summary
                      sameerb
                      Hi,
                      You can get the same grouping as shown here -
                      http://moldsoft.com.br/here.gif

                      using the following code -

                      groupingObjecFunction can be used to return the object used in the grouped rows.
                      It is a callback function which takes the grouping label as a parameter and returns an Object.
                      It can be used to return an Object containing some properties and the group information will be added to that Object.

                      Here, it is being used to return the label information in the 'Quarter' column.

                      <?xml version="1.0" encoding="utf-8"?>
                      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical" >

                      <mx:Script>
                      <![CDATA[
                      private function grpFunc(label:String):Object
                      {
                      var obj:Object = {};
                      obj.Quarter = label;

                      return obj;
                      }
                      ]]>
                      </mx:Script>
                      <mx:Array id="arr">
                      <mx:Object Quarter="Q1" Company="Company1" Sales="100" Licenses="1" />
                      <mx:Object Quarter="Q1" Company="Company2" Sales="200" Licenses="2" />
                      <mx:Object Quarter="Q1" Company="Company3" Sales="300" Licenses="3" />
                      <mx:Object Quarter="Q2" Company="Company4" Sales="400" Licenses="4" />
                      <mx:Object Quarter="Q2" Company="Company5" Sales="500" Licenses="5" />
                      <mx:Object Quarter="Q3" Company="Company6" Sales="600" Licenses="6" />
                      <mx:Object Quarter="Q3" Company="Company7" Sales="700" Licenses="7" />
                      <mx:Object Quarter="Q4" Company="Company8" Sales="800" Licenses="8" />
                      <mx:Object Quarter="Q4" Company="Company9" Sales="900" Licenses="9" />
                      </mx:Array>


                      <mx:AdvancedDataGrid id="adg" initialize="gc.refresh()" width="400" height="400" >
                      <mx:dataProvider>
                      <mx:GroupingCollection id="gc" source="{arr}" >
                      <mx:Grouping >
                      <mx:GroupingField name="Quarter" groupingObjectFunction="grpFunc" />
                      </mx:Grouping>
                      </mx:GroupingCollection>
                      </mx:dataProvider>

                      <mx:columns>
                      <mx:AdvancedDataGridColumn dataField="Company" />
                      <mx:AdvancedDataGridColumn dataField="Sales" />
                      <mx:AdvancedDataGridColumn dataField="Quarter" />
                      <mx:AdvancedDataGridColumn dataField="Licenses" />
                      </mx:columns>
                      </mx:AdvancedDataGrid>

                      </mx:Application>


                      However, there are two Bugs -
                      https://bugs.adobe.com/jira/browse/FLEXDMV-958
                      https://bugs.adobe.com/jira/browse/FLEXDMV-959

                      which will be fixed in the next release.
                      Hence, the above code will work only after the next release.

                      Thanks,
                      Sameer
                      • 8. Re: AdvancedDataGrid Summary
                        Rafael Magalhães Level 1
                        Ok, I understood! Thanks for the explanations. Do you know when you will release the next update?
                        • 9. Re: AdvancedDataGrid Summary
                          Quimera Systems
                          Boa tarde rafael, até que enfim achei um irmão no forum da adobe.

                          Adicione meu msn por favor para trocarmos algumas figurinhas, um abraço.

                          Atenciosamente

                          Thiago Segato
                          kernelpanic_th@hotmail.com
                          • 10. Re: AdvancedDataGrid Summary
                            Rafael Magalhães Level 1
                            Hehe...

                            É bom encontrar brasileiros no fórum! Já te adicionei no msn.

                            O meu é: rafaelmagalhaes@gmail.com


                            Abraço!