Send 'search=...' instead of '$search=...' to a dotnet 3.1 WebAPI

Hi,

Currently, the official implementation of OData for WebAPI does not support the $search keyword. I've already filed an issue for that at:


Meanwhile, I'd like to use the search functionality of the Grid as described here:


I can successfully handle/search in the API once it receives a 'search' parameter. Unfortunately, I can't find a way to send 'search=...' instead of '$search=..." from the SfGrid.

Could you please let me know if this is possible?

Regards
Eugene

1 Reply 1 reply marked as answer

RN Rahul Narayanasamy Syncfusion Team August 19, 2020 12:09 PM UTC

Hi Eugene, 

Greetings from Syncfusion. 
 
Query: Odata $search - Send 'search=...' instead of '$search=...' 
 
We have validated your query and yes, ODataV4 (.Net Core) does not support $search parameters. We have analyzed your query to implement search using $filter at our end. Since it is a known request, we have considered that requirement as an usability feature and logged the report for the same “Provide support for search operations in ODataV4 adaptor using $filter request”. Fix for the improvement will be included in our 2020 Volume 3 release. 
  
You can now track the current status of your request, review the proposed resolution timeline, and contact us for any further inquiries through this link.     
  
  
Till then as an alternative we suggest you to achieve your requirement using below solution. We have performed the search operation using $search parameter using ODataQueryOptions and manually creating a Where filter to searching the text. Refer the below code example.   
  
public PageResult<Book> Get(ODataQueryOptions opts)  
       {  
           var results = _db.Books.AsQueryable();  
           var count = results.Count();  
           if (opts.OrderBy != null)  
               results = opts.OrderBy.ApplyTo(results);  
           if (opts.Filter != null)  
           {  
               results = opts.Filter.ApplyTo(results, new ODataQuerySettings()).Cast<Book>();  
           }  
           var queryString = opts.Request.Query;  
           string search = queryString["$search"];  
           if (search != null)  
           {  
               //sarch query is maintained. to overcome that we have used below workaround  
               string key = search.Split(" OR ")[search.Split(" OR ").Length - 1];  
               //searched the typed string using where query and retured the results.  
               results = results.Where(fil => fil.Id.ToString().ToLower().Contains(key) || fil.Name.ToLower().Contains(key) || fil.Gender.ToString().ToLower().Contains(key)  
|| fil.Active.ToString().ToLower().Contains(key) || fil.CreditLimit.ToString().ToLower().Contains(key) || fil.RegistrationDate.ToString().ToLower().Contains(key));  
           }  
           if (opts.Count != null)  
               count = results.Count();  
           if (opts.Skip != null)  
               results = opts.Skip.ApplyTo(results, new ODataQuerySettings());  
           if (opts.Top != null)  
               results = opts.Top.ApplyTo(results, new ODataQuerySettings());  
           return new PageResult<Book>(results, null, count);  
       }  
  
  
Kindly download the sample from below   
  
  
Note: above attachment consist of two application. Run the ODataV4Serviec first and then BlazorApp to bind data properly.    
  
Kindly get back to us if you have further queries.   

Regards, 
Rahul 


Marked as answer
Loader.
Up arrow icon