Sorting on child fields in Repeating Group

Context: the following 3 tables in my database:
Owner
Property
Offer

are related as an Owner can have many Properties, and the system Users can make multiple Offers on Properties.

In a Repeating Group listing Offers and Offer details I also show related Property details and related Owner details.

Chang how the results are sorted in the Repeating Group is easy enough for primary fields like Offer Amount and Offer Date, but I am lost on how to sort by the secondary, related, child fields like Property Address, or Owner Name.

I have seen other discussions posted here about similar issues but it seems there isn’t a real solution (or I have misunderstood the solution).

Although I have tried all sorts of way to solve this (including multiple lists held as state variables and alternate plugins), I have stripped it right back to its simplest form here:

I’d be keen to see how “Sort by Property” and “Sort by Name” features could be built. As I said I think I have read discussions on similar issues but either I don’t feel they solved the problem or I have misunderstood.

1 Like

Thanks @boston85719, you’ve certainly been through the wringer on these issues! Very interesting reading…but without the original app being available to drill down on the topics that interest me I’m struggling to find the specifics of my issue. Even when your post is title refers to “sorting” the solution seems to be about “filtering”.

In your example of your hotel search results functionality, did you ever need to “sort” (not filter) by your referenced/child field “Property Type”? I’d like to see how you accomplished that…

Yes, if you read through the entire post you will see that it details how to filter and how to sort because the post discusses how to set up a search results page, which would naturally require both sorting and filtering options.

Read through the post and see how it could help you.

Sorry @boston85719 - I feel like I’m being slow.

Let me break your post down for you compared to my problem so I can demonstrate I am indeed reading it, the difference between what I am reading and my problem and where I might not be understanding…

OK- so you first describe how you are showing search result on a primary/parent table called “Hotel Listing” but most importantly for me that it has referenced child fields, and you specifically name “Property Type” and “Facilities List” as two of these. “Property Type” is of particular interest to me, because it is a child field of a referenced table “Property Type”, an almost exact scenario as I have described above (the “Facilities List” field is not quite the same).

Next you discuss setting up custom states for sort or filter parameters, and you have included “Property Type” which is awesome.

and you populate the states with the options available in the RG (which makes sense - no point including data for sorting or filtering that isn’t in the results list right?)

Then, you set the the complex filtering system - which I have to admit is pretty impressive:

Finally, you add some sort options (by Original Price) - and again I have learnt from this that sorting needs to happen before filtering so another good learning here:

However, unless I’m mistaken (and this is probably the part where I’m being slow), these sort options are using fields directly from the primary/parent table “Hotel Listing”, not fields from your referenced/child tables like “Property Type”. Is this correct? What is it I’m missing?

Perhaps an easier way to describe it, what would you do if you had to sort these results so that all Condos were shown first, then all Houses, then all Hotels, then all Apartments etc. rather than filter them by this characteristic?

All you would need to do is sort after you filter the results…in the case of this

I believe you would use the sort by feature on the filter itself…see the screen shot above under the “add new constraint”

Other options are to have repeating groups that are “hidden”…most people use a popup to keep them. These repeating groups can be filter or sort “steps” so you can have a set up like

R.G. 1 is list of all “things” ( not filtered or sorted )

R.G. 2 is using R.G. 1 has a datasource and you filter the results

R.G. 3 is on the page itself and visible to a user…it uses the R.G. 2 as the datasource and it is on R.G. 3 that you sort.

When you set up the sort, if the database is set up correctly and you have relational database structure ( which I believe you do ) then the sort would look like

sort by : property listing : property type name

This should make it so that the property type name ( house, hotel etc ) would be used as the alphabetical sort

Try this method of multiple repeating groups and see how it works for you.

One other benefit is that it is quicker, since you do a search for all things on page load to get all listings into R.G. 1 then every time a user is filtering or sorting it doesn’t require a new search of the database, instead it just references the info from the R.G. 1 or R.G. 2…also helps with responsive design issues if you need more than one R.G. on page to display results of different widths etc.

Any chance you could show me a quick a demo of what you are describing? We might be getting down to it here, I may not have set up my data structure correctly to make this work!

I have tried setting up something similar to the two options you have outlined and haven’t been successful.

Option 1 - sorting on filter feature

This seems to have a similar problem to using the sorting on the datasource - child fields just simply aren’t available for selection:

Remember, in my model an “Offer” has a “Property” (referenced/child table):

But when I create a filter on my data source there are no “Property” fields available to sort on:

