RecordSet.sortItemsBy

Availability

Usage

RecordSet.sortItemsBy(fieldName, direction)

Parameters

Parameter
Description
fieldName
The name record field that is the sort key.
direction
(Optional) Specifies the sort direction. A value of "DESC" specifies descending sorting. Any other value is interpreted as ascending sorting, the default.

Return value

Returns true if the sort succeeds, or false if any errors occurred.

Description

Method. Sorts all records in the RecordSet object without making a new copy. The sort key value for each record is the contents of the field identified by the field ID. The original order is not saved.

Sorting large RecordSet objects can take a long time. RecordSet objects that contain fewer than 2000 records should take less than one second on a computer with a Pentium 3 processor. Sort times increase rapidly as the number of records grows.

When two or more records have the same sort key value, they are not sorted in a special way. The original order of the records might not be preserved.

If the fieldName parameter identifies a field that does not exist in one or more records, then null is used as the key value for those records. Null sorts lower than any other value.

The sortItemsBy method may only be used on fully populated RecordSet objects.

All registered views will receive the following callback:

View.modelChanged("sort", 1, lastRecordNumber);

Error handling

Error condition
What happens
Error message
The RecordSet object is server-associated but 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 the sortItemsBy method:

#include "NetServices.as"
var productList =new RecordSet(["ProductName","Price","Color"]);
var itemToAdd = {ProductName:"magicbubbles",Price:1,Color:"0x987654"};
var itemToAdd2 = {ProductName:"kiddyshampoo",Price:7,Color:"0x876543"};
var itemToAdd3 = {ProductName:"dishes",Price:2,Color:"0x098763"};
productList.addItem(itemToAdd);
productList.addItem(itemToAdd2);
productList.addItem(itemToAdd3);
productList.sortItemsBy("ProductName");
productList.sortItemsBy("Price","DESC");

See also

RecordSet.addView, RecordSet.filter, RecordSet.sort

 

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/asDict44.htm