GridFilterColumn.Operator Contains acts like StartsWith

Hello,

the contains operator for string fields does not work for me.
It acts like a StartsWith, not like a Contains...

For example name: "Hans Mustermann", search for "Han" works, but "Muster" does not work  at all.

What am i doing wrong?

GridFilterSettings
Mode="FilterBarMode.Immediate"
ImmediateModeDelay=@WaitMsecondsBeforeGoSearchByFilter
Type="Syncfusion.Blazor.Grids.FilterType.FilterBar"
Operators=Operator.Contains
>
<GridFilterColumns>

<GridFilterColumn
Field="name"
MatchCase=false
Operator=Operator.Contains
Predicate="OR"
Value=@name_filter_value
/>
<GridFilterColumn
Field="firma"
MatchCase=false
Operator=Operator.Contains
Predicate="OR"
Value=@firma_filter_value
/>
<GridFilterColumn
Field="modell_typ"
MatchCase=false
Operator=Operator.Contains
Predicate="OR"
Value=@fahrzeug_filter_value
/>

</GridFilterColumns>
</GridFilterSettings>

 

<GridColumn Field="firma"
HeaderText="Firma"
Width="150"
MinWidth="150"
ClipMode="ClipMode.Clip"
/>
<GridColumn Field="name"
HeaderText="Name"
Width="150"
MinWidth="150"
ClipMode="ClipMode.Clip"
/>
<GridColumn Field="modell_typ"
HeaderText="Fahrzeug"
Width="150"
MinWidth="150"
ClipMode="ClipMode.Clip"
/>

3 Replies 1 reply marked as answer

RN Rahul Narayanasamy Syncfusion Team February 2, 2022 01:31 PM UTC

Hi Niwa, 

Greetings from Syncfusion. 

Query: the contains operator for string fields does not work for me. It acts like a StartsWith, not like a Contains... For example name: "Hans Mustermann", search for "Han" works, but "Muster" does not work  at all. 

Based on your shared details, we have checked your reported problem. Here, we have performed the initial filter based on your mentioned word “Muster” with Contains operator. The filtering works fine without any issues. We could not able to reproduce the reported problem at our end. Find the below code snippets and sample for your reference. 

 
<SfGrid DataSource="@Orders" AllowFiltering="true"> 
    <GridFilterSettings Mode="FilterBarMode.Immediate" 
                        ImmediateModeDelay=@WaitMsecondsBeforeGoSearchByFilter 
                        Type="Syncfusion.Blazor.Grids.FilterType.FilterBar" 
                        Operators=Operator.Contains> 
        <GridFilterColumns> 
            <GridFilterColumn Field="CustomerID" MatchCase=false Operator="Operator.Contains" Predicate="OR" Value="@val"></GridFilterColumn> 
           <GridFilterColumn Field="ShipCity" MatchCase=false Operator=Operator.Contains Predicate="OR" Value="@cityval"></GridFilterColumn> 
            <GridFilterColumn Field="ShipCountry" MatchCase=false Operator=Operator.Contains Predicate="OR" Value="@countryval"></GridFilterC 
        </GridFilterColumns> 
    </GridFilterSettings> 
    <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" MinWidth="150" ClipMode="ClipMode.Clip"></GridColumn> 
       . . . 
    </GridColumns> 
</SfGrid> 
 
@code{ 
    public List<Order> Orders { get; set; } 
    double WaitMsecondsBeforeGoSearchByFilter { get; set; } = 1000; 
    public string val = "Muster"; 
    public string cityval = "London"; 
  public string countryval = "JAPAN"; 
 
    protected override void OnInitialized() 
    { 
        Orders = Enumerable.Range(1, 75).Select(x => new Order() 
        { 
            OrderID = 1000 + x, 
            CustomerID = (new string[] { "ALFKI", "Hans Mustermann", "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(); 
    } 
 
    . ..  
} 

 


If you are still facing the problem, then could you please share the below details which will be helpful to validate and provide a better solution. 

  • Reproduce the problem in the provided sample and revert back to us.
  • Share a simple reproduceable sample if possible.
  • Full Grid code snippets with video demonstration of the problem.

Regards, 
Rahul 



NI niwa replied to Rahul Narayanasamy February 3, 2022 05:18 PM UTC

Hello Rahul, thank you for your answer.

Sadly, your provided project isn't working either, video attached.

I have not changed your code, i am running dotnet 5, blazor wasm in chrome


Attachment: Bildschirmaufnahme_20220203_um_18.10.21.mov_49c00e64.zip


RN Rahul Narayanasamy Syncfusion Team February 4, 2022 01:48 PM UTC

Hi Niwa, 

Thanks for sharing the details. 

We are able to reproduce the reported case at our end. You want to change the default filter operator for the column as contains instead of startswith. But in your shared code snippets, you have just applied the initial filter for the column with contains operator. So it was not working while you performing the filter operation dynamically. 

To achieve your requirement, you can change the default filter operator by extending FilterSettings property in the column. In the following sample, we have changed the default operator for CustomerID column as contains from startswith. Find the below code snippets and sample for your reference. 

Reference

 
<SfGrid DataSource="@Orders" AllowFiltering="true"> 
    <GridFilterSettings Mode="FilterBarMode.Immediate" 
                        ImmediateModeDelay=@WaitMsecondsBeforeGoSearchByFilter 
                        Type="Syncfusion.Blazor.Grids.FilterType.FilterBar" 
                        Operators=Operator.Contains> 
        . ..  
    <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" MinWidth="150" ClipMode="ClipMode.Clip" 
                    FilterSettings="@(new FilterSettings{ Operator = Operator.Contains })"></GridColumn> 
        . ..  
    </GridColumns> 
</SfGrid> 


Please let us know if you have any concerns. 

Regards, 
Rahul 


Marked as answer
Loader.
Up arrow icon