Possible to sort an array of maps on multiple criteria?

webteam's Avatar

webteam

17 Feb, 2015 05:33 PM

Is it possible to sort an array of maps on multiple criteria?

For example could I sort the below by count & then title? I tried the addSortCriterion but that gave me an error.

#set ($menuItems= [])
#set ($tmp = $menuItems.add({"title" : "item1", "count" : 5, "url" : "http://www.google.com"}))
#set ($tmp = $menuItems.add({"title" : "item3", "count" : 3, "url" : "http://www.google.com"}))
#set ($tmp = $menuItems.add({"title" : "item4", "count" : 2, "url" : "http://www.google.com"}))
#set ($tmp = $menuItems.add({"title" : "item2", "count" : 3, "url" : "http://www.google.com"}))


#foreach ($item in $_SortTool.sort($menuItems, 'count:desc'))
<a href="$item.url">$item.title</a>
#end
  1. 1 Posted by Ryan Griffith on 17 Feb, 2015 07:29 PM

    Ryan Griffith's Avatar

    Hi,

    The Sort Tool can sort by multiple properties by supplying them as an array. For example:

    #foreach ($item in $_SortTool.sort($menuItems, ['count:desc', 'title:asc']))
    <a href="$item.url">$item.title</a>
    #end
    

    For information on this functionality can be found on this page.

    Please let me know if you have any questions.

    Thanks!

  2. 2 Posted by webteam on 17 Feb, 2015 07:52 PM

    webteam's Avatar

    Thank you!

  3. webteam closed this discussion on 17 Feb, 2015 07:53 PM.

Discussions are closed to public comments.
If you need help with Cascade CMS please start a new discussion.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

 

26 Aug, 2016 01:19 PM
25 Aug, 2016 03:02 PM
25 Aug, 2016 12:50 PM
24 Aug, 2016 08:43 PM
24 Aug, 2016 07:20 PM
21 Aug, 2016 01:20 PM