Initial Filtering Two Values in column with or operator

Hello, I have a grid and on initial load I want the filter to return rows that are either Step.Progress or Step.Final.

I want to filter the Step field with OR operator to display rows that are either Step.Progress or Step.Final

However the code below doesnt work

<GridFilterColumn Field="Step" Operator="Operator.Equal" Predicate="or" Value="Step.Progress" >
</GridFilterColumn>

<GridFilterColumn Field="Step" Operator="Operator.Equal" Predicate="or" Value="Step.Final" >
</GridFilterColumn>


public enum Step {
Final,
Progress,
Complete
}


1 Reply 1 reply marked as answer

VN Vignesh Natarajan Syncfusion Team August 10, 2022 05:05 AM UTC

Hi Pavel,


Greetings from Syncfusion support.


We suggest you achieve your requirement of filtering the column with multiple values using Created event and FilterByColumnAsync method of Grid. Refer to the below code example.


<SfGrid @ref="Grid" DataSource="@Orders" AllowFiltering="true" AllowPaging="true"> 

    <GridEvents Created="CreatedHandler" TValue="Order"></GridEvents>

    <GridColumns>

        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>

        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn>

        <GridColumn Field=@nameof(Order.Progress) HeaderText="Progress" 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 SfGrid<Order> Grid { get; set; }

    public List<Order> Orders { get; set; } = new List<Order>();

    public async Task CreatedHandler()

    {

        await Grid.FilterByColumnAsync("Progress", "equal", new List<string> { "Complete", "Progress" }, "or");

    }

 

 

    protected override void OnInitialized()

    {

        Orders = Enumerable.Range(1, 75).Select(x => new Order()

            {

                OrderID = 1000 + x,

                Progress = (new Step[] {Step.Complete, Step.Final, Step.Progress })[new Random().Next(3)],

                CustomerID = (new string[] { "ALFKI", "ANANTR", "ANTON", "BLONP", "BOLID" })[new Random().Next(5)],

                Freight = 2.1 * x,

                OrderDate = (new DateTime[] { new DateTime(2010, 5, 1), new DateTime(2010, 5, 2), new DateTime(2010, 5, 3), })[new Random().Next(3)],

            }).ToList();

    }

 

    public class Order

    {

        public int? OrderID { get; set; }

        public string CustomerID { get; set; }

        public Step Progress { get; set; }

        public DateTime? OrderDate { get; set; }

        public double? Freight { get; set; }

    }

 

    public enum Step

    {

        Final,

        Progress,

        Complete

    }


Also, we have discussed similar topics in the below Public forums. Refer this for your reference


http://www.syncfusion.com/forums/161018/filterbycolumn-with-multiple-conditions?reply=Sg23ue


Please get back to us if you have further queries.


Regards,

Vignesh Natarajan


Marked as answer
Loader.
Up arrow icon