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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

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

Thread ID:

Created:

Updated:

Platform:

Replies:

148960 Nov 8,2019 09:49 PM UTC Nov 11,2019 01:16 PM UTC Blazor 1
loading
Tags: ComboBox
ebi torabi
Asked On November 8, 2019 09:49 PM UTC

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();

    }

Saranya Dhayalan [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon