You know - I think the problem was I just didn't quite understand
how "filterFunction" works, and what exactly happens when return true
occurs.
Finally got it tho, and here it is!! The trick was just
understanding when to "end" the statement, and when to check
something first or last. Its basically:
1) Still not sure what the first line does, but its comparing the
text of my search box with one column in the grid. If the text box
has nothing OR has something, it passes either way.
2) If the first combobox is NOT "Show All", and the second combobox
IS "Show All", then check the first combobox
3) If the second combobox is NOT "Show All", and the first combobox
IS "Show All", then check the second combobox
4) If BOTH comboboxes are NOT "Show All" then check BOTH comboboxes
5) If BOTH comboboxes ARE "Show All" then check nothing.
Surely there's an easier way to implement this, but darnit, it works!!
Now I will need to stretch out my search box to include more than one
column. Wish me luck, ;)
- Chris
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" &&
cbCourseList.selectedItem.courseName == "Show All") {
if (item.typeName == cbTypeList.selectedItem.typeName) {
return true;
}
} else if (cbTypeList.selectedItem.typeName == "Show All" &&
cbCourseList.selectedItem.courseName != "Show All") {
if (item.courseName == cbCourseList.selectedItem.courseName) {
return true;
}
} else if (cbTypeList.selectedItem.typeName != "Show All" &&
cbCourseList.selectedItem.courseName != "Show All") {
if (item.typeName == cbTypeList.selectedItem.typeName &&
item.courseName == cbCourseList.selectedItem.courseName) {
return true;
}
} else if(cbTypeList.selectedItem.typeName == "Show All" &&
cbCourseList.selectedItem.courseName == "Show All") {
return true;
}
}
return result;
}
--- In [email protected], "Doug Lowder" <[EMAIL PROTECTED]>
wrote:
>
> 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" <qnotemedia@>
> 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>
> >
>