I’m having trouble figuring out how to sort lists by reference fields.
Two scenarios where I’m having trouble:
Picture something similar to AllTrails, we have Activities (like a hike for example). The activities are linked to different collections:
Reviews: one activity to many reviews
Difficulty: many activities to one difficulty
I want to be able to sort the list by difficulty. I assigned numbers to the difficulties (to be able to create an ascending/descending order from Easy, Regular, Hard) but I am not able to sort by the reference field.
I want to be able to sort from best review to worst. This requires calculating the average review score from multiple user reviews (created using the star review component). Again, can’t sort via the reference field with the added dimension that this would need to be an average of all the reviews that reference this specific activity.
Is this even possible? // Has anyone found a workaround for a similar build?
Not possible at the moment, unfortunately. But this would be great! In the meantime you can create a number property on the Activities collection and update that when creating a new activity and sort the list with that property!
Not possible too and needed a number property on the Activities collection and update that every-time when creating reviews with current activity > reviews > rating > average and sort the list with that property!
To have a sorting field, it needs to be inside the collection, you can have additional calculated fields to do that, you can perform synchronized updates every time the relational collections is updated or just before needing to show the list.
About function, it may not like the one in spreadsheet but you can check custom formula and put them in input text field at initial and have couple of them put together or combine with logged in user> numbers field.
By having both number parameters inside of the activity collection, you’re able to use them as sorting filters, just like @Yongki & @dilon_perera stated.
Here’s a more detailed explanation:
Add a number parameter to your activities and call it “Difficulty #”. Then you can use that as a sorting filter for the activity. 1 - easy, 2 - regular, 3 - hard. You can sort high to low for hard-to-easy or low-to-high for easy-to-hard. Also add the difficulty number to the difficulties collection. That way you can use a dropdown or option that says where current activity difficulty # is equal to Difficulties collection number.
Add another number parameter to your activities and call it “Average Rating”. Whenever a user leaves a review for an activity, add another action to update the activity and set the value to “current activity > reviews > rating > average”