Hi All,
I have a datagrid with a combobox in the Header field. I need to know
how to use this as a filter. I'm working with an example of a combobox
that acts as a filter to a datagrid. This works perfectly. I also know
how to put the combobox in the header of a datagrid using a
headerRenderer. I don't know how to make the filter work once its in
the datagrid header. Part of the problem is that the combobox has to be
in a separate MXML file. Once its separate I can't (or don't know how)
to reference its properties in script. I'm including the code at the
bottom. I've had to comment out a lot of the script in order to get
this to work.
Thanks in advance for any of your help.
Lois
**************************************************************************************
Main Application
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:comp="*"
creationComplete="simpletestCat.send();simpletestFood.send()" >
<mx:Script>
<![CDATA[
import mx.controls.dataGridClasses.DataGridColumn;
import mx.collections.ArrayCollection;
[Bindable]
public var categoryList:ArrayCollection;
[Bindable]
public var foodList:ArrayCollection;
/* public function filterByCategory(event:Event):void{
if (event.target.selectedIndex == 0){
foodList.filterFunction = null;
}else {
foodList.filterFunction = catFilter;
}
foodList.refresh();
} */
// public function catFilter(item:Object):Boolean {
// return item.category_name ==
categorySelect.selectedItem.category_name;
// }
]]>
</mx:Script>
<mx:HTTPService id="simpletestCat"
url="assets\categorylist.xml" />
<mx:HTTPService id="simpletestFood"
url="assets\foodlist.xml"
result="foodList=simpletestFood.lastResult.list.food"/>
<mx:DataGrid id="foodListBox" width="100%" dataProvider="{foodList}">
<mx:columns>
<mx:DataGridColumn headerText="Product Name"
dataField="product_name"/>
<mx:DataGridColumn headerRenderer="CBoxTest"
dataField="category_name"/>
<mx:DataGridColumn headerText="Product Price"
dataField="product_price"/>
</mx:columns>
</mx:DataGrid>
</mx:Application>
******************************************************
******************************************************
Combobox MXML Component named CBoxTest.mxml
<?xml version="1.0" encoding="utf-8"?>
<mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:ComboBox id="categorySelect" width="174">
<mx:Object label="Korean" data="A" />
<mx:Object label="Indian" data="B" />
<mx:Object label="Thai" data="C" />
<mx:Object label="Japanese" data="D" />
<mx:Object label="Ethiopian" data="E" />
</mx:ComboBox>
</mx:HBox>