Hey All
I’m using the search bar on the Dawn theme to search pages, but the suggestions/results show in a random order. Does anyone know how to sort them alphabetically? Thanks in advance ![]()
LINK TO PREVIEW (We are working on an unpublish theme)
A user is experiencing random ordering of search results in the Dawn theme’s search bar when searching for pages. They need the suggestions to display alphabetically.
Proposed Solution:
en.default.json filelocaleCompare()The solution involves intercepting the search API response and applying a .sort() method to the results array before rendering. The user is working on an unpublished theme and has provided a preview link for reference.
Hey All
I’m using the search bar on the Dawn theme to search pages, but the suggestions/results show in a random order. Does anyone know how to sort them alphabetically? Thanks in advance ![]()
LINK TO PREVIEW (We are working on an unpublish theme)
Hello, @teoias
fetch('/search/suggest.json?q=' + query + '&resources[type]=product')
.then((response) => response.json())
.then((data) => {
let results = data.resources.results.products;
// Sort results alphabetically by title
results.sort((a, b) => a.title.localeCompare(b.title));
renderSearchResults(results); // Function to display sorted results
});
Thanks!