We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Cannot filter with Operator=@Operator.Contains

Filtering works nicely for StartsWith, but when I set the operator to Contains it still acts as if it were set to StartsWith

How can I fix this?

@page "/"

<h1>Hello, world!</h1>

<EjsGrid DataSource="@Orders" AllowFiltering="true" AllowPaging="true">
        <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.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>
        <GridFilterColumn Field=@nameof(Order.CustomerID) Operator=@Syncfusion.EJ2.Blazor.Operator.Contains/>

    public List<Order> Orders { get; set; }

    protected override void OnInitialized()
        Orders = Enumerable.Range(1, 75).Select(x => new Order()
            OrderID = 1000 + x,
            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)],

    public class Order
        public int? OrderID { get; set; }
        public string CustomerID { get; set; }
        public DateTime? OrderDate { get; set; }
        public double? Freight { get; set; }

1 Reply

MS Madhu Sudhanan P Syncfusion Team February 2, 2020 04:51 AM UTC

Hi Peter, 
Greetings from Syncfusion support.  
To change the default filter operator for particular column (CustomerID) in Grid. We suggest you to define the filter operator at column level using Filter property. Refer the below code example.  
<EjsGrid DataSource="@Orders" AllowFiltering="true" AllowPaging="true" Height="315"> 
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Center" Width="120"></GridColumn> 
        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name"  Filter="@FilterParams" TextAlign="TextAlign.Center" Width="150"></GridColumn> 
        <GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Center" Width="130"></GridColumn> 
        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Center" Width="120"></GridColumn> 
    object FilterParams = new { @@operator = "contains" }; 
    . . .  . .   
Note: GridFilterSettings is used to set default filtered columns or initial filtering to the Grid. If you want to change the default operator kindly refer the above solution. 
Kindly refer our UG documentation for your reference. 
Please get back to us if you have further queries.      
Madhu Sudhanan P 

Live Chat Icon For mobile
Up arrow icon