0

I'm trying to figure out how to go about defining a sort when building a query for an item query (this is driving the results of an SXA page list). When in the query builder, I see that sort is an option, but it's unclear after typing sort: what the builder is expecting next. A GUID of a field to sort? Also, I am not finding any kind of documentation talking about if you are able to define ascending / descending in the sort or really anything about it other than it's existence. If anyone has some background on this, I would really appreciate it.

5

This is Sitecore specific, not SXA. When you build a query you need to specify a field that will be used for sorting. Then when you click on the sort icon you can change it to descending or ascending.

Here is a quick demo

enter image description here

I just build a query to search for items of template Blog Post and sort them using custom field: Published (DateTime)

The raw values of my queries are:

  • +template:{efa62406-cfd7-43c6-b702-3f53dfb1cee3};sort:published
  • +template:{efa62406-cfd7-43c6-b702-3f53dfb1cee3};sort:published[desc]

I am not sure where you put your query (directly into a data source field or on item) but recommended location is ItemQuery item (/sitecore/content/Tenant/Site/Settings/Item Queries/YOURITEM)

I published a few days ago a blog post which touches this topic. You could learn how to do it by reading Item Queries section.

You will also find step by step instruction how to configure sorting for Search Results in case you switch from Page List.

6
  • This is great detail. I think part of my confusion is that my Sitecore site is actually not giving me predictive options based on what I am typing. I'd be curious to see what the sort portion of the query you put together looks like. I assume it's +template:{guid};+sort{?} Also, are you aware of being able to define if it will sort ascending or descending based on the field you enter? – David Hake Dec 19 '17 at 21:54
  • @DavidHake answer updated with raw values of my crafted queries. Yes, I presented two cases on the gif (descending/ascending) – Alan Płócieniak Dec 19 '17 at 21:58
  • Thank you! One last question, are you aware of being able to sort on any custom fields, or is it limited to fields on a standard Sitecore item? – David Hake Dec 19 '17 at 22:39
  • I am not sure what do you mean. Custom fields from template or custom field types? If the first, then the answer is yes. I used Published field which comes from my custom template and it is not a default Sitecore field, I've created templates from the scratch. Default types like date, integer have proper comparer already, I've never created a comparer for custom field types and I don't know for now how to do it. Btw. do you really need that? – Alan Płócieniak Dec 19 '17 at 22:47
  • Yeah, I meant a custom field in a template I've created. If I define a template in my query I am searching for, should the sort make all the fields available in that template for me to sort against? – David Hake Dec 20 '17 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.