User Guide
344 Components Dictionary
Example
The following code creates a new sort named "nameSort" that performs a descending, case-
insensitive sort on the DataSet object’s
"name" field.
import mx.data.components.datasetclasses.DataSetIterator;
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});
my_ds.addSort("nameSort", ["name"], DataSetIterator.Descending |
DataSetIterator.Unique | DataSetIterator.CaseInsensitive);
In the following example, you can dynamically add data to a DataSet component by entering
first and last names into TextInput component instances on the Stage and clicking the Submit
button. After you add items to the DataSet component, you can clear the data set by clicking
the Clear button on the Stage. Drag a DataGrid component to the Stage, and give it an
instance name of
my_dg. Drag two Button components to the Stage, and give them instance
names of
submit_button and clear_button. Drag a DataSet component to the Stage, and
give it an instance name of
my_ds. Drag two TextInput components to the Stage, and give
them instance names of
firstName_ti and lastName_ti. Drag an Alert component into the
current document’s library. Add two component properties,
firstName and lastName, to the
DataSet component’s schema by using the Schema tab of the Component inspector. Next,
add a data binding from the
dataProvider property of the DataSet component to the
dataProvider property of the DataGrid component by using the Binding tab in
the Component inspector. Finally, paste the following code in the first frame of the
main timeline:
import mx.controls.Alert;
my_ds.addSort("lastFirst", ["lastName", "firstName"]);
my_dg.enabled = false;
clear_button.enabled = false;
submit_button.label = "Submit";
clear_button.label = "Clear";
my_ds.addEventListener("addItem", addItemListener);
my_ds.addEventListener("modelChanged", modelChangedListener);
submit_button.addEventListener("click", submitListener);
clear_button.addEventListener("click", clearListener);