<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Declarations>
<mx:ArrayCollection id="dataProvider" >
<fx:Object serial="001" name="name_101" sex="男" age="21" tell="15110010001" email="email@001.com" address="adress_001" />
<fx:Object serial="002" name="name_102" sex="女" age="18" tell="18710010002" email="email@002.com" address="adress_002" />
<fx:Object serial="003" name="name_103" sex="女" age="25" tell="15510010003" email="email@003.com" address="adress_003" />
<fx:Object serial="004" name="name_204" sex="男" age="22" tell="13110010004" email="email@004.com" address="adress_004" />
<fx:Object serial="005" name="name_205" sex="女" age="30" tell="13310010005" email="email@005.com" address="adress_005" />
<fx:Object serial="006" name="name_206" sex="男" age="28" tell="13510010006" email="email@006.com" address="adress_006" />
<fx:Object serial="007" name="name_207" sex="男" age="33" tell="13910010007" email="email@007.com" address="adress_007" />
<fx:Object serial="008" name="name_308" sex="女" age="37" tell="13810010008" email="email@008.com" address="adress_008" />
<fx:Object serial="009" name="name_309" sex="男" age="50" tell="18810010009" email="email@009.com" address="adress_009" />
</mx:ArrayCollection>
<fx:Array id="columns">
<mx:DataGridColumn dataField="serial" headerText="编号" />
<mx:DataGridColumn dataField="name" headerText="姓名" />
<mx:DataGridColumn dataField="sex" headerText="性别" />
<mx:DataGridColumn dataField="age" headerText="年龄" />
<mx:DataGridColumn dataField="tell" headerText="电话" />
<mx:DataGridColumn dataField="email" headerText="Email" />
<mx:DataGridColumn dataField="address" headerText="地址" />
</fx:Array>
</fx:Declarations>
<fx:Script>
<![CDATA[
protected function searchHandler():void{
if (input_field.selectedIndex != -1){
var condition:String = input_condition.text;
var conditionField:String = input_field.selectedItem.dataField;
var filterFunction:Function = function (item:Object):Boolean
{
return (condition == ""|| (item[conditionField]).toString().indexOf(condition) != -1);
};
dataProvider.filterFunction = filterFunction;
dataProvider.refresh();
}
}
]]>
</fx:Script>
<mx:VBox left="10" right="10" top="20" bottom="20">
<mx:ControlBar width="100%">
<mx:ComboBox id="input_field" prompt="请选择过滤条件"
dataProvider="{columns}" labelField="headerText"
change="{searchHandler()}"/>
<mx:TextInput id="input_condition"
change="{searchHandler()}" />
<mx:Button enabled="{input_field.selectedIndex != -1}"
label="查询" click="{searchHandler()}" />
</mx:ControlBar>
<mx:DataGrid id="grid" width="100%" height="100%"
dataProvider="{dataProvider}"
columns="{columns}" />
</mx:VBox>
</s:Application>
DataGrid快速查询
最新推荐文章于 2023-09-20 19:55:29 发布