Gravatar for nbordeleau@coveo.com

Question by Nicolas, Apr 24, 2014 12:05 PM

How can I set the default sort order using the Javascript Search Framework

I've added two sort components to my search page, one for Date and the other for Relevancy. How can I specify which one to use by default when my search page load?

1 Reply
Gravatar for olamothe@coveo.com

Answer by olamothe, Apr 24, 2014 1:54 PM

You can specify a defaut sort option on each Tab component. If you specify your desired sort option on the default tab (that is, the first one that appears in your HTML markup), then that sort will be selected by default when your page load.

Or, you can also load your page with the parameter #sort=date%20descending, for example

Documentation for Tab component

Gravatar for nbordeleau@coveo.com

Comment by Nicolas, Apr 24, 2014 2:38 PM

What if i'm not using the Tab component?

Gravatar for nbordeleau@coveo.com

Comment by Nicolas, Apr 24, 2014 2:53 PM

Then, how to do this without url parameters? I want the page to load with a predefined sort order without having to change all the links in my site.

Gravatar for olamothe@coveo.com

Comment by olamothe, Apr 24, 2014 3:17 PM

The url parameter is just a representation of the internal state.

You can set it programatically like this:

$('#search').coveo('init');
$('#search').coveo('state', 'sort', 'date ascending');
$('#search').coveo('executeQuery');

https://developers.coveo.com/display/JsSearch/State

Gravatar for apare@coveo.com

Comment by Alexandre Paré, Apr 24, 2014 3:26 PM

nice this is magic

Ask a question