Remote autocomplete filtering
The autocomplete filtering capabilities aren't just limited to the default implementation, which searches for objects in array sources. We can specify a custom source()
function that will retrieve only data the user is looking for. This is the ideal approach if you're looking to use autocomplete on a data source with thousands of items. Otherwise, filtering gets too demanding on the browser—the large data set to download, followed by a large array search with each keystroke.
How to do it...
We'll use the GitHub API as the data source for our autocomplete widget. This is a good example since it is much too large to use in the browser memory.
$( function() { $( "#autocomplete" ).autocomplete({ minLength: 3, source: function( request, response ) { $.ajax({ url: "https://api.github.com/legacy/repos/search/:" + request.term, dataType: "jsonp", success: function( resp ) { ...