Add row from one repeater to another always adds the first row of the originating repeater


#1

I have 2 repeaters. One with 3 rows of names (this is where the row is getting added to) and one with over 100 names (this has the names that I select and add to the other repeater). I am performing a search by last name from the originating repeater and then selecting one of those names using a checkbox. When I click on my “assign selected patients” button a row should be added with that name to the repeater above. It works as long as the search only brings back one row. However, when the search brings back multiple names and I select one of the names (not the first in the list), it always adds a row with the name of the first name on the list. Would like to be able to add whatever names I am selecting via checkbox to the other repeater. Any suggestions?


#2

@mnunez,

I think you’ll need to upload your .rp file here in order for forum users to see exactly what’s going on with your code. There are many ways this could work or not…

In general, look again closely at your conditional logic–your IF conditions–to follow exactly how a row is determined to be selected and exactly what conditions must exist in order to copy a row to the second repeater. It is not clear from your description how you are performing your search; are you filtering the big repeater? How are you distinguishing between a row that meets the search criteria and a selected row from those row results? Does the first row in your search results somehow get automatically “selected”? …Etc.

Your source file will be worth 1000 x 1000 words!


#3

Hi!

Here is the way I usually do it. Note that this requires the column in this 100 row repeater to be unique. Assuming both columns were called name:

OnSelected
   Add rows 1 (setting name column in the small repeater to [[Item.name]]

OnUnselected
   Delete rows where [[TargetItem.name == Item.name]]

If it takes more than one column to uniquely identify a row (e.g., you have 5 Smiths) make an “id” column (that you don’t display) where every row is unique and add that column value as well when you add the row. Then to delete it you’d just replace “id” for “name” in the OnUnselected above.

Attached is a sample of adding and deleting rows with checkboxes. It doesn’t matter if the first repeater is filtered.

repeater_add.rp (54.8 KB)


Change repeater text on selection of another repeater
#4

Hi again! I didn’t notice that you first select them, and then assign them with a button outside of the repeater.

This would be much easier if you filtered the second repeater rather than added/deleted rows. Do the following.

Get rid of all code in the checkbox

Make the data in your second repeater the same as in the first. Add the following filter on the second repeater in its OnLoad (not OnItemLoad) interaction

OnLoad
   Add filter to this where [[Item.isMarked == true]]

When you first run the prototype, the second repeater will show no rows because none of its rows are marked yet.

Now, when we click the button, we want it to go through all of the rows in the search repeater and mark and unmark rows in the second repeater according to whether the checkbox is selected. This calls for a listener.

Basically, a listener is something you force an event upon (like Move) and then that command’s corresponding event handler (e.g. OnMove) will execute for each row in the repeater. (If you google “axure repeater listener” you’ll see lots of examples using this technique.)

We’ll add a hotspot inside of the repeater to serve as a listener and give it this code (where the second repeater is called “toRepeater”)

That Set Items per Page command simply forces the filter in the second repeater to be re-evaluated.

Now, when the button outside of the repeater that does the transfer is clicked, simply move the hotspot by (0.0) to fire off its OnMove event.

Updated file: repeater_add_2.rp (59.7 KB)


#5

This helps…thank you!


#6

Hi Joseph,

I am trying to use your great pattern as a filter - it perfectly works as is for my case, except for one issue:
In my case, the filtered content on the right must be ‘visible’ on the page load - the default filter status should be that all entries are un-check-marked. Like here:

I am not sure how to modify your pattern (posted here) to achieve this goal. Would greatly appreciate it, if you could please advise how to do this.

I tried to delete this line of code that controls visibility of content, and filter stop working.

image

Preview
question.rp (289.0 KB)

Thank you in advance,
Natalie


#7

Hi Natalie!

The way a filter works is that if the filter evaluates to true for a given row, that row will show; if it evaluates to false, it won’t. So we want the filter to evaluate to true for ALL rows when no checkbox is checked. Note that a filter doesn’t need to refer to the repeater at all. A filter defined as [[True]] would show all rows because it would evaluate to—surprise—TRUE no matter which row was being evaluated.

Set up a counter variable (starting with a zero value) that increments when you check a box and decrements when you uncheck it. Then change your filter to this.

[[Item.isMarked == True || LVAR_checkedCount == '0']]

Those two pipes (||) mean OR, so only one of the two expressions needs to be true for the filter as a whole to be true. So when no rows are checked, and thus the counter variable is 0, the filter will evaluate to true for every row, because the second half of the expression is true no matter which row is being evaluated by the filter.

If the count is not 0, the filter will work as it did before because of the same OR.

I updated your file: question.rp (291.2 KB)

[Edit] There is a decent explanation of filters in this RP sample describing facet filters, though this is tackling the problem a different way, which wouldn’t work so well when checkboxes are in a repeater.


#8

Hi Joseph!
Thank you so much for your detailed explanation and for this amazing sample!
Now, it works 100% as per my demo requirements, which is phenomenal.
I truly appreciate your great help!
Many thanks,
Natalie


closed #9