0 Replies Latest reply on Oct 3, 2007 5:42 AM by stevo84

    How to use compareFunction with sortOn??

    stevo84
      Hi!

      I am in big problem. I am sorting a DataSet fed by XML, that includes styled HTML. Because of that sorting doesn't work right, 'cos on some rows there are <b> tags...

      I would like to cleanup fields before sorting, however using compareFunction by which I could achieve that is not possible in sortOn function. On the other hand i cannot use sort 'cos i presume that it can be only used for one dimensional arrays...

      Here is my code...

      function order(a, b):Number {
      var name1:String = string_clean_html(a.Etg);
      var name2:String = string_clean_html(b.Etg)
      if (name1<name2) {
      return -1;
      } else if (name1>name2) {
      return 1;
      } else {
      return 0;
      }
      }

      var dgListener2:Object = new Object();
      dgListener2.headerRelease = function(evt:Object) {

      trace("column "+products_dg.getColumnAt(evt.columnIndex).headerText +" header was pressed");
      trace("\t current sort order is: "+evt.target.sortDirection);

      var sortOrder:String = evt.target.sortDirection;
      var sortColumn:String = evt.target.columnNames[evt.columnIndex];

      switch (sortColumn) {
      case 'Etg' :
      myIterator= products_ds.getIterator();
      if (sortOrder=="ASC")
      {
      myIterator.sortOn(order); //doesn't work
      }
      else
      {
      myIterator.sortOn(["Etg"], Array.NUMERIC); //doesn't work as well (probably because some rows cannot be converted to numeric form)
      }
      products_ds.setIterator(myIterator);
      break;
      }
      }
      products_dg.addEventListener("headerRelease", dgListener2);