Forum Documentation Showcase Pricing Learn more

Sorting Repeating Groups That Use :grouped by?

Hello everyone!

Has anyone found a way to sort a RG that’s using :grouped by in a way other than alphabetical?

In my case, I have meal deals that get grouped together when there’s the same meal deal listed multiple times because it’s offered at different restaurant locations. As such, my results show alphabetically by the restaurant, as that’s what I’m grouping them by.

I would love to organize these by the distance the deals are from the user (which can’t be stored). @romanmg, I was attempting to do a method similar to what you have here - any other ideas?

Hello
already ask, but no response

The ugly turnaround I had to use is creating another field like “Sort_number” on the Thing I want the aggregated result to be sorted, and then use an AVERAGE on it.

1 Like

Yep, I do something similar now. Since the distance will be a dynamic value that can’t be stored, I’m looking to do another approach.

Hi all,

After lots of trial and error, I found a way to sort a repeating group that uses :grouped by!

What you have to do essentially is create your repeating group normally like you have been, and use the :grouped by like normal. However, in each cell of your repeating group, you need to add another group. You can then set this group to be the elements you need by using the repeating group as a list of data, and matching it against search results, using the cell index to create the new list.

Since this is very confusing, here’s a screenshot of how I set up that group that’s in each repeating group cell (group on the right, search being run on the left):

I can now sort by any field for my data types! Hope this helps :slight_smile:

1 Like

Hi @callen.hedglen, are you still using this method?

I’m so confused by it that I haven’t been able to bring myself to try it. So having a group inside the repeating group allows you to change the order of the repeating group? I guess I’m not understanding how that’s possible for a child group to influence its parent repeating group like that.

I’m afraid the solution above performs a request Do a search for for each cell of the repeating group. If so, it may work but is not efficient

Hi @philnauta! Sorry to just be getting back; I’ve been traveling for the past 5 weeks.

So, the problem with using :grouped by is that you are only able to sort the “groups” by Bubble’s default sorting. I looked around a lot, and didn’t see any easy way to fix this, so a work around had to be created.

In general, what I can sort in Bubble is data returned from a search. The other comment mentioned that this isn’t efficient since it’s being ran on every cell (unfortunately), but it works, and will only do a search through the data that’s in your repeating group, since you’re selecting that as the source. Searching is also much faster than filtering.

The search we perform in the new group we created (which is in each repeating group cell) is just there to return the same data as the repeating group, so that we can manipulate it the way we want. From there, we do the type of sorting we want. In my case, I wanted to sort by a restaurant name.

Now each cell will return that same sorted data. To access the data you need, you select the one that is at the current cell’s index!

Confusing as hell, I know - it took me forever to get to that point. Hopefully that helps clear things up a bit.

1 Like