Looks like a few too many return statements in the processFilter() function, causing some of the code to be skipped instead of being processed. Probably ought to be something like "result = x" instead, so that you can return a single result at the end of the function.
--- In [email protected], "qnotemedia" <[EMAIL PROTECTED]> wrote: > > Hi all - I have two questions to post today, but will keep them > separate. > > I'm using some filter as you type code from Ben Forta and cflex.net. > The following code is basically an InputText search box along with a > combobox, and they both are filtering a datagrid's arraycollection. > What I want to do is add a second combobox to the process. It never > seems to work correctly, but each combobox, along with the text > search seems to work on their own. Note that in the code below, the > course combobox is commented out. > > I suppose what I don't understand is how exactly the processFilter > function works. > > > dgObjectList = DataGrid with 3 columns: objName, typeName, courseName > objectList = DataGrid's dataprovider > > cbTypeList = Combobox with labelField=typeName. Data includes typeID > typeListFilter = cbTypeList's dataprovider > > cbCourseList = Combobox with labelField = courseName. Data includes > courseID > courseListFilter = cbCourseList's dataprovider > > searchText = textInput box for keyword search. > > Code is as follows. Thanks for reading, > - Chris > > [Bindable] > private var objectList:ArrayCollection; > > [Bindable] > private var typeListFilter:ArrayCollection; > > [Bindable] > private var courseListFilter:ArrayCollection; > > private function resultHandlerGetAllObjects (event:ResultEvent):void { > objectList = event.result as ArrayCollection; > /* add function for filtering */ > objectList.filterFunction=processFilter; > } > private function resultHandlerGetAllTypesFilter > (event:ResultEvent):void { > typeListFilter = event.result as ArrayCollection; > } > private function resultHandlerGetAllCoursesFilter > (event:ResultEvent):void { > courseListFilter = event.result as ArrayCollection; > } > > /* Code from: > http://www.forta.com/blog/index.cfm/2006/7/13/Filtering-Data-In- Flex > http://www.cflex.net/showFileDetails.cfm? > ObjectID=415&Object=File&ChannelID=1 > */ > > private function processFilter(item:Object):Boolean { > var result:Boolean=false; > dgObjectList.selectedIndex = -1; > > if(item.objName.length == 0 || item.objName.toUpperCase().indexOf > (searchText.text.toUpperCase()) >= 0) { > if(cbTypeList.selectedItem.typeName != "Show All") { > return item.typeName == cbTypeList.selectedItem.typeName; > } else if(cbTypeList.selectedItem.typeName == "Show All") { > return true; > } > /* Course ComboBox - works on its own, but not WITH the other > combobox! > if(cbCourseList.selectedItem.courseName != "Show All") { > return item.courseName == cbCourseList.selectedItem.courseName; > } else if(cbCourseList.selectedItem.courseName == "Show All") { > return true; > } */ > } > return result; > } > > Code in App: > <mx:HBox width="100%"> > <mx:Label text="Search:"/> > <mx:TextInput id="searchText" width="100%" > change="objectList.refresh();"/> > </mx:HBox> > <mx:HBox width="100%"> > <mx:Label text="Type:"/> > <mx:ComboBox id="cbTypeList" width="100%" > dataProvider="{typeListFilter}" labelField="typeName" > change="objectList.refresh();"/> > </mx:HBox> > <mx:HBox width="100%"> > <mx:Label text="Course:"/> > <mx:ComboBox id="cbCourseList" width="100%" > dataProvider="{courseListFilter}" labelField="courseName" > change="objectList.refresh();"/> > </mx:HBox> > <mx:HBox width="100%" height="100%"> > <mx:DataGrid id="dgObjectList" width="100%" height="100%" > dataProvider="{objectList}" change="displayObject();"> > <mx:columns> > <mx:DataGridColumn headerText="Name" wordWrap="true" > dataField="objName"/> > <mx:DataGridColumn headerText="Type" dataField="typeName"/> > <mx:DataGridColumn headerText="Course" dataField="courseName"> > </mx:columns> > </mx:DataGrid> > </mx:HBox> >

