DEMO:
http://hi.baidu.com/candypopoo1986/blog/item/afa0932846c52a91023bf6ef.html
mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="ini()" layout="absolute" height="299" width="328" backgroundColor="#FFFFFF">
<mx:Script>
<![CDATA[
import mx.controls.List;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
[Bindable]
public var Arr:ArrayCollection = new ArrayCollection([{name:"popoo",age:23,sal:30000},{name:"haha",age:12,sal:4000},{name:"bobo",age:10,sal:2322},{name:"hoho",age:3,sal:20202}]);
public function ini():void{
Arr.filterFunction = filter;
Arr.refresh();
}
public function filter(value:Object):Object
{
var str:String = select.selectedItem.name;
if(Number(value[str]>int(t1.text))){
return true;
}
return false;
}
]]>
</mx:Script>
<mx:DataGrid dataProvider="{Arr}" fontSize="12" x="10" y="10">
<mx:columns>
<mx:DataGridColumn headerText="姓名" dataField="name"/>
<mx:DataGridColumn headerText="年龄" dataField="age"/>
<mx:DataGridColumn headerText="工资" dataField="sal" />
</mx:columns>
</mx:DataGrid>
<mx:TextInput id="t1" x="126" y="192" />
<mx:Button x="10" y="240" fontSize="12" label="查询" click="ini()"/>
<mx:ComboBox id="select" x="10" y="192" width="66" fontSize="12">
<mx:Object label="年龄" name="age" />
<mx:Object label="工资" name="sal" />
</mx:ComboBox>
<mx:Label x="94" y="194" text="大于" fontSize="12"/>
</mx:Application>
这种机制在于重新删选了dataProvider中的ArrayCollection 数据,设置数据绑定后,重写filterFunction 方法,就会根据过滤内容进行重新展示
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