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

How to change the default filter type to "Contains" in DropDownList

Hi, I want to use filter type Contains by default in DropDownList. Is it possible?
Thanks.

3 Replies

CI Christopher Issac Sunder K Syncfusion Team December 24, 2018 07:09 AM UTC

Hi Evgeny, 

Thanks for contacting Syncfusion Support.  

We suggest you to change the filter type as “contains” through filtering event of DropDownList as shown below 

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

We have prepared a sample for reference. Please refer to the below given link 



Please let us know if you need any further assistance. 

Thanks,
Christo



JR Jaco Roux replied to Christopher Issac Sunder K February 13, 2020 12:22 PM UTC

Hi Evgeny, 

Thanks for contacting Syncfusion Support.  

We suggest you to change the filter type as “contains” through filtering event of DropDownList as shown below 

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

We have prepared a sample for reference. Please refer to the below given link 



Please let us know if you need any further assistance. 

Thanks,
Christo


How do handle this when you are using the | async pipe to bind data?

The data will be an Observable so the query with updateData can't work.


SP Sureshkumar P Syncfusion Team February 15, 2020 03:34 PM UTC

Hi Jaco, 
 
Greetings from Syncfusion support. 
 
We can set the filtertype property value as ‘contains’ to achieve your requirement.  
 
Kindly refer the below code example. 
 
[app.component.html] 
 
<ejs-dropdownlist id='remoteData' #remote [dataSource]='data | async' [filterType]='filterType' [allowFiltering]='true' 
    [fields]='remoteFields' [placeholder]='remoteWaterMark' sortOrder='Ascending'></ejs-dropdownlist> 
 
[app.component.ts] 
@ViewChild('remote') 
  public multiselectObj: DropDownListComponent; 
  public data: any; 
  constructor(private http: HttpClient) { 
 
  } 
  ngOnInit() { 
    this.getData(); 
  } 
 
  public getData() { 
    this.data = this.http.get<{ [key: string]: object; }[]>('https://services.odata.org/V4/Northwind/Northwind.svc/Orders').pipe( 
      map(data => { 
        return (<any>data).value; 
      }) 
    ); 
  } 
  public remoteFields: Object = { text: 'CustomerID', value: 'CustomerID' }; 
  // set the placeholder to MultiSelect input element 
  public remoteWaterMark: string = 'Select names'; 
  public filterType: any = 'Contains'; 
@ViewChild('remote') 
  public multiselectObj: DropDownListComponent; 
  public data: any; 
  constructor(private http: HttpClient) { 
 
  } 
  ngOnInit() { 
    this.getData(); 
  } 
 
  public getData() { 
    this.data = this.http.get<{ [key: string]: object; }[]>('https://services.odata.org/V4/Northwind/Northwind.svc/Orders').pipe( 
      map(data => { 
        return (<any>data).value; 
      }) 
    ); 
  } 
  public remoteFields: Object = { text: 'CustomerID', value: 'CustomerID' }; 
  // set the placeholder to MultiSelect input element 
  public remoteWaterMark: string = 'Select names'; 
  public filterType: any = 'Contains'; 
 
 
We have created a sample based on your requirement. please find the sample here: https://stackblitz.com/edit/angular-guucqq-w9wfww?file=app.component.ts  
 
Regards, 
Sureshkumar P 


Loader.
Live Chat Icon For mobile
Up arrow icon