Forum Academy Marketplace Showcase Pricing Features

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:

3 Likes

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.

1 Like

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

You can sort a groupedby repeating group by date if you group by a field that counts the things in the Type as they are created, with the most recent ones always having a higher count than earlier things and in date-order.

I used the following repeating group within a repeating group approach that focuses on sorting by date.

  1. groupby a field that counts the number things using a Search for[Type]:count expression. This field is created when a button is clicked or other workflow is initiated to create a thing.

  2. sort by that field in the repeating group’s Data source expression

  3. Set that sort be descending or ascending as you want.

  4. Set new things created in the internal repeating group to be the count of the external group’s cell.

  5. Filter the things in the internal group by the external group’s groupedby field (the “Grouping”).

I used this approach to create a comment board app for Word and PDF docs called Feedback (www.feedbackdocs.com) that lists comments by most recent and allows users to reply to previous comments without changing the order of the primary comments. So even if someone replies to an old comment, the most recent primary comment is still at the top.

For my app: I have a data type called TALKs. When you click Add Comment to add a thing to the external RG (a comment), it adds a field I called Count that counts the number of rows/things. I groupby that field because it will always be adding to the number of comments that I want to groupby.

Below you can see what I’m referring to.

  1. When the Add Comment Button is clicked

2. and 3

4.


(this is what happens when the reply button from the internal repeating group is click to create a new thing)

5.

1 Like