I wanted to implement an ajax based autocomplete feature for my searchbox, and i came across, implementing autocomplete in my website.
Now what i wanted to know was that i attach a datasource to the control, but so far i have seen that the datasource requires a textbase schema, can’t i like it to a query, where it control calls the query and it returns the records on which the filter of the control must apply.
Hope my question is clear
How do you think you can link it to a query on client-side??
You can link it to an AJAX call to the server, which returns the option-list.
The control’s filter will do the rest filtering on that option-list.
The best practice would be, to fire an AJAX on page load, to a server function, which will query to the database (MySQL in your case) and fetch the options-list in json format. Assign the option-list to as an input for autocomplete. (Its obviously better than to fire a ajax-request everytime user starts to type-in the search box.)
If you use jquery it can be something like this.
I can provide you with example in libraries other than jquery, but i hope this can make you find your way.
Edit: No, your database needn’t to have sorted choices. It is your server function, that should be doing all the sorting. Use,
and your server function will get search term (keyword user types in search-box), as get request. Filter your database there, and this is the place where you can hook related words along with the results. Just make a list of everything you want to show as suggestion, and return in serialize json format and let autocomplete to take care of matching and sorting the data.