Access number or marked repeater rows?

I’m wondering if there’s a variable of some sort where I can get the number of currently marked repeater items to display in a ‘# Selected’ kind of thing. Attendance.rp (280.1 KB)

The easiest way to do this is to have a global variable called something like ‘MarkedRows’, then add one to it every time you mark a row, and remove one every time you unmark a row.

Simple demo here.

Attendance-Live-Count.rp (282.3 KB)

This is doing three things:

  • Checking an item updates [[MarkedRow]] to [[MarkedRow+1]] and moves the count text by 0,0
  • Unchecking an item updates [[MarkedRow]] to [[MarkedRow+1]] and moves the count text by 0,0
  • When moved, the count text does a check to see if the value of [[MarkedRow]] is more than 0. If it is, then it updates itself to [[MarkedRow]] selected. If it isn’t, it updates to None selected.

This will work as a demo, but the selected/unselected state of the row won’t be persistent unless you have a repeater column to track the state of the row, which is a little more complex.

1 Like

Thanks so much! It works perfectly

One more question, when I click the bulk select checkbox at the top, all the rows are getting counted twice. So if there are 9 rows, it reads 18. I can’t figure out a way around this.

Apologies, not sure why it’s doing that. It appears to be looping through the whole repeater twice, checking and unchecking the box in each row. @josephxbrick is our resident repeater expert and may be able to help?

Wasn’t there a recent bug fix for checkbox events double-firing? I wonder whether it could be that.

1 Like

Hi!

Jeff’s hunch is right: for whatever reason, the checkbox in the repeater is firing twice when its checked state is checked outside the repeater.

I recommend using the repeater “listener” method for this. Basically, you place on object (I use a hotspot) within the repeater row, and then move it from outside of the repeater with the intention of triggering the inner-hotspot’s Move event. The cool thing about this, is that the Moved event will then fire for each row in the repeater, AND you will have access to the objects on each row, as well as Item properties, like Item.column name, Item.index, etc.) so you can then use conditions to ask questions about the state of each row. (If you google my name and “axure listener” you will see many other ways to use a listener in a repeater.)

Here’s what you do in this situation:

  • IMPORTANT: remove all code from the checkbox inside the repeater (that decrements and increments the variable.)

  • place a hotspot in the repeater row and call it, say, “listener_CheckIfThisRowIsMarked”

  • Handle its Moved event, because we will be moving this hotspot from outside of the repeater

  • In the Moved event, say this (pseudo-code)

    On Moved
      If checkbox in repeater row is selected
        Increment counter global var
    
  • Then, outside of the repeater, make a second hotspot. This hotspot will be your generalized “count all rows” function that you will call whenever you want to update the count. You will “call” it by moving it. Name it, say, function_countAllRows

    On Moved
       Set counter variable to 0
       Move listener hotspot in repeater by 0,0 (this will update the count var)
       Set text on total-count label to counter variable.
    

Okay, now that that is all set up, inside of the checkbox in the row you would say this

  On Selected or Unselected
    move function_countAllRows by 0,0 (this is the hotspot outside of the repeater.)

[Edit] Instead of the above, REMOVE the code in the checkbox, and instead place a hotspot over the checkbox (probably also including the student’s name) and use this code. This way the function won’t get called multiple times on a Select All, which still gives an accurate count, but is much slower.

  On Click (of the hotpot covering the checkbox)
    Toggle the selected state of the checkbox in the row
    Move the function hotspot outside of the repeater

Then, in the check-all checkbox outside of the repeater you would say

  On Selected
    select the checkbox inside of the repeater
    move function_countAllRows by 0,0 

  On UnSelected
    unselect the checkbox inside of the repeater
    move function_countAllRows by 0,0 

I know this is a strange concept, so if you have any questions about why this works, please ask.

I updated the file: Attendance-Live-Count.rp (283.8 KB)

[Edit] An advantage to having a generalized count-rows function is that you can build whatever logic you want into it. For example, you can automatically select the check-all select box when all rows are selected by the user, and unselect it when less than all rows are selected. If you do this, however, you’ll want to NOT use the OnSelected, OnUnselected events of the check-all checkbox to perform any function; instead, you can put a hotspot over the whole checkbox that toggles it on click, and then conditionally checks or unchecks the checkbox in the repeater based on the new state of the check-all-or-none checkbox.

(Also, I fixed a slowness issue by removing the code from the checkbox in the repeater and using a hotspot over the top of it instead: otherwise, the hotspot “function” outside of the repeater gets called multiple times when you do a select all.)

Example:Attendance-Live-Count2.rp (285.4 KB)

2 Likes