Hello,
I have a repeating group listing all users. I want that the list is sorted by default by the user’s subscription plan - premium first, free after. For this, I created a data field subscription plan for a user and an option set subscription plan with both options free and premium. Can someone have a look and tell me how to fix the sorting settings? Thanks in advance!
In Bubble (annoyingly) you can’t sort a list by a field on related field in Bubble - you can only sort by fields on the Datatype itself.
So, the simplest, most performant, and most Bubble way is to add an additional field on the User datatype, of whatever ‘type’ it is you want to sort by (in your case, presumably ‘text’) and set it to the name of the Subscription.
Then you can sort by that - and the sorting is done in the database query itself, so it’s very efficient.
Of course, you need to ensure the subscription field and the text subscription name field are always kept in sync.
An alternative method is to do the sorting on the client-side using some simple javascript.
There are various ways to to that - but I’d suggest using an Expression Element that outputs a list of the same type, and simply creating an object array containing each User’s Unique ID and the subscription name.
Then you can sort that array by subscription name, and output it - and then use that list for your RG datasource.
Obviously, this means the sorting is done client-side, so the full dataset has to be loaded to the page first in order to sort it.
Fine for small lists - but not suitable for larger data sets.
This is great to know! Thank you adamhholmes!