Hi ajacobsuk,
It’s a bit tricky to pull off, but you can accomplish what you’re looking for without limiting the maximum number of rows that can be added to the repeater. Instead of using one variable for each row of the repeater’s dataset, you’ll use one variable for each column. This variable will hold all the individual values for each row of the repeater, separated by a special character that won’t appear in the rows’ values. Every time the page is loaded, the repeater will loop through this variable’s value, extracting the bits between the special characters and using them to fill in the dataset.
Rather than edit your RP file, I’ve chosen to attach a simple, stripped-down example file to better demonstrate this setup. Take a look and then read on for an explanation of how the file works.
See it live! | PersistentRepeater_EXAMPLE.rp (70.5 KB)
Note: The magic in this setup relies on the substring() and indexOf() JavaScript string methods. If you aren’t familiar with these, take a moment to read the linked reference guides before continuing.
The “ADD ROW” Button
The droplist and text field widgets are used to populate the repeater’s two dataset columns, “Number” and “Comment”. Clicking the “ADD ROW” button adds a row to the repeater using the values from the droplist and text field, and it also adds those values to the existing values of two global variables, “NumberVar” and “CommentVar”, followed by a tilde character, ~
.
This format, [[VariableName]][[NewValue]]~
, adds the new value to the end of the variable’s existing value, ensuring that later, when the page is loaded again, the individual values are added back into the repeater in the correct order. The tilde characters give us a means of determining the end of each individual value.
The Repeater’s First OnLoad Case
When the page is loaded, the repeater’s first OnLoad case begins by using the variable values to add rows to the repeater:
[[VariableName.substring(0,VariableName.indexOf("~"))]]
selects the portion of the variable value from the beginning to the first tilde, i.e. the first individual row value. Once that row is added, the “Set Variable Value” action removes the first individual row value from the variable with the expression [[VariableName.substring(VariableName.indexOf("~")+1)]]
, which sets the variable value to only include whatever comes after that first tilde. Now, the second individual row value is the first, and it gets added to the repeater when the OnLoad case fires itself again with the “Fire Event” action at the end of the case.
The Repeater’s Second OnLoad Case
The repeater’s first OnLoad case continues to loop until one of the variable values contains no more characters, i.e. until there are no more individual row values to add to the repeater. At this point, the repeater’s second OnLoad case fires, moving a rectangle in the repeater—this could be any widget in the repeater with an unused OnMove event—by (0,0), triggering its OnMove event:
This case uses a “Set Variable Value” action with the expression [[VariableName]][[Item.CorrespondingColumn]]~
to build the variable values back up, allowing the repeater to be repopulated again on subsequent page loads. Because events on widgets in repeaters fire in item order, the individual row values will be added to the variable values in the correct order.
I hope that this helps! Have a go at implementing this setup in your file, and let me know if you have any questions.