DataGrid快速查询

<?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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值