Filter and refresh function for ArrayCollection
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
backgroundColor="white">
<mx:Script>
import mx.collections.ArrayCollection;
[Bindable]
public var salesAC:ArrayCollection = new ArrayCollection([
{name:"A",value:1},
{name:"B",value:2},
{name:"C",value:3},
{name:"D",value:4},
{name:"E",value:5},
{name:"F",value:6}
]);
public function filterFunc(item:Object):Boolean
{
if(item.value >= salesRange.values[0] && item.value <= salesRange.values[1])
return true;
else
return false;
}
public function filterSales():void
{
salesAC.filterFunction=filterFunc;
salesAC.refresh();
}
</mx:Script>
<mx:Panel width="400" height="300" title="Sales Dashboard">
<mx:HSlider change="filterSales()"
id="salesRange"
width="100%"
thumbCount="2"
labels="['0','2','5','7','10']"
tickInterval="1"
height="50"
maximum="10"/>
<mx:DataGrid id="dg" width="100%" height="100%" dataProvider="{salesAC}">
<mx:columns>
<mx:DataGridColumn headerText="Country" dataField="name" />
<mx:DataGridColumn headerText="Revenue" dataField="value" />
</mx:columns>
</mx:DataGrid>
</mx:Panel>
</mx:Application>
Related examples in the same category