User 'sort by' field a then field b


(Emily) #1

Matrix Version: 5.2.4

Hi all,

I am wondering if there is a way using in-built Matrix keywords/functions (i.e. not having to write the javascript myself) to allow the user to sort results of an Asset Listing / Search Page by one dimension and then by a secondary dimension.

I know of the sort_by keyword, which allows the user to select how to sort the results. But how can I essentially get it to have two of them, with the pattern of sort by 1 and then by 2?

Or would this have to be done via Javascript? (I know it wouldn’t be complex JS, but I have been asked if we can do this wholly with Matrix abilities).

Any thoughts would be appreciated. :slight_smile:
Emily.


(Peter McLeod) #2

Hi

Have you looked into using custom grouping options in your listings. Should allow you to sort the groups (in the Asset Grouping screen) and the indiviual assets (in the Asset Sorting screen) .

Not sure if it will get you the exact resutls you need, but probably good to try if you haven’t already.

Thanks
Peter


(Emily) #3

Hi Peter,

I have used Asset Grouping before, an actually am using it the way you mention in a different page.

The problem is that I want the user to be able to choose which dimensions to sort by. The way I see it, Custom Groupings sort BEFORE the content is served to the user – and the user is unable to modify the sorting of Custom Groupings.

In contrast, the Asset Sorting screen is the default options, and the options for Sort By (which is the select box that allows users to change how the content is sorted).

Essentially I want the functionality of two Sort By boxes, but with the system knowing to “first sort according to [Sort By #1], then sort by [Sort By #2] if selected.”

I hope that makes sense.

Thank you for your ideas input though! :slight_smile:

Emily.


(Peter McLeod) #4

Hi Emily

There might be a way to dynamically pass in the grouping requirements (in combination with the sort select inputs), but not sure if this is possible.

Another option could be to use a REST JS asset as a controller for your search or listing asset. Eg:

  • Your search/sorting parameters get passed to the REST JS asset.
  • It gets the data from the search asset or asset listing (as data).
  • You apply your sort logic using JS to the respone data and output your html.

This would still technically meet your requirements as its all matrix capabilities and done server side.

Thanks
Peter