Adobe® Flex® 4 Language Reference
Hide Packages and Classes List |  Packages  |  Classes  |  Index  |  Appendixes
mx.collections 
SortField 
Packagemx.collections
Classpublic class SortField
InheritanceSortField Inheritance EventDispatcher Inheritance Object

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

Provides the sorting information required to establish a sort on a field or property in an existing view. Typically the sort is defined for collections of complex items, that is items in which the sort is performed on properties of those objects. As in the following example:

     var col:ICollectionView = new ArrayCollection();
     col.addItem({first:"Anders", last:"Dickerson"});
     var sort:Sort = new Sort();
     sort.fields = [new SortField("first", true)];
     col.sort = sort;
  
There are situations in which the collection contains simple items, like String, Date, Boolean, etc. In this case, sorting should be applied to the simple type directly. When constructing a sort for this situation only a single sort field is required and should not have a name specified. For example:

     var col:ICollectionView = new ArrayCollection();
     col.addItem("California");
     col.addItem("Arizona");
     var sort:Sort = new Sort();
     sort.fields = [new SortField(null, true)];
     col.sort = sort;
  

MXML SyntaxexpandedHide MXML Syntax

The <mx:SortField> tag has the following attributes:

  <mx:SortField
  Properties
  caseInsensitive="false"
  compareFunction="Internal compare function"
  descending="false"
  name="null"
  numeric="null"
  />
  


Public Properties
 PropertyDefined By
  caseInsensitive : Boolean
Specifies whether the sort for this field should be case insensitive.
SortField
  compareFunction : Function
The function that compares two items during a sort of items for the associated collection.
SortField
 Inheritedconstructor : Object
A reference to the class object or constructor function for a given object instance.
Object
  descending : Boolean
Specifies whether the this field should be sorted in descending order.
SortField
  name : String
The name of the field to be sorted.
SortField
  numeric : Object
Specifies that if the field being sorted contains numeric (number/int/uint) values, or string representations of numeric values, the comparitor use a numeric comparison.
SortField
 Inheritedprototype : Object
[static] A reference to the prototype object of a class or function object.
Object
Public Methods
 MethodDefined By
  
SortField(name:String = null, caseInsensitive:Boolean = false, descending:Boolean = false, numeric:Object = null)
Constructor.
SortField
 Inherited
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Registers an event listener object with an EventDispatcher object so that the listener receives notification of an event.
EventDispatcher
 Inherited
Dispatches an event into the event flow.
EventDispatcher
 Inherited
Checks whether the EventDispatcher object has any listeners registered for a specific type of event.
EventDispatcher
 Inherited
Indicates whether an object has a specified property defined.
Object
 Inherited
Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter.
Object
 Inherited
Indicates whether the specified property exists and is enumerable.
Object
 Inherited
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Removes a listener from the EventDispatcher object.
EventDispatcher
  
Reverse the criteria for this sort field.
SortField
 Inherited
Sets the availability of a dynamic property for loop operations.
Object
 Inherited
Returns the string representation of this object, formatted according to locale-specific conventions.
Object
 Inherited
Returns the string representation of the specified object.
Object
 Inherited
Returns the primitive value of the specified object.
Object
 Inherited
Checks whether an event listener is registered with this EventDispatcher object or any of its ancestors for the specified event type.
EventDispatcher
Events
 Event Summary Defined By
 Inherited[broadcast event] Dispatched when the Flash Player or AIR application gains operating system focus and becomes active.EventDispatcher
 Inherited[broadcast event] Dispatched when the Flash Player or AIR application operating loses system focus and is becoming inactive.EventDispatcher
Property Detail

caseInsensitive

property
caseInsensitive:Boolean

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

Specifies whether the sort for this field should be case insensitive.

The default value is false.

This property can be used as the source for data binding. When this property is modified, it dispatches the caseInsensitiveChanged event.



Implementation
    public function get caseInsensitive():Boolean
    public function set caseInsensitive(value:Boolean):void

compareFunction

property 
compareFunction:Function

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

The function that compares two items during a sort of items for the associated collection. If you specify a compareFunction property in a Sort object, Flex ignores any compareFunction properties of the Sort's SortField objects.

The compare function must have the following signature:

function myCompare(a:Object, b:Object):int

This function must return the following values:

  • -1, if a should appear before b in the sorted sequence
  • 0, if a equals b
  • 1, if a should appear after b in the sorted sequence

The default value is an internal compare function that can perform a string, numeric, or date comparison in ascending or descending order, with case-sensitive or case-insensitive string comparisons. Specify your own function only if you need a need a custom comparison algorithm. This is normally only the case if a calculated field is used in a display.



Implementation
    public function get compareFunction():Function
    public function set compareFunction(value:Function):void

descending

property 
descending:Boolean

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

Specifies whether the this field should be sorted in descending order.

The default value is false (ascending).

This property can be used as the source for data binding. When this property is modified, it dispatches the descendingChanged event.



Implementation
    public function get descending():Boolean
    public function set descending(value:Boolean):void

name

property 
name:String

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

The name of the field to be sorted.

The default value is null.

This property can be used as the source for data binding. When this property is modified, it dispatches the nameChanged event.



Implementation
    public function get name():String
    public function set name(value:String):void

numeric

property 
numeric:Object

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

Specifies that if the field being sorted contains numeric (number/int/uint) values, or string representations of numeric values, the comparitor use a numeric comparison. If this property is false, fields with string representations of numbers are sorted using strings comparison, so 100 precedes 99, because "1" is a lower string value than "9". If this property is null, the first data item is introspected to see if it is a number or string and the sort proceeds based on that introspection

The default value is false.

This property can be used as the source for data binding. When this property is modified, it dispatches the numericChanged event.



Implementation
    public function get numeric():Object
    public function set numeric(value:Object):void
Constructor Detail

SortField

()Constructor
public function SortField(name:String = null, caseInsensitive:Boolean = false, descending:Boolean = false, numeric:Object = null)

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

Constructor.

Parameters
name:String (default = null) — The name of the property that this field uses for comparison. If the object is a simple type, pass null.
 
caseInsensitive:Boolean (default = false) — When sorting strings, tells the comparitor whether to ignore the case of the values.
 
descending:Boolean (default = false) — Tells the comparator whether to arrange items in descending order.
 
numeric:Object (default = null) — Tells the comparitor whether to compare sort items as numbers, instead of alphabetically.
Method Detail

reverse

()method
public function reverse():void

Language Version: ActionScript 3.0
Product Version: Flex 3
Runtime Versions: Flash Player 9, AIR 1.1

Reverse the criteria for this sort field. If the field was sorted in descending order, for example, sort it in ascending order.

Note: an ICollectionView does not automatically update when the SortFields are modified; call its refresh() method to update the view.