We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Search by text instead of value

I saw documentations of AutoComplete component and it's weird when you type and search for an item 
it only searches by value. Typically we search for the text to obtain the value behind it.
for example data array is like :

    {Name:"Ali",Id :"1"},
    {Name:"Alice",Id :"2"},
    {Name:"John",Id :"13"},
    {Name:"Sarah",Id :"45"},
    {Name:"Payam",Id :"12"},

Normal behaviour is when we type "li"  the result should be (Ali, Alice) and selecting "Ali" should set the "1" as the value of  text input or whatever is.

Is it possible to have different text and value  and could be search through the text in AutoComplete component?

1 Reply

PO Prince Oliver Syncfusion Team April 29, 2019 05:45 AM UTC

Hello Ali, 

Greetings from Syncfusion support. 

The AutoComplete control is intended to work with value property alone by default. The filtering, sorting operation are executed based on the value field. If you require to use text field, then it can be customized using filtering event. you can learn more about it here: https://ej2.syncfusion.com/react/documentation/auto-complete/filtering/?no-cache=1  

You need to customize the query in the filtering event to filter based on the Text field. Kindly refer to the following code. 

private onFiltering(e: FilteringEventArgs) { 
    let query: Query = new Query(); 
    //frame the query based on search string with filter type. 
    query = (e.text !== '') ? query.where('Name', 'startswith', e.text, true) : query; 
    //pass the filter data source, filter query to updateData method. 
    e.updateData(this.dataSource, query); 

Also take moment to look at the following KB document for further details: https://www.syncfusion.com/kb/10158/why-autocomplete-does-not-filter-using-text-field 


Live Chat Icon For mobile
Up arrow icon