I want to be able to display first item of a list that is sorted

I want to sort a list by a total count from a list of numbers and display only the first item. Is that possible? Because the option is not appearing in the sorting selection field.

This sounds like something that is possible but you need to be more clear in order to receive help.

Sorry, it’s hard for me to explain as I am new to Bubble, but I am not seeing the list of numbers that I want to sort the thing by in this dropdown.

I was able to get this done by using the backend workflow to check for every time a value is updated and then the total sum of the values is written into a number, not a list of numbers. Is this a good practice, though?

1 Like

The logic of sorting by a list doesn’t make sense. You have 4 objects, each have a list of numbers:

  • Object 1-- 2, 6, 5
  • Object 2-- 3, 23, 9
  • Object 3-- 4, 0, 41
  • Object 4-- 9, 10, 2

You can’t tell Bubble to sort these based on this list of numbers, it needs to be stored as a single number in order to appear as an option in the “sort by” field.

In terms of your solution, that works, but it will trigger that workflow everytime the ANY field from the object is updated, which is probably redundant (although if this is the only field in your data type then it’s fine).

I’d say you should just create a new field – let’s call it numSum-- and whenever you add a number to the list, you set the numSum to “This item’s numSum + new number”. If the list of numbers gets set as a one time occurance, then you could just do “List of numbers :sum”.

Hard to say what best practice would be without knowing all the context. if you’re really interested in learning all about best practices in Bubble, check out this book: The Ultimate Guide to Bubble Performance - Amlie Solutions

Okay, how would I go about doing that?

Currently, I thought I had a simple thing. A list of posts and each has a like. And I want to sort them by the amount of likes.

I have created a new number field - however I am not sure how to write the total amount of likes (which is a list of numbers and a list of users) in it.

Sorry if I seem lost… I kind of am.

Many thanks, though, I feel I am a bit closer to a solution :slight_smile:

the post datatype will a have a user data field which will be a list, so anytime a user likes a post: the user is being added to the list of users of liked the post as long as they were not in the list before and vice versa
Consequently, the number of likes will just be the “post’s likes count”, if you want to sort a list of posts by number of likes, you can add a number of field which stores the current number of likes(so anytime a user likes/unlikes a post, you are just getting the figure by “post likes count” -1 / posts likes count +1)

The clearer you make the question, the clearer the answers will be made – just a note for the future.

If I understand you correctly, and I might not, try :sorted by (sort order):grouped by (something)'s count:first item

Yes, have a database trigger that watches for changes on the list of numbers for a Thing, and store the total on that number field.

This topic was automatically closed after 70 days. New replies are no longer allowed.