This content has been marked as final. Show 16 replies
if (item.name.search('\(Joe\)') != -1)
I did that and still returns '(Joe)' and 'Joe'.
Just curious... what kind of object are you passing in to the filter function ? Is it just XML?
dataprovider, arraycollection from database
Ok. I'm just not getting what you're trying to do. Please excuse my blank stare!
Can we see a sample of your data? I'm just not understanding this:
(item.name.search('(Joe)') != -1)
Strange to see the parenthesis in here. And it looks like you are comparing a string to a number.
Here is the code
private function refresh_handler():void
qryData.filterFunction = filter_handler;
private function filter_handler(item:Object):Boolean
var isMatch2:Boolean = false;
if (item.name.search('(Joe)') != -1)
isMatch2 = true;
Can we see an example of you data (not the code)?
in the table
Your data is showing two records, with Joe in the name field in record #1, and (Joe) in the name field of record two, correct? Any reason that the parenthesis in record #2 are necessary?
I was hoping to solve this problem without modifying the record. Let say the data is from 3rd party and we have no access other than read-only.
Thanks for taking your time to write the code!!! That was awsome!
I changed the code from
return (item.Artist == filterText)
return (item.Artist.search(filterText) != -1)
and it seems the search function ignores parenthesis, I can't seem to know why.
Glad that helps. I don't think you need to use search in your code, though. Keep in mind that the filter function is receiving only a single item from you dataprovider, so there is no need to search-there's only one thing in the item.
The filter function only needs to return true or false; that's it.
Your code looks like you are comparing the results of a search (which returns true/false) to a number (-1, which is always interpreted in ActionScript as true). So it looks like you are saying "If true=true" or "if true=false". The function will evaluate and then return true or false. Clear as mud? So you are doing two comparisons and slowing things down.
Keep it simple by comparing the item's value (a string, "Joe") to the variable you pass in (a var, filterText, which could be "Joe"). This will return true, and when you refresh the ArrayCollection, only the items evaluated as true will be visible.
You are absolutely right. I shouldn't have used the search function since I'm just filtering the dataprovider with dataprovider item. But I still want to know why search function ignores the character, it just bothers me. :)
Again thanks for your help.
I tried looking for the "search" method you are using, and cannot find it. Can you point me to it in the help docs?
btw, I'm attaching the code since I'll be taking down the example soon. Hope this can help someone else: