RecordSet.sort

Availability

Usage

RecordSet.sort(compareFunction)

Parameters

Parameter
Description
compareFunction
An ActionScript comparison function that determines the sorting order. Given the arguments A and B, the comparison function returns a value as follows:
  • -1 if A appears before B in the sorted sequence.
  • 0 if A = B.
  • 1 if A appears after B in the sorted sequence.

Return value

Nothing.

Description

Method. Sorts all the records using a user-specified compare function. The sort method sorts all the records in place, without making a new copy. The order is determined by the user-supplied compareFunction function. The original order is not remembered.

The sort method is approximately 10 times slower than the sortItemsBy method.

All registered views receive the following callback:

View.modelChanged("sort");

When you use the sort method, avoid sorting a RecordSet object that is associated with an application server and not fully populated yet.

Error handling

Error condition
What happens
Error message
The RecordSet object is not fully populated.
No change is made to the RecordSet object, and an error message is reported to the Flash MX output window and Debug Console.
Operation not allowed on partial RecordSet objects.

Example

The following example demonstrates how to sort an employeeList RecordSet object by multiple keys:

function orderBySeveralKeys(aRecord, bRecord)
{

    var aKey = aRecord.location + aRecord.department + aRecord.lastName;
    var bKey = bRecord.location + bRecord.department + bRecord.lastName;
    if (aKey < bKey) 
    {
      return -1;
    }
    else if (aKey > bKey) 
    {
      return 1;
    }
    else 
    {
      return 0;
    }
}
employeeList.sort(orderBySeveralKeys);

See also

RecordSet.addView, RecordSet.filter, RecordSet.sortItemsBy

 

Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/flashremoting/mx/Using_Flash_Remoting_MX/asDict43.htm