Option 2 - sorting using second/multiple RGs

Again a similar issue, where if I select an RG as the data source the child table fields are not available for selection:

Do I need to move away from normalised data structures and deal with the problems of data redundancy instead?

I am not very familiar with data. I learned a little bit which was enough to get me through my project on bubble.

When you talk about data redundancy

If you mean data redundancy in the sense of having a relationship built into two tables

  1. Data type = Offer
    data field = property ( related to data type 2 )

  2. Data type = property
    data field = offer ( related to data type 1 )

Whereby having the “circular referencing” going on as data redundancy, then I have my database set up with data redundancy.

If talking about the problems associated being mostly focused while building workflows to add / edit data to remember to update that data in each location their is redundancy, I personally find the tradeoff of doing that compared to not being able to retrieve data as easily, I choose the easier retrieval.

I also, didn’t come up with the complex filtering, I had a lot of help from @NigelG who in my experience on the forum has been the most knowledgeable and helpful in regards to database structuring in bubble.

Check out this editor and see if it does the trick for you.

What I put together was a single repeating group that will show results of offers only when a property type is selected. Once you selected a property type, only offers for that type are visible, however you can add additional property types. I used two, home or commercial.

From this you can then select a sort option to sort by the offer value…

Cheers @boston85719 - appreciate all your help with this.

Normalization is the process you have referred to about splitting data into separate tables and creating relationships between them. Tables that aren’t normalized generally contain redundant data like this one:

You can see I’ve highlighted the redundant (repeating rows) of data. That should be split into a separate table as a single row with a relationship created to the first table (normalisation).

I’m starting to wonder if I am going to have to give up on normalisation and to get what I am trying to do. As you have indicated from your own example, you still can sort by Property Type (which is what I am really trying to do!)

BTW - I can’t confirm whether my statement about not sorting by Property Type is correct, you may not have set permissions on your sample app so I can access?

it is accessible to view, not to edit

let me know if you can’t view

Weird, I’m getting a “No Translation” error trying to access that app…

@davis.systems
Maybe I am missing a capability that @boston85719 has figured out, but from my understanding, Bubble does not allow sorting of combined things on a field that is not in the primary thing. The only way I was able to achieve what you are asking is by duplicating the secondary fields within the primary thing. This does make those data fields completely redundant outside of the sorting capability, but I could not find an alternative solution. I’ll be following this thread to see if you are able to get secondary sorting to work.

Yeah, thats the conclusion I’m arriving at. Thanks for the response @SerPounce.

Maybe someone else can tell us otherwise…

try it again, i guess i had not set it available to view. Just set it properly now.

I guess what I am doing isn’t really a sort but a filter.

My set up is giving a list of offers the ability to show only those of a certain type, so it isn’t really sorting the list of offers by the property type.

to be able to sort by the property type I believe you are correct it would need to be a text field on the offer data type.

To do that wouldn’t be difficult when creating the data.

So now there are two data fields of property type…one that is the relation to property type data type and the second is a text field used simply to sort a list of offers by the property type name.

Obviously would make it a bit more difficult to ensure data is consistent but I think worth the trade off of functional control.

@davis.systems Unfortunately, I believe this is the only way to sort on related fields at this point.

It seems like I saw a post indicating that Bubble is working on this issue, though. :crossed_fingers: :slight_smile:

1 Like

Cheers for responding Eli and confirming.

Can I ask where that post is you mentioned? I’d be really keen to stay across a list of known pain points/workarounds, feature requests, defects, confirmed feature development pipeline/release dates (if published). Are these around?

I’ve seen new features announced in the announcements section, and I discovered after losing a couple of days trying to resolve a different issue that I had stumbled on a known defect (discovered because I ultimately raised it as a defect on the Bubble support page and received a “we know” response!)

I’m getting a sense that both the product and the developer community are mature enough now to work collaboratively on the prioritisation of the feature/defect pipeline, and to be informed of problem areas to reduce lost development time trying to resolve issues that can be solved (yet)…

Unless this is already happening and I’m missing it?

That I can’t say nor can I confirm it’s existence. I did a quick search for it and turned up empty though my memory tells me otherwise. However, my memory is not to be trusted so let’s assume I’m mistaken until proven differently.

There was once a roadmap at this link but it appears the roadmap is no longer available. However, you can see a detailed list of features released and the release date here.

No problem @Eli. Thanks again, and thanks for the release link. I think I may have seen that page before.

:+1: