Instantsearch sortBy error

Hi, I am getting the below error using the sortBy widget in instantsearch. I am using plain JavaScript. I would appreciate any feedback. Thanks!

Error:
Uncaught TypeError: instantsearch.widgets.sortBy is not a function

Code snippet:
search.addWidgets(
instantsearch.widgets.sortBy({
container: ‘#sort-by-container’,
items: [
{ value: ‘stage-products’, label: ‘Most relevant’ },
{ label: ‘Price (asc)’, value: ‘instant_search_price_asc’ },
{ value: ‘products_price_desc’, label: ‘Price (desc)’ }
]
})
);

CDN:
https://cdn.jsdelivr.net/npm/instantsearch.js@2.3.3/dist/instantsearch.min.js

The widget was not called sortBy, but sortBySelector in v2 which you are using

The docs for v2 are here: https://community.algolia.com/instantsearch.js/v2/widgets/sortBySelector.html

Here’s your code fixed: : https://codesandbox.io/s/modern-https-76x1e?file=/src/app.js:252-551

PS: you probably want to update to InstantSearch v4 for all the latest features, a migration guide is here: https://www.algolia.com/doc/guides/building-search-ui/upgrade-guides/js/#upgrade-from-v2-to-v3

Thanks for the solution in v2! I ended up migrating the code to v4.

1 Like