1

I'm using a SharePoint 2013 site, in which one of the page has a search bar(which has 'autocomplete' feature). The values from the SharePoint list needs to be populated as soon as a character is typed in the drop down. It worked fine in the beginning, but now the issue arises when a new item is added in the SharePoint list, and when we type for that in the search bar it is not getting auto-populated in the search bar.

Any help here, please!

1 Answer 1

0

Verify the below:

Go to the list setting page -> Click on the Advanced Settings

Under the search section :

Allow items from this list to appear in search results? Yes

And from the Reindex List section, click on the Reindex List button

Then run the Full Crawl from Central Admin.

Now search should work.

Reference screenshot:

Why SharePoint list item does not appear in the search?

Auto Complete in SharePoint search using jquery:

1: // Parse an item and create an title/value dictionary with all the properties available

   2: function getFields(results) {

   3:     r = {};

   4:     for(var i = 0; i<results.length; i++) {

   5:         if(results[i] != undefined && results[i].Key != undefined) {

   6:             r[results[i].Key] = results[i].Value;

   7:         }

   8:     }

   9:     return r;

  10: }

  11:  

  12: $(document).ready(function() {

  13:     

  14:     var autocomplete = $( "#restSearch" ).autocomplete({

  15:         minLength: 3,

  16:         source: function( request, response ) {

  17:             $.ajax({

  18:                 beforeSend: function (request)

  19:                 {

  20:                     request.setRequestHeader("Accept", "application/json;odata=verbose;charset=utf-8");

  21:                 },

  22:                 url: "/_api/search/query?querytext='" + request.term + "*'",

  23:                 dataType: "json",

  24:                 success: function( data ) {

  25:                     response( $.map( data.d.query.PrimaryQueryResult.RelevantResults.Table.Rows.results, function( item ) {

  26:                         return {

  27:                             fields: getFields(item.Cells.results)

  28:                         }

  29:                     }));

  30:                 },

  31:                 error: function( data ) {

  32:                     alert('search error');

  33:                 }

  34:             });

  35:         },

  36:         // Run this when the item is in focused (not selected)

  37:         focus: function( event, ui ) {

  38:             //$( "#restSearch" ).val(ui.item.value );

  39:             return false;

  40:         },

  41:         // Run this when the item is selected

  42:         select: function( event, ui ) {

  43:             location.href = ui.item.fields.Path;

  44:         },

  45:         appendTo: $('#menu-container')

  46:     }).data( "uiAutocomplete" )._renderItem = function( ul, item ) {

  47:         // format the documents using the OOTB SharePoint icons

  48:         img = "ic" + item.fields.FileType + ".png";

  49:         if(item.fields.FileType == "html") {

  50:             img = "html16.png";

  51:         }

  52:         return $("<li>").append('<a><img style="margin-right:3px;top:3px;" src="/_layouts/15/images/'+ img +'">' + item.fields.Title + '</a>' )

  53:             .appendTo( ul );

  54:     };

  55: });

Source:

Auto Complete in SharePoint search using jquery

1
  • Thanks for the response. The code is working fine, I re-indexed the list. My concern is auto-complete is not working only for few items(probably newly added items in the list)
    – Monika
    Apr 20, 2020 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.