Complex Filter oDataV4

Hello,

I have a grid with SfDatamanager , the odata request have expand a relation 1:n and need filter for the child table (a collection).

the url for example is:

https://localhost:44336/odata/PromeVenues?&$select=Id,VenueId,Name&$expand=PromeEventRun($select=StartDate,EndDate,VenueId,Id)&$filter=DataareaId eq 'SEI' and PromeEventRun/any(o: o/EventId eq 1165 and o/StartDate le 2020-05-12 and o/EndDate ge 2020-05-12)

(the red marked is parametrized)

 well the problem start when i filter grid column the url send to server add another $filter and this is not correct. Any Solution for this?

I suppose that one solution is move the initial filter to Query Grid, i know move the DataAreaId  eq 'SEI', but how can write the filter for expand entity?


thanks in advance

5 Replies 1 reply marked as answer

RN Rahul Narayanasamy Syncfusion Team December 1, 2020 04:08 PM UTC

Hi Sergio, 

Greetings from Syncfusion. 

We have validated your query and we might suspect that you want to write an expand query to expand the complex properties. We suggest you to achieve your requirement using Query property of Grid and define the complex property with dot operator. Refer the below code example. 

@using Syncfusion.Blazor.Grids 
@using Syncfusion.Blazor.Data 
 
<SfGrid @ref="Grid" TValue="Order" Width="400" Query="Qry" AllowPaging="true">    <SfDataManager Url="{your Url}” Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager> 
    <GridPageSettings PageSize="5"></GridPageSettings> 
    <GridColumns> 
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" Width="120"></GridColumn> 
        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn> 
        <GridColumn Field=”Manager.EmployeeId HeaderText="Manager Id" Width="150"></GridColumn> 
        <GridColumn Field=”Supervisor.EmployeeId HeaderText="Supervisor Id" Width="150"></GridColumn> 
        <GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date"  Width="130"></GridColumn> 
        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" Width="120"></GridColumn> 
    </GridColumns> 
</SfGrid> 
 
@code{ 
    public Query Qry = new Query().Expand(new List<string> { "Manager","Supervisor" }); 
} 


Refer our UG documentation on complex binding for your reference 


Kindly get back to us if you have any other concerns.  

If it does not meet your requirement or if we misunderstood your query, kindly share the below details. It will be helpful to validate and provide a better solution. 

  • Grid code snippets.
  • Share your model class properties.
  • Video demonstration of the problem.
  • Detailed explanation of the problem.
  • Share a simple sample that explaining your problem.

Regards, 
Rahul 




SC Sergio Cabello December 2, 2020 11:18 AM UTC

Hi Rahul

i don't need display expand columns

mi initial url for odata adaptor is 

https://localhost:44336/odata/PromeVenues?&$select=Id,VenueId,Name&$expand=PromeEventRun($select=StartDate,EndDate,VenueId,Id)&$filter=DataareaId eq 'SEI' and PromeEventRun/any(o: o/EventId eq 1165 and o/StartDate le 2020-05-12 and o/EndDate ge 2020-05-12)

if you see i have a $filter

when i put in any column of the grid any filter  the new url add a new $filter and this incorrecte for odata syntax

https://localhost:44336/odata/PromeVenues?&$select=Id,VenueId,Name&$expand=PromeEventRun($select=StartDate,EndDate,VenueId,Id)&$filter=DataareaId eq 'SEI' and PromeEventRun/any(o: o/EventId eq 1165 and o/StartDate le 2020-05-12 and o/EndDate ge 2020-05-12)&$Filter=MyColumn eq 5


thanks for your time


RN Rahul Narayanasamy Syncfusion Team December 15, 2020 03:55 AM UTC

Hi Sergio, 
 
Thanks for sharing the details. 
 
We have validated your query and checked the reported problem at our end. But we could not reproduce the problem. While performing filtering operation with complex data, the corresponding url is generated and the operation works fine. Find the below sample for your reference. 
 
 
Could you please  share the below details. It will be helpful to validate and provide a better solution.  
 
  • Grid code snippets.
  • Share your model class properties.
  • Reproduce the problem in the provided sample and revert back to us.
  • Share a simple sample that explaining your problem is possible.
 
Regards, 
Rahul 
 



SC Sergio Cabello December 15, 2020 11:50 AM UTC

Hi Rahul

over your example try change the url from datamanager with this 

<SfDataManager @ref="dm" Url="http://localhost:64956/odata/books?$filter=Gender eq 'Female'" Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager>

after this change try in the filter bar search for example Customer6

i attach screenshot fiddler error request. you can see two $filter and this is not a correct odata syntax

remember that me odata request is filtering a 1:n relation and filter is over the child entity is not a simple odata filter

thanks for your time



Attachment: errorFilter_4033febe.7z


RN Rahul Narayanasamy Syncfusion Team December 22, 2020 01:48 PM UTC

Hi Sergio, 

Thanks for sharing the details. 

We have validated your query and we might suspect that you want apply initial filtering while binding the Grid data. We suggest you to achieve your requirement by applying initial filtering using Query property. Now it works fine. Find the below code snippets and sample for your reference. 

 
<SfGrid ID="Grid" @ref="Grid" AllowFiltering="true" Query="Qry" TValue="CustomerViewModel" Toolbar="@ToolbarItems" Height="100%" AllowPaging="true" AllowSorting="true"> 
    <GridPageSettings PageSize="2"></GridPageSettings> 
    <SfDataManager @ref="dm" Url="http://localhost:64956/odata/books" Adaptor="Adaptors.ODataV4Adaptor"></SfDataManager> 
    <GridEvents OnActionFailure="ActionFailureHandler" OnActionBegin="OnBegin" TValue="CustomerViewModel"></GridEvents> 
    . . . 
</SfGrid> 
 
 
@code{    
    SfDataManager dm { get; set; } 
    public Query Qry = new Query().Where("Gender", "equal", "Female").Expand(new List<string> { "Group", "Div" }); 
    . . . 
} 


Reference


Please let us know if you have any concerns. 

Regards, 
Rahul 
 


Marked as answer
Loader.
Up arrow icon