Skip to end of metadata
Go to start of metadata
In this topic:

 

This component allows to add an expression to the current query to specify how search results must be sorted. In other words, it's the component that handles the Sort By feature.

Options

sortCriteria

sortCriteria: "relevancy"
<div data-sort-criteria="relevancy" ></div>

This option specifies the criteria on which the component should sort the results. The available criteria are: 

  • relevancy
  • date
  • qre
  • @fieldname (replace fieldname by an actual field name, for example @syssize)

     

    Icon

    Before using a field ensure it is sortable (for Coveo Cloud see Creating and Managing Fields for a Source).

You can also specify the direction (ascending or descending) separated by a space inside the criteria for relevant fields (date and @fieldname) like so:

  • data-sort-criteria="date ascending"
  • date-sort-criteria="@syssize descending"

You can specify multiple sort toggles using two criteria separated by commas, like so:

  • data-sort-criteria="date ascending,date descending"
  • data-sort-criteria="@syssize ascending,@syssize descending"

 

Assertions on initialization

Icon

The Sort component will always check (and fail to instantiate) if:

  • The criteria is not of the type "relevancy", "date", "qre", "@field"
  • The direction IS NOT specified for "date" and "@field"
  • The direction IS specified when it makes no sense: "relevancy", "qre"

caption

caption: "caption"
<div data-caption="caption"
>

Specifies the caption that will be displayed by the component.

Methods

getCurrentCriteria

$('#mySort').coveo('getSort')

Gets the current sort criteria value.

getField

$('#mySort').coveo('getDirection')

Gets the current direction for the sort component (ascending/descending).

select

$('#mySort').coveo('select', direction?: string)

Selects the sort component.

Direction: Optional. Which direction to choose for the component. Only useful for a sort component with a data-sort-criteria containing multiple direction choices.

Sample

  • No labels