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
close icon

How do I write a query in the combo box where I apply the contain filter

public void CommerceDrugsNameFilter1(Syncfusion.EJ2.Blazor.DropDowns.FilteringEventArgs args)

    {
       
        if (args.Text.Length > 2)
        {
            DrugQuery = "new ej.data.Query().where('Name', 'contain', '" + args.Text + "')";
        }
       
        StateHasChanged();

    }

3 Replies

SD Saranya Dhayalan Syncfusion Team November 11, 2019 01:16 PM UTC

Hi Ebi, 
 
Thank you for contacting Syncfusion support 
 
We can achieve your requirement in filtering event. You can use Filter method to pass your datasource, the ComboBox filtering based on update data in Filter method. Please find the below code snippet: 
 
    <EjsComboBox TValue="string" @ref="comboObj" Placeholder="Select a game" DataSource="@Games" AllowFiltering="true"> 
        <ComboBoxEvents TValue="string" Filtering="OnFilter"></ComboBoxEvents> 
        <ComboBoxFieldSettings Value="text"></ComboBoxFieldSettings> 
    </EjsComboBox> 
 
 
 
@code{ 
 
    EjsComboBox<string> comboObj; 
 
    public void OnFilter(FilteringEventArgs args) 
    { 
        args.PreventDefaultAction = true; 
        var query = "new ej.data.Query().select(['text', 'id']).where('text', 'contains', '" + args.Text + "', true)"; 
        comboObj.Filter(Games, query); 
    } 
 
    public class GameFields 
    { 
        public string id { get; set; } 
 
        public string text { get; set; } 
    } 
    List<GameFields> Games = new List<GameFields>() 
   { 
        new GameFields(){ id= "Game1", text= "American Football" }, 
        new GameFields(){ id= "Game2", text= "Badminton" }, 
        new GameFields(){ id= "Game3", text= "Basketball" }, 
        new GameFields(){ id= "Game4", text= "Cricket" } 
    }; 
 
} 
 
 
For your convenience we have prepared a sample. Please find the below sample link: 
 
 
We have another suggestion to use contains filter in ComboBox component. Use FilterType property. Please find the below code snippet: 
 
<EjsComboBox TValue="string"  @ref="comboObj" Placeholder="Select a game" FilterType="Syncfusion.EJ2.Blazor.DropDowns.FilterType.Contains" DataSource="@Games" AllowFiltering="true"> 
        <ComboBoxEvents TValue="string" Filtering="OnFilter"></ComboBoxEvents> 
        <ComboBoxFieldSettings Value="text"></ComboBoxFieldSettings> 
    </EjsComboBox> 
 
 
Could you please check the above sample and get back to us if you need any further assistance on this? 
 
Regards, 
Saranya D 



MI Mike-E April 10, 2022 07:54 PM UTC

In my case, FilterType="FilterType.Contains" is exactly what I was looking for.  Nice work out there Team Syncfusion. 👍



UD UdhayaKumar Duraisamy Syncfusion Team April 15, 2022 07:01 AM UTC

Hi Mike,


We are glad that your requirement has been fulfilled on your end. We are always happy to assist you.


Regards,

Udhaya Kumar D



Loader.
Live Chat Icon For mobile
Up arrow icon