4 Replies Latest reply on Apr 18, 2012 8:10 AM by Loic.Aigon

    Datagrid sorting issues with 1/0 items to consider

    Loic.Aigon Adobe Community Professional

      Hi all,

       

      I have an issue I can't find a way to fix. I am using a datagrid which I pouplate through a XMListCollection based on some XML datas.

       

      XML:

       

      var prefs:XML = <files>
      <file name="@toto" favourite="1"/>
      <file name="@toto"favourite="0"/>
      </files>;
      

       

      XMLListCollection

       

      var xlc:XMLListCollection = new XMLListCollection( new XMLList ( prefs.file) );
      

       

      MXML

       

      <mx:DataGrid id="filesList" width="100%" height="100%" dataProvider="{xlc}">
      <mx:columns>
      <mx:DataGridColumn width="25" dataField="@favourite"sortCompareFunction="favourite_sortCompareFunc"/>
      </mx:columns>
      </mx:DataGrid>
      

       

      Sorting fucnction:

       

      private function favourite_sortCompareFunc(itemA:Object, itemB:Object):int {
         
         
          var value1:Number = Number( itemA.@favourite );
          var value2:Number = Number( itemB.@favourite );
         
          if(value1 < value2){
               var n:Number = -1;
               return n;
          }
          else if(value1 > value2){
               return 1;
          }
          else{
               return 0;
          }
         
          return 1;
      }
      

       

      Once loaded, the datagrid appears in a "normal state":

      Capture d’écran 2012-01-29 à 12.13.13.png

       

      But if I try to sort first column, it becomes messy

       

      Capture d’écran 2012-01-29 à 12.13.24.png

      Capture d’écran 2012-01-29 à 12.13.32.png

       

      I think it might be related to the fact that the data to be sorted is only made of 0 & 1. But I can't imagine this kind of situations is not fixable.

      Any hint ?

       

      Thanks in advance for any advice,

       

      Loic