User Guide

362 Components Dictionary
Example
In the following example, filtering is enabled on the DataSet object named employee_ds.
The specified filter function returns
true if the empType field in each item is set to
"management"; otherwise, it returns false.
employee_ds.filtered = true;
employee_ds.filterFunc = function (item:Object):Boolean {
// Filter out employees who are managers.
return(item.empType != "management");
};
In the following example, you filter the contents of a DataSet component based on the
selected item in a ComboBox component. The ComboBox component lets you select all
people, males only, or females only.
Drag the a DataSet, DataGrid, and ComboBox components to the Stage, and give them
instance names of
my_ds, data_dg, and filter_cb respectively. Select the my_ds DataSet
instance on the Stage and add two new properties:
name and gender. Create a data binding
between the
dataProvider property of the DataSet and the dataProvider of the DataGrid
component by using the Bindings panel of the Component inspector. Add the following
ActionScript code to Frame 1 of the main timeline:
my_ds.dataProvider = new Array({name:"Charles", gender:"M"}, {name:"Buddy",
gender:"M"}, {name:"Walter", gender:"M"}, {name:"Ellen", gender:"F"},
{name:"Jamie", gender:"F"}, {name:"Sarah", gender:"F"}, {name:"Adam",
gender:"M"});
my_ds.addSort("nameSort", ["name"]);
my_ds.addSort("genderSort", ["gender", "name"]);
my_ds.useSort("genderSort");
filter_cb.dataProvider = [{label:"All", value:""} , {label:"Male only",
value:"M"}, {label:"Female only", value:"F"}];
filter_cb.addEventListener("change", filterListener);
function filterListener(evt_obj:Object):Void {
var selItem:Object = evt_obj.target.selectedItem;
if (selItem.value.length == 0) {
my_ds.filtered = false;
} else {
my_ds.filtered = true;
my_ds.filterFunc = function(item:Object):Boolean {
return (item.gender == selItem.value);
}
}
}