Complex filtering with dynamic datasource

Hello,

The project type is: Blazor Server

There is a combobox with manually populated datasource as ObservableCollection.
There is only the top 10 items are retrieved and shown.
I added filtering via the fitering event, it works well for the datasource, but the collected items are not shown in the combobox.
It's because I need to set the FilterType, which only accepts: Contains / StartsWith / EndsWith, meanwhile my manual filtering is something like: ContainsAnyWord
I suspect that the built in Filtering is applied over the manually filtered datasource, which gives 0 result. 
But without setting the FilterType there is no result at all.

The control is briefly:

           
             
                         AllowFiltering="true" FilterType="SfDDFilterType.Contains" >

               
                                Created="CB_Created"
                                Filtering="CB_Filtering"
                                ValueChange="CB_ValueChanged"/>
               

               

               
                           
           

My question is how to use the custom datasource with manual filtering, ignoring the built in filter logic?

4 Replies 1 reply marked as answer

IP Istvan Piroska August 18, 2020 09:58 AM UTC

The code is:

             <SfComboBox @ref="@CBFilter" TValue="string" TItem="VendorProduct" DataSource="@VendorProductSelection" Value="@Value"
                         AllowFiltering="true" FilterType="SfDDFilterType.Contains" >

                <ComboBoxEvents TValue="string"
                                Created="CB_Created"
                                Filtering="CB_Filtering"
                                ValueChange="CB_ValueChanged"/>
                <ComboBoxFieldSettings Value="@nameof(VendorProduct.Id)" Text="@nameof(VendorProduct.SkuName)"/>

                <ComboBoxTemplates TItem="VendorProduct">

                </ComboBoxTemplates>
            </SfComboBox>    




PM Ponmani Murugaiyan Syncfusion Team August 19, 2020 02:50 PM UTC

Hi Istvan,  

Greetings from Syncfusion support. 

Query: How to use the custom datasource with manual filtering, ignoring the built in filter logic? 

As per your requirement “to filter the dynamically added items in the datasource(ObservableCollection) using filtering event”, we have prepared sample. Please find the code snippet for custom filter using filtering event below for reference. 

public void onFiltering(Syncfusion.Blazor.DropDowns.FilteringEventArgs args) 
    { 
        args.PreventDefaultAction = true; 
        var query = new Query(); 
        if (args.Text != "") 
        { 
            query = new Query().Where(new WhereFilter() 
            { 
                Field = "Name", 
                value = args.Text, 
                Operator = "Contains", 
                IgnoreCase = true 
            }); 
        } 
        this.CBFilter.Filter(VendorProductSelection, query); 
    } 

 
Kindly check with the above sample. If issue still exists in your end or if we misunderstood the query, please provide the below details. 

  1. Whether used complex data in your datasource.
  2. If possible replicate the issue in the provided sample.

The above requested details will helps us to provide you the solution at earliest. 
 
Regards, 
Ponmani M

Marked as answer

IP Istvan Piroska August 19, 2020 06:38 PM UTC

Perfect, thank you!
Applying the following filtering code after the manually populated datasource is does the job.

                e.PreventDefaultAction = true;

                var filter = "";
                if (!string.IsNullOrWhiteSpace(e.text))
                    filter = e.text;

                var fs = filter.Split(" ");
                var query = new Query();
                foreach (var s in fs) 
                    query = query.Where(new WhereFilter
                    {
                        Field = nameof(VendorProduct.SkuName), 
                        value = s, 
                        Operator = "Contains", 
                        IgnoreCase = true
                    });
                CBFilter.Filter(VendorProductSelection, query); 


PM Ponmani Murugaiyan Syncfusion Team August 20, 2020 12:10 PM UTC

Hi Istvan, 

Thanks for the update.  

We are glad to hear that the provided suggestion helped you in achieving your requirement.  

Please get back to us if you need further assistance. 

Regards, 
Ponmani M 


Loader.
Up arrow icon