2 Replies Latest reply on Oct 16, 2007 8:02 AM by peewee64

    wrong sort order in datagrid sorting multiple columns

    peewee64
      Hello,

      I'm a little confused about sorting multiple columns in a datagrid. The following code does some sorting, but not the sorting, I would expect or what do you thing about a alphabetical order of O coming before M or after P . In my opinion the code should sort stadt, name, vname clicking on the column stadt and name,vname clicking on the column name, but obviously it does not do it correctly? Can you see any mistake in the code or is it a bug?

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="vertical">
      <mx:Script>
      <![CDATA[
      import mx.collections.SortField;
      import mx.collections.Sort;
      import mx.collections.ArrayCollection;
      import mx.events.DataGridEvent;
      var myData : ArrayCollection = new ArrayCollection(new Array(
      {name:"Meier",vname:"Peter",stadt:"Bonn"},
      {name:"Meier",vname:"Max",stadt:"Bonn"},
      {name:"Meier",vname:"Olga",stadt:"Bonn"},
      {name:"Meier",vname:"Peter",stadt:"Bochum"},
      {name:"Meier",vname:"Susi",stadt:"Bochum"}
      ));
      function mySort(event:DataGridEvent){
      var mySorter : Sort = new Sort();
      switch (event.columnIndex){
      case 1:
      mySorter.fields = [
      new SortField("name",true),
      new SortField("vname",true)
      ];
      break;
      case 3:
      mySorter.fields = [
      new SortField("stadt",true),
      new SortField("name",true),
      new SortField("vname",true)
      ];
      break;
      }
      myData.sort = mySorter;
      myData.refresh();
      }
      ]]>
      </mx:Script>
      <mx:DataGrid dataProvider="{myData}" headerRelease="mySort(event)">
      <mx:columns>
      <mx:DataGridColumn dataField="name" headerText="Name" />
      <mx:DataGridColumn dataField="vname" headerText="Vorname" sortable="false"/>
      <mx:DataGridColumn dataField="stadt" headerText="Stadt" />
      </mx:columns>
      </mx:DataGrid>
      </mx:Application>