DataSet.hasSort()

Availability

Flash Player 7.

Edition

Flash MX Professional 2004.

Usage

dataSetInstance.hasSort(sortName)

Parameters

sortName A string that contains the name of a sort created with DataSet.addSort().

Returns

A Boolean value.

Description

Method; returns true if the sort specified by sortName exists; otherwise, returns false.

Example

The following code tests whether a sort named "nameSort" exists. If the sort already exists, it is made the current sort by means of DataSet.useSort(). If a sort by that name doesn't exist, one is created by means of DataSet.addSort(). To test this example, drag a DataSet component and a List component to the Stage, and give them instance names of my_ds and my_list respectively. Add a binding between the dataProvider property of the DataSet component and the dataProvider property of the List component by using the Bindings tab of the Component inspector. Create two properties in the schema of my_ds DataSet by using the Schema tab of the Component inspector: name (data type: String) and years (data type: Number). Add the following code on Frame 1 of the main timeline:

import mx.data.components.datasetclasses.DataSetIterator;
my_list.labelField = "name";

my_ds.addItem({name:"Milton", years:3});
my_ds.addItem({name:"Mark", years:3});
my_ds.addItem({name:"Sarah", years:1});
my_ds.addItem({name:"Michael", years:2});
my_ds.addItem({name:"Frank", years:2});

if (my_ds.hasSort("nameSort")) {
    my_ds.useSort("nameSort");
} else {
    my_ds.addSort("nameSort", ["name"], DataSetIterator.Descending);
}

See also

DataSet.addSort(), DataSet.applyUpdates(), DataSet.useSort()


Flash CS3