Dynamic sorting on search results page
-
13-01-2021 - |
Question
I've created a search page that has a couple of refiners. I've also created a display template that shows search results on a table-like format. Each search result row shows the following three properties: Title, Section, Date.
Is there anyway way I can implement a dynamic order by on the results by Section or Date (i.e. clicking on the Section or Date header would change sort order)? I already am using one result source that just has the default order by.
Solution
Each property that you want to be Sortable must be a Managed Property that is Sortable. In SPO you need to map your property to a Refinable(TYPE)## managed property since they are already flagged as sortable. Then in your search results web part add those properties as Sortable Properties in the UI. This will give you a drop down for each property you specify.
I show how to do this near the end of this video. Build an Employee Directory in SharePoint Online and SharePoint