当前位置: 代码迷 >> Web前端 >> 过滤罗选DataGrid里的数据
  详细解决方案

过滤罗选DataGrid里的数据

热度:291   发布时间:2012-11-25 11:44:31.0
过滤筛选DataGrid里的数据
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
	layout="absolute" 
	creationComplete="http_test.send()" 
	>
	
	<mx:Script>
		<![CDATA[
			import mx.collections.ArrayCollection;
			[Bindable]
			var datas:ArrayCollection;
			private function onResult():void{
				this.datas=http_test.lastResult.blog.channel.item;
			}
			private function applyFilter():void{
				if(this.datas.filterFunction==null){
					this.datas.filterFunction=this.filterCities;
				}
				this.datas.refresh();
			}
			private function filterCities(item:Object):Boolean{
				var match:Boolean=true;
				if(cityFilter.text!=""){
					var city:String=item["city"];
					var filter:String=cityFilter.text;
					//			转成小写字母			搜索字符串(输入的信息转成小字后)
					//			也就是把它们全部都转换成小写再进行搜索
					//			city.indexOf(filter)	如果没有找就就返回一个-1
					if(!city || city.toLowerCase().indexOf(filter.toLowerCase())<0){
						match=false;
					}
				}
				return match;
			}
		]]>
	</mx:Script>
	
	<mx:HTTPService id="http_test" 
		url="/flex_xml/date.xml" 
		useProxy="false"
		resultFormat="object"
		result="onResult();">	
	</mx:HTTPService>	
	
	<mx:Panel title="{http_test.lastResult.blog.channel.title}" width="90%" height="90%" verticalAlign="middle" horizontalAlign="center">
		<mx:Form>
			<mx:FormItem label="City">
				<mx:TextInput id="cityFilter" change="applyFilter();"/>
			</mx:FormItem>
		</mx:Form>
		<mx:DataGrid id="http_dataGird" 
			dataProvider="{datas}" 
			width="100%" height="50%">
			<mx:columns>
				<mx:DataGridColumn headerText="标题" dataField="title"/>
				<mx:DataGridColumn headerText="作者" dataField="author"/>
				<mx:DataGridColumn headerText="类型" dataField="category"/>
				<mx:DataGridColumn headerText="连接" dataField="link"/>
				<mx:DataGridColumn headerText="城市" dataField="city"/>
			</mx:columns>
		</mx:DataGrid>
	</mx:Panel>

</mx:Application>

?DataGrid里面的数据是取于XML如果不知道怎么解析XML数据,可以看博客《Flex里解析XML数据》里面有完整的工程,可下载

  相关解决方案