OData $search in Blazor Grid

Hello,

Is there a way to substitute OData V4 $search parameter with $select and/or $filter? I have noticed that dotnet core OData package does not have support for $search.

Thanks in advance,

Erick

7 Replies 1 reply marked as answer

VN Vignesh Natarajan Syncfusion Team June 29, 2020 09:22 AM UTC

Hi Erick,  
 
Greetings from Syncfusion support.  
 
Query: “Is there a way to substitute OData V4 $search parameter with $select and/or $filter? && dotnet core OData package does not have support for $search. 
 
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 2 Service Pack 1 release which is expected to be rolled out by end of July 2020.  
 
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,
Vignesh Natarajan
 



ER Erick July 6, 2020 05:53 PM UTC

Thanks for your answer. I will evaluate the change on API side. However I would like the service pack solution better.


Regards,

Erick


VN Vignesh Natarajan Syncfusion Team July 7, 2020 08:02 AM UTC

Hi Erick,  

Sorry for the inconvenience caused.  

Now we have enabled access to the feedback. Kindly try to access the feedback now by logging in using your email id. The reported issue will be fixed and included in our 2020 Volume 2 Service Pack which is expected to be rolled out by month end of July 2020.  

Till then we appreciate your patience.   

Regards, 
Vignesh Natarajan 



JO Josh October 22, 2021 09:50 PM UTC

Is there an update on this? I am still experiencing the "parameter $search is not...." error but I cannot access the l



RN Rahul Narayanasamy Syncfusion Team October 25, 2021 12:41 PM UTC

Hi Josh, 

Greetings from Syncfusion. 

Query: Is there an update on this? I am still experiencing the "parameter $search is not...." error but I cannot access the l 

We have analyzed your query and we would like to inform you that we have already provided support to perform Search action in ODataV4 adaptor using $filter query. So kindly upgrade your application to our latest version to resolve the reported query. To enable search operation in OData, we suggest you enable the EnableODataSearchFallback option. Please use the below code in your application to perform search operations in Grid. 
 
Limitation :  
Please find the following limitations applied for implementing this feature in your application. 
 
  1. The contains operator will be applied only for string typed column
  2. The equal operator will only be applied for all other data types.

Refer the below cod example for your reference. 

 
<SfGrid TValue="Order" @ref="GridInstance" AllowPaging="true" Toolbar="@(new List<string>() { "Search" })"> 
    <SfDataManager @ref="dm" Url=http://localhost:64956/odata/books Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager> 
    <GridEvents OnActionFailure="ActionFailureHandler" TValue="Order"></GridEvents> 
    <GridColumns> 
        <GridColumn Field=@nameof(Order.guid) HeaderText="GUID" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
        <GridColumn Field=@nameof(Order.Title) HeaderText="Title Name" Width="150"></GridColumn> 
        . . . 
    </GridColumns> 
</SfGrid> 
 
@code{ 
    SfGrid<Order> GridInstance; 
    public SfDataManager dm { get; set; } 
    protected override void OnAfterRender(bool firstRender) 
    { 
        base.OnAfterRender(firstRender); 
        RemoteOptions Rm = (dm.DataAdaptor as ODataV4Adaptor).Options; 
        Rm.EnableODataSearchFallback = true; 
        (dm.DataAdaptor as ODataV4Adaptor).Options = Rm; 
    } 
    . . . 
} 

Please let us know if you have any concerns. 

Regards, 
Rahul 


Marked as answer

JI Jimmy January 20, 2022 12:23 AM UTC

Hello,

This was working as far back as v19.3.0.59

But with more recent releases - such as version 19.4.0.43, my ODataV4Adaptor no longer works.


For my grid I have something like this:


<SfDataManager @ref="dm" Url="..."
 Offline="false"
        Headers=@HeaderData
        CrossDomain="true"
        Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager>


And in code:


        protected override async Task OnAfterRenderAsync(bool firstRender)
        {
            base.OnAfterRender(firstRender);


            if (firstRender)
            {
                HeaderData["Authorization"] = $"Bearer {accessToken}";
                RemoteOptions Rm = (dm.DataAdaptor as ODataV4Adaptor).Options;
                Rm.EnableODataSearchFallback = true;
                (dm.DataAdaptor as ODataV4Adaptor).Options = Rm;
            }
        }


I see my service that 'Url' points to returns data but the UI shows an empty grid. Would you be able to test a similar set up?

Does it have anything to do with the search fallback?

Thank you



RN Rahul Narayanasamy Syncfusion Team January 20, 2022 03:04 PM UTC

Hi Jimmy, 

Greetings from Syncfusion. 

We need some details regarding your reported problem. Could you please share the below details before proceeding this further. It will be helpful to validate and provide a better solution. 

  • Bind OnActionFailure event to the Grid and share the exception details if you have faced any errors.
  • Share you Grid code snippets and model class details.
  • Did you have used any Enum columns in the Grid or model class?

Regards, 
Rahul 


Loader.
Up arrow icon