Cases on loading a repeater


#1

I’m often using repeaters to load tables of data, and would like to change the display of some of the pieces of information based on the data: for instance display a number in red if it’s negative.

It’s possible to add cases to the onload function but they apply to all of the actions. In the above example, I could make a case for the number being negative, but I’d have to repeat all other load actions in this case and the else. What I’d like to be able to do would be “do all of that, and then if this is true do this”.

Is there a way to achieve this?


#2

Yes, you can do this. I think it would be easiest to demonstrate this if you could upload a sample .rp file, but in general, you can add multiple cases to a repeater’s Item Loaded event to handle differences in each row.

It helps if you understand that in Axure repeaters, an “Item” is the same thing as a “row”. It is also important to understand the difference between a repeater’s Loaded event and its Item Loaded event. When a repeater is first “loaded” (at the “page load” time) it first triggers the Item Loaded event for each row. Then, after the last row is handled, it triggers the Loaded event. So, Item Loaded applies to individual rows–all rows in the repeater–and Loaded applies to the whole repeater. It is “also also” important to understand that any time a repeater’s dataset is “touched” (Update Rows, Add Rows, Delete Rows, Sort, Filter, etc.) it triggers that repeater’s Item Loaded event.

I don’t understand what you mean by “all of the actions” --do you mean that it changes things in each and every row? In general, if you want anything to vary row by row, you need to handle it with conditional cases in the Item Loaded event (and it is best to have a column in the repeater dataset to control these changes.) Then, in the repeater’s Item Loaded event, use conditional cases to test the value of these columns and make changes accordingly.

So, let’s say you have a repeater with two widgets: a box for a title/label and a box for a numeric value. Furthermore, if the numeric value is negative, show it in red. You’d want at least two columns in this repeater’s dataset; one for the label and one for the value. So if there are three rows, the dataset would look something like:

| Label | Value |
Anna | 50
Billy | 32
Claude | -10

…and the Item Loaded event would include:

Case 1
If true
Set Text
myLabelBox to “[[Item.Label]]”
Set Text
myNumberBox to “[[Item.Value]]”

Case 2
If '[[Item.Value]] is less than “0”
Set Text
myNumberBox to “[[Item.Value]]” // using the “SET TO rich text” option to set the color to red

…So Case 1 applies to every row because it is triggered when “true” (always)
…Case 2 is triggered only when a row’s Value column has a negative number. To change the font properties of a widget’s text value, such as color, size, font, spacing, etc. you can choose the SET TO: rich text option instead of the default SET TO: text option.


#3

Hi,

Thanks a lot for your detailed answer, this does solve my problem!

The problem I had was that I didn’t realize that you could start the conditional loading with an “if true” case to handle all of the default behavior. If you start by a case like “if value < 0” you then have to repeat all of the default loading steps in each case, which is a hassle.

Thanks again!