ODataV4 search on string and double columns

Hello, 

I am using the Syncfusion grid with an WebAPI adaptor with a custom ODataV4 data manager to fetch data. Currently when I search using the search toolbar it applies a "contains" filter to each column with the datatype being string (even for columns that are numerical). Is there a way to allow the ODataV4 to search on numerical columns as well as string columns?

Thank you,

Josh Goughnour


8 Replies

MS Monisha Saravanan Syncfusion Team February 1, 2022 12:27 PM UTC

Hi Joshua, 

Greetings from Syncfusion support. 

Before proceeding further with your requirement, we need some more details about the requirement. So kindly share the following details to validate the reported query further at our end. 

  1. Share us the complete grid rendering code snippet.
 
  1. Share us the way that you have used to bind data using custom ODataV4 with webApi adptor.
 
  1. Have you used EnableODataSearchFallback on your DataManager to perform search operation in ODataV4 adaptor using filter queries?.

The above requested details will be helpful for us to validate your query and to provide you with a better solution as early as possible. 

Regards, 
Monisha 



JG Joshua Goughnour February 1, 2022 04:33 PM UTC

Hi Monisha, 

Below is the requested information


Grid Setup


Column setup



Startup



CustomOData Adaptor



The search string is returning a contains on each column, including the column with a number type.


Thank you,

Josh G.



MS Monisha Saravanan Syncfusion Team February 2, 2022 11:37 AM UTC

Hi Joshua, 

Thanks for your update. 

We have prepared an sample based on your shared code snippet and we are able to replicate the mentioned issue at our end. This is because EnableODataSearchFallback property is defined properly in SfDataManager. We suggest you to overcome the reported issue by handling EnableODataSearchFallback on OnAfterRender method. It will create filter query only to the required column by considering its column type. Kindly refer the attached code snippet and sample for your reference. 

public class CustomODataV4 : WebApiAdaptor 
    {         
        public override string OnPredicate(WhereFilter filter, DataManagerRequest query, bool requiresCast = false) 
        { 
            ODataV4Adaptor customAdaptor = new ODataV4Adaptor(dm); 
            //RemoteOptions Rm = customAdaptor.Options; 
            //Rm.EnableODataSearchFallback = true; 
            //customAdaptor.Options = Rm; 
            return customAdaptor.OnPredicate(filter, query, requiresCast); 
        } 
    } 
 
    protected override void OnAfterRender(bool firstRender) 
    { 
        base.OnAfterRender(firstRender); 
        if (DM != null) 
        { 
#pragma warning disable BL0005 
            DM.DataAdaptor = new CustomODataV4(DM); 
#pragma warning restore BL0005 
        } 
        RemoteOptions Rm = (DM.DataAdaptor as WebApiAdaptor).Options;  
        Rm.EnableODataSearchFallback = true;  
        (DM.DataAdaptor as WebApiAdaptor).Options = Rm;  
    } 



Kindly get back to us if you have further queries. 

Regards, 
Monisha 



JG Joshua Goughnour February 10, 2022 08:03 PM UTC

Thank you for the response!


It looks like that took care of the issue. I have 2 last questions related to this. 

1) is it possible to override the number column with a less than or greater than filter?

2) Currently the OData filter query is all lowercase. Is it possible to make this filter case sensitive?


Thank you,

Josh G.



MS Monisha Saravanan Syncfusion Team February 11, 2022 11:34 AM UTC

Hi Joshua, 

Thanks for your update. 

Query1: “is it possible to override the number column with a less than or greater than filter.” 
 
No, it is not possible to override the search operator for number column with less than or greater than. Kindly check the attached documentation to know the list of operators supported for searching. 


Query2: “Currently the OData filter query is all lowercase. Is it possible to make this filter case sensitive.” 
 
We can make the filter query to case sensitive by handling tolower or toupper to the query string. Kindly refer the below site for further reference. 
 
 
Kindly get back to us if we misunderstood your query or if you have further queries. 

Regards, 
Monisha. 



JG Joshua Goughnour February 11, 2022 03:55 PM UTC

How exactly would I force the data manager to use tolower() instead of just making the string all lowercase? 


Example of how the query string currently looks: 

(tolower(Inchi) eq 'inchi1s/hno3/c2-1(3)4/h(h,2,3,4)')

How I would like it to look:

(tolower(Inchi) eq 'InChI1S/HNO3/c2-1(3)4/h(h,2,3,4)')



Thank you,

Josh G.



MS Monisha Saravanan Syncfusion Team February 14, 2022 02:37 PM UTC

Hi Joshua, 

Thanks for your update. 

Currently we are validating the reported query at our end. We need some more time to analyze your query. So we will update you the further details in two business days on or before (16th February 2022).  

Until then we appreciate your patience. 
 
Regards, 
Monisha 



VN Vignesh Natarajan Syncfusion Team February 17, 2022 04:18 PM UTC

Hi Joshua,  
 
Thanks for the patience.  
 
Query: “How I would like it to look: (tolower(Inchi) eq 'InChI1S/HNO3/c2-1(3)4/h(h,2,3,4)')” 
 
We have achieved your requirement by overriding the BeforeSend() method of WebAPI adaptor. Similar to OnPredicate method, we suggest you to extend the BeforeSend ethod and change the Url string as per your requirement.  
 
    public class CustomODataV4 : WebApiAdaptor 
    {         
        public DataManager dm { get; set; } 
        public CustomODataV4(DataManager dataManager) : base(dataManager) 
        { 
            dm = dataManager; 
        } 
        public override string OnPredicate(WhereFilter filter, DataManagerRequest query, bool requiresCast = false) 
        { 
            ODataV4Adaptor customAdaptor = new ODataV4Adaptor(dm);            
            return customAdaptor.OnPredicate(filter, query, requiresCast); 
        } 
        public override void BeforeSend(HttpRequestMessage request) 
        { 
            //here you will get entire uri string. kindly mdify the string as per your requirement 
            if (request.RequestUri.AbsoluteUri.Contains("tolower")) 
            { 
                var check = request.RequestUri.AbsoluteUri.Replace("tolower", "toupper"); 
                var updatedUri = new Uri(check); 
                request.RequestUri = updatedUri; 
            } 
            //and send to the BeforeSend method.  
            base.BeforeSend(request); 
        } 
    } 
  
Please find the modified sample from below  
 
 
Please get  back to us if you have further queries.  
 
Regards 
Vignesh Natarajan 


Loader.
Up arrow icon