I found a way to sort a Repeating Group by more than one field at a time. It’s not pretty, and it cost me $36 in Plug-Ins, but it actually works.
My use case was this: I needed a RG to display a ranking system that would first sort my list of Things randomly, and then sort items within that random list by a yes/no field).
I’m sure there is a more elegant way to do this, but here is what I did.
- Create a second RG. Call it something like RG Sort Order.
- Make sure you check “Show all items at once”
- I added 3 input fields to the first cell of the RG.
- In input field 1, I made the Initial Content equal to 1000 and Content Format = Integer.
- I put a conditional on Input field 1 that changes the Initial Content to 2000 when the “yes/no” field (that I want to sort by after the list is sorted randomly, in my use case) on this RG cell’s things is “yes”.
- Add a “List of Numbers” element to the page (it comes with the Toolbox plug in)
- I set it to generate the numbers 100 through 999.
- I set Input field 2’s initial content equal to the “List of Numbers’ Lists’ random item”. This assigns a random 3 digit unique number to every cell in your RG.
- I set Input field 3’s initial content to “Input field 1 + Input field 2”.
- The result is every Thing in your RG will be assigned a 4 digit integer, with the first character (the thousands place) distinguishing between Things that had a “yes” in the field I wanted to sort by and those that had a “no”.
Ok, so now we want to sort all of our Things in the RG by this new 4-digit integer. There is an intermediate step I will get to in a second, but the end goal is to have your first RG reference the list of Things in your RG Sort Order and sort them by that 4-digit integer. Obviously, the 1000 series comes before the 2000 series, and since the next 3 digits were randomly assigned, I’ll end up with a RG that is sorted randomly first, and then sorted by my boolean “yes/no” field.
The problem is, that 4 digit integer we created in the RG is not an actual field on the datatype in your DB. We normally can’t reference or sort by that 4-digit integer in your first RG because of that.
But with two plug-ins, you can.
The first plug in is “RepeatingGroup Tools (BDK)”. It costs $10. The second plug in is “List Sorter(Computed values)”. It costs $26.
From here, follow the technical steps in this video. It only took me 10 minutes to get it all up and running https://www.youtube.com/watch?v=eg-pXD4VIhM
The concept is that you use the BDK plug in to extract the 4 digit integer and make it useable outside of the RG. The List Sorter plug in then behaves like a middleman between your two RGs. It takes your RG Sort Order list and pegs it to the 4-digit integers that the BDK plug in extracted in a format that can be sorted and referenced by a regular RG.
The last step is to make your first RG’s data source equal to the List Sorter’s List, and then choose the 4-digit field to sort it by, and decide whether you want is sorted from low to high (1000 - 2999) or high to low (2999 - 1000).
It aint pretty but it works. And I have been wrestling with this for a month.
Of course, you can apply this general concept to your own use case. As long as you can create a list of dummy numbers that reflect the final sort order you are trying to achieve, the rest is just building up a few input fields to create that number for Things in your RG.
I hope this saves someone some time. I also hope this concept can be further simplified by one of you out there. It surely can be.