views:

69

answers:

1

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).
A: 

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

Nikita Rybak
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
@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: http://docs.jquery.com/Plugins/Autocomplete
Nikita Rybak