How to create a filter for a repeater?


I need to add a filter to a repeater which uses 2 bits of info. The value of a drop list and the value from a text field.

I want to let the user pick “Contains” or “Starts With” and then use that with the text from a field to build the filter. Any ideas how to combine these 2 fields into a working filter?



Filters are expressions that are evaluated against each repeater row, and must evaluate to either true or false. If the expression evaluates to TRUE for the row, the row is displayed. Otherwise, the row is not displayed.

I’d first start by figuring out how to use local variables in an expression if you don’t already. (A filter is a sort of an expression.) Basically, local variables allow you to refer to properties of other objects, in your case, the dropdown’s selected option and the text field’s value. Here is a good place to start.

Also, you will need to know about the function indexOf(). This function tells you the location of one text string within another string. So if LVAR is a variable containing the string “abc” then LVAR.indexOf(‘a’) would return 0, LVAR.indexOf(‘b’) would return 1, and LVAR.indexOf(‘c’) would return 2. However, LVAR.indexOf(‘z’) would return -1, meaning “not found.”

So if you want to find out if LVAR contains “a” the expression would be LVAR.indexOf(‘a’) >= 0, since any non-negative value would cause this expression to evaluate to true. (>= is a comparison operator meaning greater than or equal to.)

If you want to find out if LVAR starts with “a” the expression would be LVAR.indexOf(‘a’) == 0, which would evaluate to true assuming the position of ‘a’ in LVAR is 0. (== is a comparison operator meaning equal to.)

This file shows two ways of solving this puzzle, each on a different page. The first conditionally applies a filter depending on which option is chosen in the dropdown, deleting any previous filter that was there. The second uses a single filter that is applied OnPageLoad, and then that filter is simply forced to re-evaluate when the filter button is pressed.

You’ll note these examples are case-sensitive; you’d have to enter T rather than t to find the t in Terrier. I added a third page showing how to do method 1 in a case-insensitive way.

filtering_exampe.rp (92.2 KB)


Thanks very much! Your description of the function indexOf() was excellent.

The problem I was having was with the syntax of using the local variable apparently. It looks like I had the brackets in the wrong location. Looking at method 2 that’s quite a nice trick, I had no idea we could force a refresh of the repeater like that.

How about filtering a list of users as you type in a droplist?

In your example, you could type rabb in your example and the droplist content would update accordingly, allowing you to select “Rabbit” from the list.

Is this possible in Axure?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.