Sort repeating group by a linked child element

Hi all,

I’ve tried to browse forums etc. but haven’t been able to find a working answer to this one, so hope you can help!

Here’s the context:

  1. I have a repeating group of cards based on a table of Destinations in the database. Each card has some info drawn directly from the destinations, like name, country, image, etc… See below for a screenshot:

Here’s the trick, the cards in the repeating group also has a field to display its minimum price. This number comes from a related database with flight prices where there are many prices per destination, so I’m searching for flight prices and filtering for prices where the destination airport name is the same as the destination airport name in the parent group (i.e. the card), and then taking the minimum price.

I obviously want to sort this repeating group, i.e. list of cards, by price so I can have the minimum price at the top, but I can’t find a solution to do so.

The plugin Lift Shifter KW might be a solution from the below article, but I cant get it to work on my scenario.
https://www.google.com/search?q=bubble+sort+repeating+group+by+related+field&rlz=1C1CHBF_en-GBAU912AU912&oq=bubble+sort+repeating+group+by+related+field&aqs=chrome..69i57j33i160l3.9416j1j4&sourceid=chrome&ie=UTF-8#fpstate=ive&vld=cid:dc933fa2,vid:AbXSLsegB-c

Hope you can help!!!

Interesting
Is there a reverse connection from Flights to Destinations? I mean, does the Flights thing contain a field that points to the Destination?

If so, you could create an RG of Prices, sorted by Price value, and then display the Destination from each cell’s Price’s Destination

Thanks for the idea @atomicfusion !
I briefly explored this path. I could restructure the database to do this, but I think I run into a problem when generating the repeating group, as the relationship between flights and destinations is a many to many relationship:i.e. flights is ultimately tied to an airport, but several destinations could be served from one airport.

So if I’m generating the repeating group from the flights data, would I be able to list a full list of unique destinations?

You could do nested RGs. The parent RG would be the Prices and the child RG within each cell of the parent will list the Destinations of that Price.

Alternatively I can also see this being done by an RG of Destinations : Grouped by (Price)
But that depends heavily on exactly how the data type is set up

Does this help at all?

I’ve run into a similar situation and resolved it by doing this: (callen.hedglen’s comment)

It’s a slightly different situation though so may not work. I’m too tired right now to think about any further ideas but I can think about it again tomorrow if you’re still stuck.