0 Replies Latest reply on Sep 24, 2008 10:30 AM by aKeychian

    Error in groups advancedDataGrid

    aKeychian
      Hello:
      I am developing an application with backend on .net.
      I'm trying to pool data through ObjCliente.Nombre tag with the following code, but repeated sample groups but with different content, although I try to sort the data, the last function that is executed is groupFunc, which takes random elements the grid, and start by grouping objects, but only the row. For example, I have 4 ObjectProxy in ArrayCollection that have the following information in ObjCliente.Nombre:

      ObjCliente.Nombre 1 = "foo"
      ObjCliente.Nombre 2 = "raul"
      ObjCliente.Nombre 3 = "foo"
      ObjCliente.Nombre 4 = "foo"

      This would generate 3 clusters, the first "foo", the second "raul" and the third "foo"

      If anyone can help me so kindly.
      Greetings.

      Xml and code here:
      Attach Code

      <Proyecto>
      <Id>17</Id>
      <Nombre>Azul Paraiso2 2</Nombre>
      <Descripcion />
      <Siglas>023-0001</Siglas>
      <Detalle>gfi</Detalle>
      <IdCliente>26</IdCliente>
      - <ObjCliente>
      <Id>26</Id>
      <Codigo>1</Codigo>
      <Organizacion>dulcito</Organizacion>
      <Apellido>perez</Apellido>
      <Nombre>raul</Nombre>
      ............






      <?xml version="1.0" encoding="utf-8"?>
      <mx:Panel xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns="*"
      width="100%" height="100%">

      <mx:Script>
      <![CDATA[
      import mx.collections.SortField;
      import mx.collections.Sort;
      import mx.collections.GroupingCollection;
      import mx.collections.Grouping;
      import mx.collections.GroupingField;
      import mx.rpc.events.ResultEvent;
      import mx.collections.ArrayCollection;

      [Bindable]private var myData:ArrayCollection;
      [Bindable]public var myGColl:GroupingCollection = new GroupingCollection();
      private var myGrp:Grouping = new Grouping();

      private function getData():void
      {
      myWS.ObtenerProyectos();
      }

      private function resultHandler(event:ResultEvent):void
      {
      myData = event.result as ArrayCollection;
      var ordenaLista:Sort = new Sort();
      ordenaLista.compareFunction =sortByClientes;
      myData.sort = ordenaLista
      myData.refresh();
      initDG();
      }

      private function groupFunc(item:Object, field:GroupingField):String
      {
      // display field2 as the label of the group
      return item.ObjCliente.Nombre;
      }


      private function initDG():void {

      // Initialize the GroupingCollection instance.
      myGColl.source = myData;

      // The Grouping instance defines the grouping fields
      // in the collection, and the order of the groups
      // in the hierarchy.
      var gf:GroupingField = new GroupingField("Cliente");
      gf.groupingFunction = groupFunc;
      var gf1:GroupingField = new GroupingField("Nombre");


      // The grouping property contains a Grouping instance.
      myGColl.grouping = myGrp;

      // Specify the GroupedCollection as the data provider for
      // the AdvancedDataGrid control.
      dgProyectos.dataProvider=myGColl;

      // Refresh the display.
      myGColl.refresh();
      }

      private function sortByClientes(obj1:Object, obj2:Object,fields:Array = null):int
      {
      var value1:String = obj1.ObjCliente.Nombre;
      var value2:String = obj2.ObjCliente.Nombre;

      if(value1 < value2) {
      return -1;
      }
      else if(value1 > value2){
      return 1;
      }
      else {
      return 0;
      }
      }

      ]]>
      </mx:Script>

      <mx:WebService id="myWS"
      wsdl=" http://localhost/XlineProjectTools/WebServices/Proyectos.asmx?WSDL"
      load="getData()"
      result="resultHandler(event)" />


      <mx:AdvancedDataGrid id="dgProyectos" width="100%" height="100%" creationComplete="initDG();" sortableColumns="true">
      <mx:columns>
      <mx:AdvancedDataGridColumn headerText="Nombre" dataField="Nombre" />
      <mx:AdvancedDataGridColumn headerText="Nombre2" dataField="Nombre" />
      <mx:AdvancedDataGridColumn headerText="Descripcion" dataField="Descripcion" />
      </mx:columns>
      </mx:AdvancedDataGrid>

      </mx:Panel>