5

I'm using jQuery UI Autocomplete.

Is there a way to override its default search algorithm?

The changes I want to make are:

  • Prioritize words that start with the search term at the top of the suggested results.
  • Return a maximum of 5 results (instead of the default behavior, which is to return all matching results, potentially creating a really tall dropdown box).

1 Answer 1

2

Normally, it all should be done in back-end. Your server-side script defines in what order and how many results will be returned.

Alternatively (if back-end is not under your control), you can specify function as source attribute. In this function you can query back-end and process results in whatever way your want. E.g., here's an example
http://jqueryui.com/demos/autocomplete/#multiple-remote

Sign up to request clarification or add additional context in comments.

2 Comments

The data is on the front end already, so I don't need to do anything with the back end. I just need to change the way the results are ordered.
@Emmett Ok, I misunderstood it. According to the docs, your only option now is using function as source and doing comparisons/ordering manually. You can also use another (possibly more popular) autocomplete plugin which has option to limit number of results and many more: docs.jquery.com/Plugins/Autocomplete

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.