This project has moved and is read-only. For the latest updates, please go here.

Autocomplete with unique values for a large list

Mar 11, 2015 at 2:39 PM
Edited Mar 11, 2015 at 2:39 PM

I want to attach autocomplete funciton to one text field. I tried the SPServices autocomplete but the list has over 2000 list items and it will grow to 50000 and this autocomplete turned out to be too slow - typing is very hard. So I wanted to add a delay function on keyup so that the search would start when users pauses for a while and not for every key press. But I had no success there. So I tried the jquery autocomplete function that has the delay option but it returns all items, not just the distinc values. I know it is possbile to solve this with an array but this approach is too slow. So I found the ajax option that is mentioned here but I don't know how to grab the returned data. I tried to get values of the select with $('#IDofselect option').each(function() ... but it looks like that the returned data is just a string and this returns nothing.
    url: weburl+'/_layouts/filter.aspx?ListId='+escape(listId)+'&FieldInternalName='+internalName+'&ViewId='+escape(viewId)+'&FilterOnly=1&Filter=1',
    success: function(data) {
        //Do Something
Does anyone have a solution for autocomplete for a large list?

Best regards, Sandra
Mar 11, 2015 at 2:52 PM

I'd suggest using jQueryUI's autocomplete instead of the one in SPServices. In either function, setting the minimum number of character the user has to type cuts down on the traffic significantly and can make the response more tolerable. Keep in mind that depending on the version of SharePoint you're running, you can't pull back more than 5000 items. The UX there would be horrible anyway, so setting the number of characters to 2 or 3 usually does the trick.

Mar 11, 2015 at 3:46 PM
Marc, thank you for your answer. I already had the minLenght set to 3. So for now I will use the jqueryUI's autocomplete with an array to remove duplicates. But I'm still affraid that in time when the list will grow, this won't be a good solution. Basically this list is a list of guest entries into our firm. And some people come and go three times per day. So per year there can be 500 items just for one person. So I was thinking that maybe it wouldn't be bad to create a second list that would contain every guest's name - when saving a guest entry there would be a check if this person already exists in the guest lists. If its a new guest, an item would be created in the guest lists. And then the autocomplete would be connected to this smaller guets list and not the entries list.

Best regards, Sandra
Mar 11, 2015 at 4:13 PM
Ah, so it sounds like your data source has lots of duplicates. You can either handle that on the server side by using a lookup column or something or you'll have to push into an array on the client side. Odds are you're going to end up running into the 5000 item limit with the duplicates.