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
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Search by text instead of value

Thread ID:





144264 Apr 27,2019 09:18 AM UTC Apr 29,2019 05:45 AM UTC React - EJ 2 1
Tags: AutoComplete
Ali Rahighi
Asked On April 27, 2019 09:18 AM UTC

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?

Prince Oliver [Syncfusion]
Replied On 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 



This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon