How to count total rows with specific word in repeater column

newbie-question
repeater-widget

#1

Hello all,

I have a repeater with two columns: each row has boy or girl in column1 and short or tall in column2.

So, Im using facet filters and I select a checkbox ‘Boy’ and I select a check box ‘Short’, this in turn filters my repeater and displays only rows that match the filter ‘Boy’ and ‘Short’. Now, how do I create a widget that shows the total number of ‘boy’ and a widget that shows total number of ‘short’ based on what is currently visible in the repeater.

Eg. based on my filter, repeater shows that I have 3 boys that are short, so the box displaying total quantity of boys = 3, and box showing total quantity of short = 3. Alternatively, if I have selected boys then the box displaying quantity of girls should display 0 since none are being displayed.

I hope you understand what I am trying to get at, thank you for your help.


#2

Hi!

Upon filtering a repeater, its OnItemLoad interaction (aka, “Item Loaded”) runs for every row in the repeater. This is where you can do the counting. E.g.:

OnItemLoad
  IF (value) [[Item.isFirst]] is equal to true
     -- we're on the first row, so zero out the counts
     set text on boyCount, shortCount to 0
  IF TRUE
     -- do all of the normal stuff here, like setting the text of widgets in the repeater row to column values
  IF [[Item.childType]] is equal to Boy
     -- childType column for this row is "Boy," so increment the text of boyCount
     Set text of boyCount to [[Target.text + 1]]
  IF [[Item.height]] is equal to Short
     -- height column for this row is "Short," so increment the text of shortCount
     Set text of shortCount to [[Target.text + 1]]

Be careful of IF vs IF ELSE (You should have no IF ELSEs here). You can right-click to toggle between the two.


#3

Hi @josephxbrick,

Thank you for the reply again. Could you please elaborate on “do all of the normal stuff here,” I am still quite noobish but what I’ve done so far is created a “case 2” where IF [[Item.isFirst]] is equal to true then I set text on boyCount to ?

Thanks again :slight_smile:


#4

Hi!

The normal stuff is like what you see in the stock repeater when you drag it onto the page: essentially setting the values of the items in your row.

Set text of (rectangle) to [[Item.Column0]]

Also, anything in brackets is an expression, so Axure uses the result of the expression rather than treating like normal text. For instance, Set text of widget cost to $[[ 1 + 1]].00 would set the text to $2.00, since Axure treats the part inside of the double brackets as something it needs to evaluate.

Target.text gets the text of the thing that your command is acting upon, so…

Set text of widget boyCount to [[Target.text + 1]] 

…gets the existing text of boyCount, adds one to it, and then set boyCount to the result. Keep in mind that Item Loaded runs once for each row in your repeater, so if your repeater has 30 rows, it will run 30 times. Because of the third IF statement above, each time Item Loaded runs into a row whose childType is Boy, it increments boyCount.

Here is some recommended reading that might clear things up.

Using local variables, This, and Target

Understanding Axure’s repeater widget

Let me know if you stuck!


#5

Wow, thanks again! When I actually got this to work, I was overjoyed. This has taught me alot.

Im still trying to wrap my head around [[Target.???]]
I understand that target refers to the object that is being changed but Im not sure what .text means and what other things can be written after Target.

For example, Im trying to count item based on the amount of checkboxes selected.

Anyway, thanks again. All the help is very appreciated.


#6

Most widgets can have a text value. .text is a way of accessing that value. This notation comes from JavaScript (most directly, in this case). So Target is a dynamic reference to a widget, and Target.text is accessing the text “property” of the widget. If the widget has a text value you’ll get that. If it doesn’t you’ll get an empty string "" (basically nothing).

Within Axure, widgets have other properties you can access. Here is an incomplete list of a few examples:

  • bottom: the Y value of the bottom edge of the widget.
  • right: The X value of the right edge of the widget.
  • left and top: see above
  • name: the name you gave the widget within Axure.

In addtion to Target, you can also use This to refer to the widget that contains the action that is triggered, instead of the widget being affected by the action. Note that sometimes these can actually be the same widget if the action is affecting the widget it’s on.

So if you have OnClick of Widget A move Widget B, if you used Target in an expression in that move action, it would refer to Widget B and This would refer to Widget A.


#7

Hi

text is a property of a widget, and the period is just a way of saying that the thing after the period belongs to the thing before the period. If you wanted to find out how tall the space inside of the browser window is, for example, you’d say [[Window.height]]. (Window is special term provided by Axure.)


closed #8

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