How do you query an API as the user types

Hi

Is it possible to use the Blazor AutoComplete component to query an API every time the user enters a letter?

For example the following API will return a list of (up to 10) stocks that contain the letters "coi" in their names:

GET:  https://api.nasdaq.com/api/autocomplete/slookup/10?search=coi

 Ideally i would want the API queried after every letter that the user enters in order to narrow down the selection.

You can see an autocomplete textbox here that behaves in that way: https://www.nasdaq.com/market-activity/stocks/screener

Any idea how to achieve this using the autocomplete component?


3 Replies 1 reply marked as answer

PM Ponmani Murugaiyan Syncfusion Team February 21, 2022 11:15 AM UTC

Hi James, 

The AutoComplete supports retrieval of data from remote data services with the help of DataManager component. By default, in AutoComplete component filtering property is enabled, so if you type any character the request will send to server and fetch the matched item and the results will be shown in the popup. 


For more information, please refer the below demo and documentation. 



The filter queries can be customized using the custom filtering option on each time the character typed, filtering event will be triggered. 

private async Task OnFilter(FilteringEventArgs args) 
{ 
    args.PreventDefaultAction = true; 
    var query = new Query().Where(new WhereFilter() { Field = "Name", Operator = "contains", value = args.Text, IgnoreCase = true }); 
    query = !string.IsNullOrEmpty(args.Text) ? query : new Query(); 
    await autoObj.FilterAsync(Country, query); 
} 


Regards, 
Ponmani M 


Marked as answer

JA James February 26, 2022 10:05 PM UTC

Thanks for your assistance Ponmani.

James



PM Ponmani Murugaiyan Syncfusion Team February 28, 2022 03:22 AM UTC

Hi James 

Welcome, if you need further assistance, please revert us we will assist you. 

Regards, 
Ponmani M 


Loader.
Up arrow icon