My suggestion list is blank

I am trying to get AutoComplete to filter match all three columns of my data.

I had the simple match working, but only on the initial column. My data has three properties: Customer Id, Customer Name and ZipCode. I would like to have it match on any of the three columns.


In the xaml I have a single line:


I call LoadCustomerData in the code-behind constructor.


private async void LoadCustomerData()

{

customerAutoComplete.DataSource = await GetCustomerCodes();

customerAutoComplete.DisplayMemberPath = "CUSTNMBR";

customerAutoComplete.SelectedValuePath = "CUSTNMBR";

customerAutoComplete.SuggestionMode = SuggestionMode.Custom;

customerAutoComplete.Filter = FilterCustomers;

customerAutoComplete.AutoCompleteMode = AutoCompleteMode.Suggest;

customerAutoComplete.Watermark = "Zip Code, Customer ID, or Customer Name";

customerAutoComplete.MinimumPrefixCharacters = 3;

}


My filter function:

private bool FilterCustomers(string search, object customer)

{

var text = customerAutoComplete.Text;


if (customer != null)

{

var myCustomer = (OrganizationSearchDto)customer;

if (myCustomer.CustName.Contains(text) || myCustomer.CustNmbr.Contains(text) ||

myCustomer.Zip.Contains(text))

{

return true;

}

}


return false;

}


I am not using a ViewModel like in the documentation examples. I hope that is not my problem. Also, in the custom filter examples we set AutoCompleteSource and I am still using DataSource.


Baring those two issues, why is my AutoComplete dropdown blank or empty?


2 Replies 1 reply marked as answer

RA Randy December 6, 2021 08:43 PM UTC

I found my error:

  1.  DisplayMemberPath and SelectedValuePath property names are case sensitive.
  2. My filter method was also case sensitive.



Marked as answer

SS Suganya Sethuraman Syncfusion Team December 7, 2021 08:06 AM UTC

Hi Randy,

Greetings from Syncfusion.

We have analyzed the reported query. We have achieved the requirement by using the following code snippet,

Code snippet
 
        public bool ContainingSpaceFilter(string search, object item) 
        { 
            if (item != null) 
            { 
                var myCustomer = item as Employee; 
 
                if (myCustomer.Name.ToUpper().Contains(search.ToUpper()) || myCustomer.ID.Contains(search) || 
           myCustomer.ZipCode.Contains(search)) 
                { 
                    return true; 
                } 
            } 
 
            return false; 
        } 

Please refer the sample for your reference,

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/AutoCompleteSample1697276246

Please check and let us know if you have any concerns.

Regards,
Suganya Sethuraman.
 


Loader.
Up arrow icon