Filter Dropdownlist on 2 different criteria

Hi,

I have a Dropdownlist of Country Codes and their Country.

Example  { id: "AFG", code: "(+93)", country: "Afghanistan" },

I want to be able to filter on the code and the country name, something like below.

public onFiltering: EmitType<any> = (e: FilteringEventArgs) => {
        let query = new Query();
        let query2 = new Query();
        //frame the query based on search string with filter type.
        query = (e.text != "") ? query.where("country", "startswith", e.text, true) : query;
        query2 = (e.text != "") ? query2.where("code", "contains", e.text, true) : query2;
        //pass the filter data source, filter query to updateData method.
        e.updateData(this.countryCodes, query);
        e.updateData(this.countryCodes, query2);
    };


This isn't working, how do I filter on those 2 fields?

3 Replies 1 reply marked as answer

SN Sevvandhi Nagulan Syncfusion Team July 31, 2020 11:06 AM UTC

Hi Glen, 


Greetings from Syncfusion support. 


We suggest you using the ‘Predicate’ of dataManager to filter items based on multiple fields in filtering event of DropDownList as shown below, 


     public onFiltering: EmitType<FilteringEventArgs> = (e: FilteringEventArgs) => { 
        let predicate = new Predicate('country''startswith', e.text, true);  
        predicate = predicate.or('code''contains', e.text,true); 
        let query: Query = new Query(); 
        //frame the query based on search string with filter type. 
        query = (e.text !== '' ) ? query.where(predicate) : query; 
        //pass the filter data source, filter query to updateData method. 
        e.updateData(this.countryCodes, query); 
    } 
 
 
 


Regards, 
Sevvandhi N 


Marked as answer

GA Glen Alexander August 2, 2020 10:36 PM UTC

Thank you! Exactly what I was looking for.


PM Ponmani Murugaiyan Syncfusion Team August 3, 2020 04:35 AM UTC

Hi Glen, 

Thanks for your update.  

We have 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