flex-搜索/过滤器数据绘制通过文本输入



我正在使用我在网上找到的过滤器设置,并且在使用三个组件进行过滤MX:DataGrid(Combobox,Checkbox和Text Input)时遇到了麻烦。复选框和Combobox正在与我的Ifilter接口和过滤器类正常使用,但是我无法使搜索输入正常工作。这是来自源文件的代码


package com.daveoncode.filters {
	
//Defines a common interface that must be implemented by all the filters.
	
	public interface IFilter {
		
		function apply(item:Object):Boolean;
		
	}
	
}
package com.daveoncode.filters {
	
	// The only purpose of Filter is to be wrapped by one or more filters (classes which extend AbstractFilter)
	
	public class Filter implements IFilter {
		// A wildcard which means "all values are accepted"
		
		public static const ALL_VALUES:String = "*";
		
		public function Filter() {
			
		}
		// This is a basic implementation of IFilter interface, the value returned is always true and only apply() 
		// methods implemented by subclasses of AbstractFilter have real buisiness logic implementation
		 
		//@return Boolean <p>Always true</p>
		 
		public function apply(item:Object):Boolean {
			
			return true;
			
		}
		
	}
	
}
package com.daveoncode.filters {
	
	public class SearchFilter extends AbstractFilterDecorator {
		
		// @param target IFilter <p>A reference to a wrapped IFilter object</p>
		// @param value Object <p>Value against which the filter is applied</p>
		
		public function SearchFilter(target:IFilter, value:Object) {
			
			super(target, value);
			
		}
		
// Impl of IFilter int by overr the dummy apply() of AbstractFilterDecorator
		
		override public function apply(item:Object):Boolean {
			
	return this._target.apply(item) && (this._value == item.Package || this._value == Filter.ALL_VALUES);
			
		}
		
	}
	
}


我正在尝试使搜索功能与下面的applyfilterrefresh()过滤功能一起使用。当前,它确实搜索了数据杂志,但仅过滤案例敏感的精确匹配。我正在寻找每次中风后过滤的。


private function applyFiltersRefresh():void {
							
		var data:ArrayCollection = ArrayCollection(sourceData);
		var filter:IFilter = new Filter();
					
		//combo box filtering - works great!
		filter = new FacilityTypeFilter(filter, facilityFilter.value);
		filter = new BedRangeFilter(filter, bedFilter.value);
				
		//checkbox filtering – works great!
		if (hideHealthcareVar == "Healthcare"){
		filter = new HideHealthcareFilter(filter, hideHealthcareVar.valueOf());
				}
				
		//Search box filtering – needs 
		 if (search.text.length > 0){
			var tempSearch:String = search.text;
			 filter = new HideHealthcareFilter(filter, tempSearch);
		}
				
		data.filterFunction = filter.apply;
		data.refresh();
			
	
				
	}


我能够以这种方式过滤我的datagrid(每个键冲程和非案例敏感),但是因为那时过滤器最终会互相覆盖,而不是同时进行两者。这就是为什么我试图将其包含在我的applyfiltersrefresh()函数中的原因。对不起,我的帖子很长,并在此先感谢您的帮助!


private function budgetGrid_filterFunc(item:Object):Boolean {
		if (search.text.length == 0) return true;
		var f:String = "ig";
		var packageSearch:RegExp = new RegExp(search.text, f);
		var packageMatch:Boolean = packageSearch.test(item.Package);
				
		var itemSearch:RegExp = new RegExp(search.text, f);
		var itemMatch:Boolean = itemSearch.test(item.ItemNum);
				
		var descriptionSearch:RegExp = new RegExp(search.text, f);
		var descriptionMatch:Boolean = descriptionSearch.test(item.ItemDescription);
				
		return (packageMatch || itemMatch || descriptionMatch);
				
				
}
private function searchInput_change():void {
				
		if (search.text.length == 0) {
			budgetGrid.dataProvider.filterFunction = null;
		} else {
			budgetGrid.dataProvider.filterFunction = budgetGrid_filterFunc;
		}
			budgetGrid.dataProvider.refresh();
				
				
		}
			

package com.daveoncode.filters {
	
	/**
	 * @author Davide Zanotti (davidezanotti@gmail.com)
	 */
	public class searchFilter extends AbstractFilterDecorator {
		
		/**
		 * @param target IFilter <p>A reference to a wrapped IFilter object</p>
		 * @param value Object <p>Value against which the filter is applied</p>
		 */
		public function searchFilter(target:IFilter, value:Object) {
			
			super(target, value);
			
		}
		
		/**
		 * Implementation of IFilter interface by overriding the dummy apply() of AbstractFilterDecorator
		 */
		override public function apply(item:Object):Boolean {
			var f:String = "ig";
			var packageSearch:RegExp = new RegExp(this._value, f);
			var packageMatch:Boolean = packageSearch.test(item.Package);
			
			var itemSearch:RegExp = new RegExp(this._value, f);
			var itemMatch:Boolean = packageSearch.test(item.ItemNum);
			return this._target.apply(item) && (packageMatch  || itemMatch);
			
		}
		
	}
	
}

相关内容

  • 没有找到相关文章

最新更新