Passing Parameter in a query to search using WebApiAdaptor

Hi team,
I want to do a API search based on the Param text value entered in the Autocomplete using WebApiAdaptor instead of getting all the records and then filtering on the client side so that the API call faster(Even with large amounts of data) .Is it possible? custom adaptor cannot be used as it is getting all the records first and then filtering.
Thread Reference : 156759
https://localhost:5010/api/Customers/Search/HU  this is what API query should be on each type we type the text in Autocomplete and perform the search using the entered text as parameter but using WebApiAdaptor.

1 Reply 1 reply marked as answer

SN Sevvandhi Nagulan Syncfusion Team November 23, 2020 01:13 PM UTC

Hi Mounika, 
 
Greetings from Syncfusion support. 
 
Query 1: 
I want to do a API search based on the Param text value entered in the Autocomplete using WebApiAdaptor instead of getting all the records and then filtering on the client side so that the API call faster(Even with large amounts of data) .Is it possible? custom adaptor cannot be used as it is getting all the records first and then filtering. 
Response: 
We would like to inform you that we can display the result based on the typed text in the AutoComplete component in the server-side with web API adaptor. In the below attached sample, we have got the typed text value in the variable named as “filtervalue”. You can use it for the application needs at your end. 
 
<SfAutoComplete TValue="string" TItem="Orders" Placeholder="Select a Employee" AllowFiltering="true"> 
    <SfDataManager Url="api/Default" Adaptor="Adaptors.WebApiAdaptor" CrossDomain="true"> 
   </SfDataManager> 
    <AutoCompleteFieldSettings Value="CustomerID" Text="CustomerID" /> 
</SfAutoComplete> 
[HttpGet] 
        public async Task<object> Get(int? code) 
        { 
            if (order.Count == 0) 
            { 
                BindDataSource(); 
            } 
            var data = order.AsQueryable();             
            var queryString = Request.Query;   
            string filter = queryString["$filter"]; 
            string auto = queryString["$inlineCount"]; 
            if (filter != null) // to handle filter opertaion 
            { 
                var newfiltersplits = filter; 
                var filtersplits = newfiltersplits.Split('(' , ')', ' ', '\''); 
                var filterfield = filtersplits[4]; 
                var filtervalue = filtersplits[2]; 
 
                if (filtersplits.Length == 7) 
                { 
                    if (filtersplits[2] == "tolower") 
                    { 
                        filterfield = filter.Split('(', ')', '\'')[3]; 
                        filtervalue = filter.Split('(', ')', '\'')[5]; 
                    } 
                } 
                switch (filterfield) 
                { 
                    case "CustomerID": 
                        data = (from cust in data 
                                where cust.CustomerID.ToLower().StartsWith(filtervalue.ToString()) 
                                select cust); 
                        break; 
                } 
            } 
            if (queryString.Keys.Contains("$inlinecount")) 
            { 
                StringValues Skip; 
                StringValues Take; 
                int skip = (queryString.TryGetValue("$skip", out Skip)) ? Convert.ToInt32(Skip[0]) : 0; 
                int top = (queryString.TryGetValue("$top", out Take)) ? Convert.ToInt32(Take[0]) : data.Count(); 
                var count = data.Count(); 
                return new { Items = data.Skip(skip).Take(top), Count = count }; 
            } 
            else 
            { 
                return data; 
            } 
        } 
 
 
Please let us know if you need further assistance on this. 
 
Regards, 
Sevvandhi N 


Marked as answer
Loader.
Up arrow icon