Repeater Filter

Can I create a filter for a repeater that will only display column0 items that begin with the letter ‘A’ and remove any duplicates?

Revealing rows beginning with the letter “A” is something a filter can do. Removing duplicates is something a filter cannot do.

 [[Item.ColumnName.indexOf("A") == 0]]

…is a filter rule that gives you only rows whose ColumnName value starts with “A”.

Keep in mind that a filter is a true/false test that is applied to each row of the repeater. If the filter’s expression is true for a given row, that row is shown; otherwise it isn’t.

So the simple filter rule [[true]] will show all rows in a repeater, because it will (of course) evaluate as true for every row in the repeater no matter its content. The rule [[false]] will hide all rows for the same reason.

The expression above evaluates to true when the value in ColumnName for a given row starts with the string “A”. (Google “javascript string indexOf” to see how this function works.)

Eliminating duplicates, however, is something a filter cannot do. (Not in any way I can think of, anyhow.) Because a filter simply applies a true/false test to each row, with no regard for any past row it encountered.

There is a way this could be done with the “listener method,” but the performance might be slow, especially in large datasets.

But when it comes down to it, you are creating a prototype, not a real application. (Believe me, I have to remind myself of this all the time.) Fix it so you don’t have duplicates for your demo. :slight_smile:

1 Like

(Edit: i started replying to this thread and decided to make a demo prototype. Joseph replied before I finished, saying about the same thing–not surprising as I’ve learned so much from him here. My filter rule is similar, just a different way to get the first character of a string. I also demonstrate a few ways to accomplish the “listener method” he mentions to remove duplicates, and a kind of “fake filter” to hide duplicates but retain them in the dataset, so they can later be shown when removing all filters.)

Your first ask, filtering based on the first character, is pretty straightforward. The built-in function, .charAt(index) , returns one character from a string, where index refers to the position, starting with zero. So, [[Item.Column0.charAt(0)]] returns the first character in the Coumn0 cell for a row in a repeater. The filter would thus be: [[Item.Column0.charAt(0).toUpperCase() == LVAR1.toUpperCase()]] where LVAR1 is a pointer to the character to use as a filter. (Adding in the .toUpperCase() function, means that ‘Apple’ and ‘apple’ will match ‘A’ and ‘a’.)

Removing duplicates is more complicated. I’m also wondering if you want to truly remove duplicate rows, or just filter them out. Also, if you want to do this for all duplicates or only duplicates starting with ‘A’. Regardless, there is no built-in action or function in Axure to help with this. Essentially you need a way to keep track of all the items in the repeater, like an array or list of all Column0 values, and test the value of Column0 for each row, removing that row if the Column0 value is already in the list. For this, you can use a “dummy event” to use as a sort of repeater listener function. Basically, you can do something like move a widget by (0,0) to fire that event, or use the Fire Event action of a widget. If that widget is in a repeater, then each row’s widget repetition gets fired also. So, the Move event of the text widget in a repeater can test a global variable to see if it’s text is contained in that variable. If not, it adds its text to the variable. If true, it must be a duplicate, so it can remove its own row. It could also hide itself (and anything else in the row if needed) so it won’t be shown, but its row would still be in the dataset. This basically acts like a filter, and can be undone by removing all filters (and actually gets undone any time the repeater is “touched” like adding/removing rows, or applying/removing any filter --so it is a hacked “fake filter” that only works in limited situations.) I also took a stab at filtering for items beginning with ‘A’ (or any char) and only removing duplicates that begin with ‘A’, and this seems to work.

filtering and removing from filter.rp (68.2 KB)

Thank you for your reply and help.

I do have a followup question regarding repeaters.
I have 2 repeaters on a page,
I want to be able to click on an item in the first repeater and then have it filter the second repeater by that selection.

I’m having problems implementing this. Any suggestions?
Thanks Again.

This is possible, yes. You need to pay attention to [[Item.ColumnName]] which refers to the first/current repeater, and [[TargetItem.ColumnName]] which refers to the second repeater to be filtered.

Axure documentation, which is in my opinion fairly vague on this topic:

Here are some recent forum threads that get into this:

That was it!
I was not using “TargetItem”.
Thank You very much for your quick reply and assistance!