I’m trying to sort a RG dynamically which works actually very well, as long as the things (fields) you sort on are on the same level as the source of the RG. I have headers for each RG column that set the RG’s custom state of ‘sort’ to the field name’s value I’d like to sort on. Like so:
RG source = Search for ‘Jobs’
Things (fields): name, Created Date.
Click on header text ‘JOB’ or header ‘CREATED DATE’:
This works great until a second level Thing comes into play.
Sorting on Job’s name is no problem, but sorting on Job’s Account’s name seems impossible using this method as Bubble does not seem to figure out which field to select for the sort. I’ve gone through many of the related topics on this forum, but couldnt find this specific issue.
I can add new conditions that if ‘this RG’s custom sort = value x’= data source= something to make sure to filter on a Thing’s thing but: 1. this is not very straightforward and 2. most often just doesn’t seem to work.
So how are you sorting RG’s on multiple fields? And why can’t I just select the second level thing to sort on and by default it’s primary field will be used?
I agree that this is pretty tricky. You’re not the first to bring it up. I tend to make it easier on myself by just adding a new field to the first level Thing so that I can sort by it instead. If it’s mission critical, then it’ll be worth the management of an additional field.
It is hard because it is inefficient to do it from the “outside in” (so Job > Account) … so get a million rows back from the database, including linking to another table, then sort that million rows (in “memory”) on the returned data and then pick the top 20 and chuck away 99980 rows. You would face the same issue with an SQL query that accessed the data this way, it would end up scanning the whole table first. You would write your query in a different way to get round this.
Far more efficient to get the first 20 from the “inside out” (so Account > Job) and then list the Job data from that 20.
(assuming that you are only displaying the first 20 in your repeating group)
It is a little confusing, however. You can only sort on the Search for fields on the search’s data type. And the reference says that if the dynamic field is not found then it won’t sort. So it looks like it will work to put “Account Name” in there, as it won’t give an error, but it just won’t sort.
The way to do it, as @romanmg says is to have a list of Jobs on the Account, and then go from Account > Job and sort on the Account.
If I understand correctly, you can in fact sort on a secondary thing when you do not state the data source as:
do a Search for Job
but instead do
do a Search for Account’s Job.
This allows you to sort dynamically on Account and also lets you add a :sorted or :filtered constraint on the Job part of the string allowing you to sort on that.
However, my problem is with the fact that I have one central data type ‘Job’ which has a lot of other data types connected. In my case, a Job can have multiple Users, Accounts connected. But also a data type called ‘Contact’, ‘Calculation’ and ‘Invoice’ as well as ‘Files’.
In the example I gave initially it is not just one secondary thing I need to reference, but multiple. I do not seem to come any further than two at this point with the solution you stated and my example above because even when you merge a data source, that second data source should be of the same data type.
This is why I come back to my initial proposal as for me it is far more logical to reference (within constraints) all the other Things through the one data type that connects them all (the Job). Is this from a data architecture perspective illogical and inefficient?
In the RG I can easily list ‘Current cell’s Job’s Account’s Contact’s email’ (going three levels deep), but sorting on that email field will be impossible?
My actual problem is not with the Accounts type, but it is an example of a data type that I’d also like to include in the RG and be able to sort on. In this case, there are constraints on the Account based on, for example, a status or a type field which results in just one Account to show up.
As I understand sorting a list alphabetically on whichever field that is in the RG is far more complex that I initially assumed, is it fair to say it is impossible to sort a RG this way? In that case I would probably have to look into another solution, something more along the lines of a search result in an entirely new RG.
I’m following the logic in the responses, but still I am unable to get passed an issue with sorting. I have watched all available tutorials, have tried nearly a dozen different logical sequences to perform the sort with no luck.
Basically I want to sort my search results in a repeating group by two different data fields and see the results show all matches for both data fields.
I have Property Listings as a data type. I have Property Types as a data type. I have property types (list) as a data field for the Property Listings data type.
I can sort fine when selecting only one property type. However, when I select a second property type I get no results displayed. I want users who select houses, condos and hotels to see the results display all the houses, condos and hotels that meet the criteria of the other search parameters.
aha! Thanks @NigelG! If I’m understanding this correctly you are showing that Bubble requires a different way of thinking about sorting… rather than searching for the thing we want to display then traversing the graph to get the data to sort by, we need to search for what we want to sort by, then traverse the graph to get the data we want to display.
That has data design implications showing why it is important to link in both directions, and it would seem to have performance implications as well… eg, a list of customers sorted by their most recent order’s date would have to be:
But wouldn’t that search return every order in the database and make Bubble’s server sort them, then go back to the database again for each order to get it’s associated customer? If I’m understanding correctly it would be more efficient to put the sort in the search then Bubble would retrieve only the first batch of items:
Below is a link to my app editor. I have it set to “everyone can edit”.
I’m trying to get the sort to function on multiple levels just like the big OTAs like booking.com or Expedia have set up. So a user could select multiple property types, multiple property facilities, multiple neighborhoods, a base review score and then sort all those results by either price, review score etc.
If anybody has any ideas on how to make this work it would be a life saver…literally.