How to filter value in combobox with concatenate string

I have an used multi column sfcombobox with Autofilter (filterType.contain) feature. It works fine. but I would like to know below 2 point for easy filter.

1. "Syncfusion.Blazor.DropDowns.FilterType.Contains" ​filter only "Text" properties (highlighted in below code). I would like to know how to filter value in all column.


<SfComboBox Enabled="@EditEnabled" @ref="cmbMaterialSKU" FilterType="Syncfusion.Blazor.DropDowns.FilterType.Contains" Query="@query" TValue="int?" TItem="MaterialSKUSearchSetup" @bind-Value="@MaterialSKUID" CssClass="e-multi-column" AllowFiltering="true" PopupWidth="700px" @onkeypress="@keydown" EnableVirtualization="true">

            <SfDataManager Json="@materialSKUSearchSetups" Adaptor="Adaptors.JsonAdaptor"></SfDataManager>

            <ComboBoxFieldSettings Text="MaterialSKUName" Value="MaterialSKUID"></ComboBoxFieldSettings>

            <ComboBoxEvents TValue="int?" TItem="MaterialSKUSearchSetup" ValueChange="@MaterialSKUChange"></ComboBoxEvents>

            <ComboBoxTemplates TItem="MaterialSKUSearchSetup">

                <HeaderTemplate>

                    <table><tr><th class="e-text-center">MaterialName</th><th width="100px">Source</th><th width="240px">MaterialCode</th></tr></table>

                </HeaderTemplate>

                <ItemTemplate Context="context2">

                    <table><tbody><tr><td style="height:none" class="e-text-center">@((context2 as MaterialSKUSearchSetup).MaterialSKUName)</td><td width="100px">@((context2 as MaterialSKUSearchSetup).SourceName)</td><td width="240px">@((context2 as MaterialSKUSearchSetup).MaterialSKUCode)</td></tr> </tbody></table>

                </ItemTemplate>

            </ComboBoxTemplates>

        </SfComboBox>




2.How to filter value using concatenate string

For example :-

Original string is = Buckle Oval Buckle Antique Black

I would like to filter above string as 

Buckle + Black


Note:-

concatenate string filter (+ operator) is available in devexpress .I would like to know how to use this in syncfussion combobox


6 Replies

VJ Vinitha Jeyakumar Syncfusion Team January 18, 2022 01:32 PM UTC

Hi Kins,


Currently, we are validating on your reported query. we will update you the further details in two business days on or before 20th January 2022.


Regards,

Vinitha



SP Sureshkumar P Syncfusion Team January 20, 2022 01:21 PM UTC

KINS, 
Query 1: 1. "Syncfusion.Blazor.DropDowns.FilterType.Contains" ​filter only "Text" properties (highlighted in below code). I would like to know how to filter value in all column. 
We can achieve your requirement by using custom filtering action. Please find the code example here 
<SfComboBox @ref="autoObj" ID="autocomplete" TValue="string" TItem="Games" Placeholder="e.g. Australia" DataSource="@LocalData"> 
    <ComboBoxFieldSettings Text="Text" Value="ID"></ComboBoxFieldSettings> 
    <ComboBoxEvents Filtering="@OnFiltering" TValue="string" TItem="Games"></ComboBoxEvents> 
</SfComboBox> 
 
