Hey @rico.trevisan, yeah List Shifter’s SORT action lets you sort one list (the list held in List Shifter’s Original List) by some other arbitrary list (the “Sort By List”). As long as you can construct the Sort By list in such a way that the item at each index corresponds to the item at that same index in the Original List, this will work.
So, in your case you have a list of Teams:
- Team 1
- Team 2
- Team 3
And then you have an expression (or have constructed, using Process List for example) a corresponding list of Maturity scores (where I’ve also supposed a value) like so:
- Maturity Score associated with Team 1 (25)
- Maturity Score associated with Team 2 (100)
- Maturity Score associated Team 3 (50)
When you execute that SORT action (sorting as number, descending), List Shifter’s Shifted List would contain:
- Team 2
- Team 3
- Team 1
Now, one weakness of the SORT action in List Shifter is that the sorted “Sort By” list is not published. This would have been handy in some cases, but I was tired of adding new outputs to List Shifter. Typically this isn’t an issue, as often SORT is used just for visually organizing a list in a Repeating Group (as you are doing) and typically the “sort by” list values will be visualized there as the result of some scalar expression within the cell.
In my example, the sorted Maturity values would be [100, 50, 25]. And if you needed that list you’d just take whatever expression you used for the Sort By list and do :sorted (by value descending) on it.
(Aside: There’s a similar action in Floppy - Count Fields/Sort - that can also do the same thing although the sort type is strictly numeric, but it does publish the sorted list of numbers.)
Internally how this works is we create an array of objects where each object is like:
{ original_list_value: Team 1, sort_by_value: 25 }
And then we sort that array of objects by the value parameter and then extract the original_list_values, which are now sorted and those are published to List Shifter’s Shifted List.
Does this help?
The tricky part oftentimes is the construction of that “Sort By” list which you might need to construct using a PROCESS List action (and possibly a second list shifter) and its associated “SET Process FIELD of Interest” action. For an example (not exactly parallel to what you are doing, but that is constructing a list of counts of some associated thing), see:
(and then there’s a bunch of intervening stuff where I create the scenario, but then the punchline is in the following reply)
And then here:
The type of scenario described above is quite common, which is why I created the “Count Fields/Sort” action in Floppy (which makes it super easy to get a list of counts and then sort by them). However, in your case you might need to iterate over your Teams and Assessments lists to match each team with its associated Assessment’s Maturity score (though perhaps there is a native Bubble expression that gives you that).