Sorting a repeating group with a dropdown menu option being a list

Hi,

the data type is Product and contains the field votes, which is a list of users (figure 1 below)

I would like the repeating group for Product to be filtered by a dropdown menu containing the 4 following options :

  • (no filter)
  • Created date (newest to oldest)
  • Created date (oldest to newest)
  • Number of votes (highest to lowest)

I can filter the repeating group for the first 3 options using the conditionals tab (figure 2).

To filter by Number of votes (highest to lowest), I understand I have to use
Sort by → Change which field and somehow pick Dynamic field name : Dropdown Product sort’s value (?? ) (figure 2)

I don’t understand how this is supposed to work since a count of unique users has to be performed within the field votes for each Product row before the sorting takes place. The field votes does not appear anywhere in the search.

Thanks for your help.

K.

figure 1:


figure 2:

To sort by number of votes you’ll need to have a number field on your product datatype to store the number of votes…

Just update that number every time a new vote is registered…

(By the way, I wouldn’t recommend using a list of users on the product datatype, so I’d suggest getting rid of that field, and using a separate datatype to store votes).

In terms of having a drop-down to determine how to sort the RG, my recommendation would be to create an option set, with your 4 sort options, each with a text attribute for the field name, and a yes/no attribute for descending…

Then just set your sort to the dropdown’s value… no need to use any conditional data sources or sorting…

@adamhholmes - One of the reasons I created a list of users on the product datatype for the votes field is to perform checks so that each user upvotes a product not more than one time.

  • Could you briefly outline what the fields of the “separate datatype to store votes” look like ?

  • From a DB performance point of view, will your DB tables structure suggestion be the most efficient way to sort and display say hundreds of products by number of votes for which thousands of users vote on ?

Thanks.

K.

The ‘Vote’ datatype will need, as a minimum, a field for ‘User’ (which will probably just be the Created By filed, but depending exactly on your use case may need to be an additional User filed), and a Product field (of type ‘Product’).

Of course it can also include any additional data you need to store about the specific vote.

  • From a DB performance point of view, will your DB tables structure suggestion be the most efficient way to sort and display say hundreds of products by number of votes for which thousands of users vote on ?

Yes, without question… the number of votes is irrelevant… it’s just a single Number field…

1 Like