@code { 
    SfComboBox<string, Games> autoObj; 
    public Query query; 
 
    public class Games 
    { 
        public string ID { get; set; } 
        public string Text { get; set; } 
    } 
    List<Games> LocalData = new List<Games> { 
    new Games() { ID= "Game1", Text= "American Football" }, 
    new Games() { ID= "Game2", Text= "Badminton" }, 
    new Games() { ID= "Game3", Text= "Basketball" }, 
    new Games() { ID= "Game4", Text= "Cricket" }, 
    new Games() { ID= "Game5", Text= "Football" }, 
    new Games() { ID= "Game6", Text= "Golf" }, 
    new Games() { ID= "Game7", Text= "Hockey" }, 
    new Games() { ID= "Game8", Text= "Rugby"}, 
    new Games() { ID= "Game9", Text= "Snooker" }, 
    new Games() { ID= "Game10", Text= "Tennis"}, 
    }; 
 
    public async Task OnFiltering(FilteringEventArgs e) 
    { 
        e.PreventDefaultAction = true; 
        query = new Query().Where(new WhereFilter() 
        { 
            Field = "ID", 
            value = e.Text, 
            Operator = "startswith", 
            IgnoreCase = true 
        }); 
 
        await this.autoObj.Filter(LocalData, query); 
    } 
 
} 
 
 
Query 2: 2.How to filter value using concatenate string 
 
We will validate the requirement and update in one business day (January 21st, 2022). 
 
Regards, 
Sureshkumar P 



KI KINS January 20, 2022 03:57 PM UTC

Thanks for reply..


The above code will work for ID Column only,I would like to know how to filter other column.



VJ Vinitha Jeyakumar Syncfusion Team January 21, 2022 02:06 PM UTC

  
Hi Kins,

If you want to filter the items based on multiple fields, we suggest you to use the ‘Predicate in the filtering event.

Code snippet:
public async Task OnFiltering(FilteringEventArgs args) 
    { 
        e.PreventDefaultAction = true; 
        var pre = new WhereFilter(); 
        var predicate = new List<WhereFilter>(); 
        predicate.Add(new WhereFilter() { Condition = "or", Field = "ID", value = args.Text, Operator = "contains", IgnoreAccent = true, IgnoreCase = true }); 
        predicate.Add(new WhereFilter() { Condition = "or", Field = "Text", value = args.Text, Operator = "contains", IgnoreAccent = true, IgnoreCase = true }); 
        pre = WhereFilter.Or(predicate); 
        var query = new Query().Where(pre); 
        await this.autoObj.Filter(LocalData, query); 
    } 

For Query "How to filter value using concatenate string"

We want to let you know that we didn't have support for filtering by string concatenation. We can use only three filter types such as Contains, StartsWith and EndWith. If you want to add any custom filters, you can do it using the Filtering event.

Regards,
Vinitha



KI KINS January 25, 2022 05:48 AM UTC

Can you please provide me example code for string concatenation "+" for custom filter in  "Filtering event"



SP Sureshkumar P Syncfusion Team February 13, 2022 04:37 PM UTC

Kins, 
 
We have created the sample based on your requirement with + operator word search using our combobox component.  
 
Find the code change example 
public async Task OnFiltering(FilteringEventArgs args)  
    { 
        args.PreventDefaultAction = true; 
        var splitWord = new string[] {}; 
        if (args.Text.IndexOf("+") > 0) 
        { 
            splitWord = args.Text.Split("+"); 
        } 
        var pre = new WhereFilter();  
        var predicate = new List<WhereFilter>(); 
        if (splitWord.Length > 0) 
        { 
            predicate.Add(new WhereFilter() { Condition = "and", Field = "Text", value = splitWord[0], Operator = "contains", IgnoreAccent = true, IgnoreCase = true }); 
            predicate.Add(new WhereFilter() { Condition = "and", Field = "Text", value = splitWord[1], Operator = "contains", IgnoreAccent = true, IgnoreCase = true }); 
        } 
        else 
        { 
            predicate.Add(new WhereFilter() { Condition = "or", Field = "ID", value = args.Text, Operator = "contains", IgnoreAccent = true, IgnoreCase = true }); 
            predicate.Add(new WhereFilter() { Condition = "or", Field = "Text", value = args.Text, Operator = "contains", IgnoreAccent = true, IgnoreCase = true }); 
        } 
        pre = WhereFilter.Or(predicate);  
        var query = new Query().Where(pre);  
        await this.autoObj.Filter(LocalData, query);  
    } 
 
 
Regards, 
Sureshkumar P 


Loader.
Up arrow icon