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 to change the default filter type to "Contains" in DropDownList

Thread ID:

Created:

Updated:

Platform:

Replies:

141638 Dec 23,2018 12:00 PM UTC Feb 15,2020 03:34 PM UTC Angular - EJ 2 3
loading
Tags: DropDownList
Evgeny Agusev
Asked On December 23, 2018 01:43 PM UTC

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

Christopher Issac Sunder K [Syncfusion]
Replied On 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


Jaco Roux
Replied On 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.

Sureshkumar P [Syncfusion]
Replied On 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 


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