1 Reply Latest reply on Mar 15, 2010 2:07 PM by Flex harUI

    ArrayCollection Sort with typed Object

    eranda007

      I have a ArrayCollection that initialize with follwing VO. I need to sort from the 'friendname' attribute.

       

          public class Friend
          {
             
              private var _id:Number;
              private var _friendid:Number
              private var _friendname:String
         
              public function Friend()
              {
              }
             
              public function get id():Number
              {
                  return _id;
              }
             
              public function set id(value:Number):void
              {
                  _id = value                   
              }
             
              public function get friendid():Number
              {
                  return _friendid;
              }
             
              public function set friendid(value:Number):void
              {
                  _friendid = value;
              }
             
              public function get friendname():String
              {
                  return _friendname;
              }
             
              public function set friendname(value:String):void
              {
                  _friendname = value;
              }

      }

       

       

      I wrote a function to sort the ArrayCollection

       

      private function sortDataByFriendName(rawData:ArrayCollection):ArrayCollection
        {
                  var dataSortField:SortField = new SortField();
                     dataSortField.name = "friendname";
                      dataSortField.numeric = false;
                      dataSortField.caseInsensitive = true;
                       dataSortField.descending = true;

                var dataSort:Sort = new Sort();
                      dataSort.fields = [dataSortField];
                        rawData.sort = dataSort;
                      rawData.refresh();
                 
                  return rawData;
      }

       

       

      But the ArrayCollection dosen't sort.

       

      How do I sort the Sort the ArrayCollections with typed objects

       

      Thanks in advance.