Skip navigation
Currently Being Moderated

Detect Sort

Apr 9, 2013 1:57 PM

Is it possible to detect an exisitng sort of a dataProvider (ArrayCollection)?

 

Thanks

 
Replies
  • Currently Being Moderated
    Apr 15, 2013 6:45 AM   in reply to Zolotoj

    You could capture a sort on a DataGrid using sortChange and set a variable based on that change.

     
    |
    Mark as:
  • rtalton
    1,133 posts
    Oct 28, 2008
    Currently Being Moderated
    Apr 15, 2013 9:05 AM   in reply to Zolotoj

    Hi Zolotoj,

     

    Within some method you have, you can get the DataProvider's sort like this:

    var currentSort:ISort = this.acMyDataProvider.sort

     

    Then you can easily examine the SortField's "name" property like this:

    var theSortFieldName:String = currentSort.fields[0].name

     

    where--

    "acMyDataProvider" is an ArrayCollection,

    "fields" is an Array of SortField,

    "name" is the name of the field used to sort the Collection.

     

    If more than one SortField is contained in the "fields" collection (like a multiple-field sort), you can loop through them to get the name of each SortField.

    Each SortField object contains all the information and options about the sort, like descending, numeric, compareFunction.

     

    ++++++++++++

     

    If it helps anyone else, I often use the following technique to capture the current sort, re-sort on a different field, search for something using the new sort, then revert back to the original sort by doing this:

     

    EXAMPLE

    //store the current sort, whatever it may be

    var currentSort:ISort = this.acMyDataProvider.sort;

     

    //change to another sort:

    var newSort:Sort = new Sort();

    newSort.fields = [new SortField('EmployeeName', false, false)];

    acMyDataProvider.sort = newSort;

    acMyDataProvider.refresh();

     

    //search for a record using the new sort:

    var searchObj:Object = {EmployeeName:'Johnny'};

    var cursor:IViewCursor = this.acMyDataProvider.createCursor();

    if(cursor.findFirst(searchObj)) {

         trace('found');

         //do something with the record

         var employee:Object = cursor.bookmark;

         employee.ID = 95;

         employee.HireDate = new Date();

         ...

         ...

    }

     

    //revert back to the old sort, whatever it was:

    this.acMyDataProvider.sort = currentSort;

    acMyDataProvider.refresh();

     

    In this case I don't need to know the name of the field(s) being sorted on; I just want to restore whatever sort the user has done (like in a DataGrid) after I search for something using a different sort.

    This should give you an idea on the different ways you can use sorting within a Collection.

     

    HTH

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points