Forum Academy Marketplace Showcase Pricing Features

Sort list by order added? (for recently viewed products)

Hi! I’m figuring out how to make a repeating group of recently viewed items → thereby the most recently viewed item has to show first.

The repeating group data source is “Current user’s Recently Viewed Products”
containing the “Product” data type. Although since this is a list, I cannot seem to sort it by order added and modified date refers to the product’s modified date instead of the date it was added to “Current users’s Recently Viewed products”

Is there a method I can workaround this problem?
Many thanks!

The list should keep its order and the repeating group will display elements in this order. So add elements to the beginning of the (or display the list in reverse).

Hi! Thanks for the response! But bubble always seem to display the first item (oldest item) in the list first. Is there anyway we could sort it the way around as you suggested? e.g adding items to beginning of the list or to display the list in reverse?

Thanks for the help so far!

hi @phetxdphet !

there are a few ways to do this based on your app’s behavior:

  1. if you would like it to be session based, meaning that recently viewed are only saved as long as the session is not expired. In that case, the solution can be achieved using custom states and @keith 's awesome plugin List Shifter Karma-Ware Plugin | Bubble
  1. Keep your data structure as it is (saved to each user) and use the plugin to reverse the list order.

  2. if, on the other hand you would like to keep your recently viewed records (and I believe you do since you are saving them to the user datatype) and do not wish to use plugins the easiest way to do this is to create a new datatype called user recently viewed, where each record represents a user and a viewed product. In this case, created date reflects the actual date this product was viewed by the current user and you can sort the list in descending order.

an important point to keep in mind, though: You will probably need to set a limit to each user’s recently viewed items count to make sure the app doesn’t become slow when you scale. Many users and many products will do that.

How to do it:

  1. Set the RG’s data type as “users recently viewed” and source is “users recently viewed” filtered by user= current user.

when a product is viewed:

  1. Check whether this user has viewed it before or not. If yes, delete the record.

    I am using the repeating group’s list to minimize number of records to be searched every time an item is clicked since the RG already has only this users’ viewed products, not the whole DB.

  2. Create a new users’s recently viewed record (regardless of the previous step’s result) that connects this user with the product.

see it in action (excuse the ugly design again :sweat_smile: )

1 Like

Thanks for such a detailed response! The plugin worked wonders and it was easy & simple to implement. Also thanks for the the detailed workaround as well!

Hope you have a blessed day!

1 Like