skip to Main Content

Hello all respected members.

I have a question on how to add AND condition to WHERE clause on below syncfusion datagrid code:

<SfGrid DataSource="@detailData" Query="@(new Query().Where("book_name","equal",_data.book_name))" AllowPaging="true">

What I want to achieve is that I can have more than 1 conditions from the code.

Thank you.

2

Answers


  1. If you want to apply multiple conditions in a query, you can generate predicates using the WhereFilter and then pass the generated predicates to the Grid Query property for performing filtering operations in the Grid. Please refer to the code snippet and documentation below for your reference.

    <SfButton Content="Apply Filter" OnClick="Filter"></SfButton><SfButton Content="Clear Filter" OnClick="ClearFilter"></SfButton><SfGrid DataSource="@Orders" Query="@QueryData" AllowPaging="true">
    
    @code {
    public List<Order> Orders { get; set; }
    
    public Query QueryData { get; set; } = new Query();
    public void  Filter()
    {
        var Col1Pre = new WhereFilter();
        var predicate = new List<WhereFilter>();
        predicate.Add(new WhereFilter() { Field = "Freight", value = 2, Operator = "greaterthanorequal" });
        predicate.Add(new WhereFilter() { Field = "Freight", value = 15, Operator = "lessthanorequal" });
        Col1Pre = WhereFilter.And(predicate);
        QueryData = new Query().Where(Col1Pre);
    
    }
    
    public void ClearFilter()
    {
        QueryData = new Query();
    }
    

    Reference:
    https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Data.WhereFilter.html
    https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Data.WhereFilter.html#Syncfusion_Blazor_Data_WhereFilter_And_Syncfusion_Blazor_Data_WhereFilter_
    https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Data.WhereFilter.html#Syncfusion_Blazor_Data_WhereFilter_Or_Syncfusion_Blazor_Data_WhereFilter_

    Login or Signup to reply.
  2. You can chain Where methods to apply multiple filters in a row which is equivalent to AND.

    Doc

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search