jQuery-Autocomplete
jQuery-Autocomplete copied to clipboard
Sort result list for local data
I'm using a local list for suggestions. However it seems to be not possible to have a custom sorting for this list.
formElement.ref.autocomplete({
lookup: data,
autoSelectFirst: true,
minChars: 0,
appendTo: formElement.ref.parent(),
orientation: 'bottom',
lookupFilter: () => true,
});
What I want to achieve is to display the mached results on top, and UNION the unmatched suggestions below.
I tried using transformResult and onSearchComplete, but none seems to have an effect on the suggestions list and transformResult not even triggered.
As far as I understood, this kind of function should usually work:
transformResult: (response, originalQuery) => {
const matches = [];
const unMatches = [];
for (const element of response) {
if (element.toLowerCase().match(originalQuery.toLowerCase())) {
matches.push(element)
} else {
unMatches.push(element);
}
}
return matches.concat(unMatches);
}