Appending RG while maintaining sort order

I have users with lists of preferences and I’m using intersect on those lists to calculate count on # of matches in preferences lists. I am sorting users by distance also. So using bdk tools and transform list (sorry @keith ) I was able to sort the result by the calculated value of intersect:count however I need to sort within the count based on distance so that if more than 1 user result with the same intersect:count is returned - the one with the closer distance to the currentuser appears first in the list.

I accomplished what I am trying to show the user with stacked RGs where each RG is set to intersect:count is 4 intersect:count is 3 intersect:count is 2 intersect:count is 1 intersect:count is 0 – each sorted by distance from currentuser & utilizing collapse when hidden to appear as one RG.

Unfortunately my method prevents me from doing a lot of different things with my RG because its not just one RG its many. So pagination doesn’t work.

Is it possible to append one RG to another maintaining the sorting? They are all USER.

Hey @dtm2023, first, I want to remind you that Repeating Groups are just a display mechanism for lists (by which we mean, some list expression). The RG is not the list, it is merely a display element for the list expression you’ve constructed in the “Data source” field here:


… or when you force a new list to be displayed via Display List:

Of course, Repeating Groups have an exposed state which allows you to refer to the current contents of the RG somewhere else (as That Repeating Group's List of Whatevers). This is similar to if you were storing the result of some list expression in a custom state, or in some other element (like List Shifter or Floppy Expression Watcher) that takes some input list expression and exposes that list at some other exposed state (which I usually refer to as an “output”).

So you’ve apparently got five list expressions. I suppose these are the outputs of five different Transform List elements? And then perhaps you’re sorting each list by geographic distance?

So you’ve got TL 1 :sorted, TL 2: sorted, etc.

In vanilla Bubble, the “concatenation” operator is merged with, which is one of those operators that operates set-wise (it removes duplicates). However, in this case that wouldn’t seem to be an issue.

Anyway, when you merge two lists (e.g., List A merged with List B) that have defined sorting, the resulting list preserves the order of items in each list as far as I can tell. And the result is [First Item from A, ..., Last Item from A, First Item from B, ... Last Item from B].

So there’s a lot of different ways you can accomplish merging the five lists. If you turn on parentheses (Settings > Versions > Experimental > Expression parentheses) you can just write this merge as an expression (and you’ll see in my previous screenshot there’s an example of this) and it’ll look something like:

(TL1 :sorted) merged with (TL2 :sorted) merged with (TL3 :sorted) merged with (TL4 :sorted) merged with (TL5 :sorted)

And unless you further modify that expression, the order of things should be preserved.

If for some reason it isn’t, what you could do is use List Shifter’s SET Custom List action. The “Custom List” is like a custom state (it only updates when you tell it to via the SET action) but it preserves duplicates and the SET action has a concatenate option. Like so:

When the concatenate option is set, what happens is that the new Custom List value is appended to the current Custom List value, so you’d do this as 5 actions, appending the list expressions in order. List Shifter’s Custom List output then contains the results of the concatenation (note that you have to set “publish custom list” to yes for the values to appear there – this lets you do things like multiple concatenations in a row and then, only at the end, expose the new value).

(To use the Custom List or Process List features of List Shifter, you have to tell List Shifter the type of the list you’re going to construct, and that’s done in the main List Shifter interface, under PROCESS Output Type:

@keith I hope you know how much value you add to the bubble forum. Your willingness to unpack a question into a mini lesson has saved me countless hours of research, trial and error this time and many times before. Looking forward to implementing your guidance into my project.

1 Like

Upon further review…

I’m using a source RG to pull users within my “search radius” and sorting by distance to Currentuser… Extracting data to transform list and sort by calculated value which is intersect count. Then displaying transform list’s outputlist:filtered by advanced intersect count is 5… Count is 4 count is 3 etc. That allowed me to get the correct display… I’m not having much luck with “merged by” the parenthesis seem to appear in the wrong places while trying to build the expression. Your example was that I was using sorted by but I am using filtered. Not sure if that makes a difference.

It doesn’t.

You’ll get the hang of it. Also: Are you saying you get an incorrect/undesirable result or are you just getting hung up on the looks of the expression?

It does not.

Screenshot 2023-03-01 060054
Without using :items until #10 (because I need to display the entire contents of the transformlist which I do not know the # of) I can not seem to close parenthesis around that section of the expression which leads to something like this.

Or like this:
Screenshot 2023-03-01 061752

Update: I used items from 0 to get my parenthesis correct. Looks like this and is displaying the RG correctly.
Screenshot 2023-03-01 101512

thanks @keith - I was unaware ‘merged with’ would keep the sorting correct so it was just a matter of getting the expression to show correctly (thanks to the parenthesis - also something I did not know about previously) – you are a lifesaver. Also, it was an 8 item list so I had to merge intersect count 8,7,6,5,4,3,2,1, 0 - could this have been made simpler with listshifter or floppy? I may have a 32 item list to compare - then I’ll have to merge 32 times… and this is already UGLY:
Screenshot 2023-03-01 102626

1 Like