注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

Flex 技术博客

醉里挑灯看剑,梦回吹角连营

 
 
 

日志

 
 

DataGrid的过滤  

2008-12-01 11:02:04|  分类: Flex 应用 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

一个例子,很久前写的,放出来看看。

 DataGrid的过滤 - 阿蔡 - 古越之地

在filter input 输入字符,可对DataGrid进行过滤。道理很简单,就是利用自定义的filterFunction给DataGrid进行过滤。

直接来看代码

<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" xmlns:local="*" backgroundColor="#999999">

      <mx:Script>

            <![CDATA[

                  import mx.collections.XMLListCollection;

                  [Bindable]

                  private var resultText:String = "Result(s)";

                  private var xml:XML = <root>

                                                <c firstName="Michael" lastName="Scofield" address="Fox river"/>

                                                <c firstName="Lincoln" lastName="Burrows" address="Sona"/>

                                                <c firstName="Fernando" lastName="Sucre" address="Boston"/>

                                                <c firstName="Theodore T-Bag" lastName="Bagwell" address="Houston"/>

                                                <c firstName="Veronica" lastName="Donovan" address="New York"/>

                                                <c firstName="Henry" lastName="Pope" address="Miami"/>

                                                <c firstName="LJ" lastName="Burrows" address="Phoenix"/>                                                                 </root>;

                 

                  [Bindable]

                  private var dp:XMLListCollection = new XMLListCollection(xml.children());

                 

                  private function textChangeHandler():void{

                        if(textInput.length==0)

                        {

                              dp.filterFunction = null;

                        }

                        else

                        {

                              dp.filterFunction = filterFunction;

                        }

                        dp.refresh();

                        resultText = dp.length + " Result(s)";

                  }

                 

                  private function filterFunction(item:Object):Boolean

                  {          

                        var searchString:String = textInput.text.toLocaleLowerCase();                      

                        var tempString : String;

                        for(var j:int = 0; j<apps.columns.length;j++) {

                              tempString = String (item[apps.columns[j].dataField]);                             

                              if(tempString.toLocaleLowerCase().indexOf(searchString)>-1) return true;

                        }                

                        return false;

                  }

            ]]>

      </mx:Script>

      <mx:HBox width="100%">

            <mx:Label text="Filter Input:"/>

            <mx:TextInput id="textInput" change="textChangeHandler()"/>

            <mx:Spacer width="100%"/>

            <mx:Label text="{resultText}"/>          

      </mx:HBox>

      <mx:DataGrid id="apps" dataProvider="{dp}" width="100%">

            <mx:columns>

                  <mx:DataGridColumn dataField="@firstName" headerText="First_Name"/>

                  <mx:DataGridColumn dataField="@lastName" headerText="Last_Name"/>

                  <mx:DataGridColumn dataField="@address" headerText="Address"/>

            </mx:columns>

      </mx:DataGrid>     

</mx:Application>

源码下载

Sample 下载

 

  评论这张
 
阅读(836)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017