Changing Default sortBy Value in sortBy Widget

TLDR Sachyya wants to change the default sortBy value in a widget. Jason explains that modifying the first element in the 'items' array determines the default sortBy value.

Photo of Sachyya
Thu, 18 May 2023 10:12:56 UTC

How can we change the default sorby selected value in the sortBy widget. I know that whichever value is passed as empty request( i.e. default text_match) ordering will be selected. For example in this site: Relevant Paragraph is the default one. I want to make Relevant Date the default one. How do I go about that?

Photo of Jason
Thu, 18 May 2023 15:31:37 UTC

In this code: ```search.addWidgets([ sortBy({ container: "#sort-by", items: [ { label: "Default", value: "products" }, { label: "Price (asc)", value: "products/sort/price:asc" }, { label: "Price (desc)", value: "products/sort/price:desc" }, ], }), ]);``` I think the first email of the `items` array determines which is the default sort by used by instantsearch