Problem with grid search using oData (ODataV4Adaptor)

Hello

We are implementing SF Grid in our application. Our backend is in C # Asp .Net Core. Due to the amount of data we chose to implement with Data, but we are having problems doing research. The return is a 400 error, as shown below. I would like to know if you know anything about this problem with the search parameter with oData.

From what we are seeing there is no support for the search parameter. Is this right? Do you know of any solution to the problem?

We are using DataManager with the ODataV4Adaptor adapter, all as it is in the documentation.

// How are we doing
getODataList (): any {
        return new DataManager ({
            url: 'http: // localhost / cargo',
            adapter: new ODataV4Adaptor ()
        });
    }

// We are passing the parameters to the grid like this
this.toolbarOptions = ['Search', 'PdfExport'];

// In HTML in the <ejs-grid> component we are passing like this
<ejs-grid [toolbar] = "toolbarOptions" ...

// Bad request object received
{
    "error": {
        "code": "",
        "message": "The query parameter 'Specified argument was out of the range of valid values. (Parameter' $ search ')' is not supported.",
        "details": [],
        "innererror": {
            "message": "Specified argument was out of the range of valid values. (Parameter '$ search')",
            "type": "System.ArgumentOutOfRangeException",
            "stacktrace": "at Microsoft.AspNet.OData.EnableQueryAttribute.ValidateQuery (HttpRequest request, ODataQueryOptions queryOptions) \ r \ n at Microsoft.AspNet.OData.EnableQueryAttribute.CreateAndValidateQueryOptions (HttpRequest request, nataQueryContext). AspNet.OData.EnableQueryAttribute. <> C__DisplayClass1_0. <OnActionExecuted> b__1 (ODataQueryContext queryContext) \ r \ n at Microsoft.AspNet.OData.EnableQueryAttribute.ExecuteQuery (Object responseValue, IQueryable, DescriptionQueryActivityActivationActivationItem, Scripture Func`2 createQueryOptionFunction) \ r \ n at Microsoft.AspNet.OData.EnableQueryAttribute.OnActionExecuted (Object responseValue, IQueryable singleResultCollection, IWebApiActionDescriptor actionDescriptor, IWebApiRequestMessage request, Func`2 modelFunction, Func`2 createQueryOction1, Func`2 createQueryOption1 createErrorAction) "
        }
    }
}


5 Replies 1 reply marked as answer

MF Mohammed Farook J Syncfusion Team June 24, 2020 09:00 AM UTC

 
Hi Tech , 
 
Thanks for contacting Syncfusion support. 
 
As mentioned by default, ODataV4 does not support “$search” query. So it is not possible to perform search using $search querystring with default ODataV4 service. 
 
 
Regards, 
J Mohammed Farook  



GG Greg Grater replied to Mohammed Farook J July 13, 2021 08:54 PM UTC

This was opened over a year ago!?!?  .Net Odata v4 has never supported $search yet Syncfusion's SfGrid automatically forms the Odata query with the $search.  Is Syncfusion ever going to fix this?   


As a possible work around, maybe provide the ability to express which columns are filtered when someone types something into the input and then automatically transform that into a $filter?   


If you're going to provide an OData4Adapter for Blazor, please make it compliant with the OData 4 implementation.



VN Vignesh Natarajan Syncfusion Team July 19, 2021 07:39 AM UTC

Hi Greg,  
 
Thanks for contacting Syncfusion support.  
 
Query: “If you're going to provide an OData4Adapter for Blazor, please make it compliant with the OData 4 implementation. 
 
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" AllowFiltering="true" Toolbar="@(new List<string>() { "Search" })" AllowPaging="true"> 
    <SfDataManager @ref="dm" Url=https://services.odata.org/V4/Northwind/Northwind.svc/Orders/ Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager> 
    <GridColumns> 
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn> 
        <GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn> 
        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
    </GridColumns> 
</SfGrid> 
  
@code{ 
    public SfDataManager dm { getset; } 
  
    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; 
    } 
 
 
Kindly refer the below sample for your reference 
 
 
Please get back to us if you have further queries. 
 
Regards, 
Vignesh Natarajan 


Marked as answer

MC Mason Channer September 7, 2021 02:54 PM UTC

Hi Vignesh, works great for my solution. 

Though for others it is limited by 2048 bytes in a query string, so if you have a lot of columns it will not work with OData.


In the future, how could I limit which columns to include in the search $filter



VN Vignesh Natarajan Syncfusion Team September 8, 2021 03:16 AM UTC

Hi Mason,  

Greetings from Syncfusion support.  

Query: “In the future, how could I limit which columns to include in the search $filter” 

We have analyzed your query and we would like to inform you that we have already documented this topic in our UG documentation to perform search operation in specific column. Kindly refer the below UG documentation for your reference.  


Please get back to us if you have further queries.  

Regards, 
Vignesh Natarajan  


Loader.
Up arrow icon