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

Filtering is not working

Thread ID:

Created:

Updated:

Platform:

Replies:

147139 Sep 2,2019 10:17 AM UTC Sep 12,2019 06:35 AM UTC Angular - EJ 2 5
loading
Tags: Grid
kenan dogan
Asked On September 2, 2019 10:18 AM UTC


Pavithra Subramaniyam [Syncfusion]
Replied On September 3, 2019 07:22 AM UTC

Hi kenan, 
 
Thanks for contacting Syncfusion support. 
 
In custom data binding with Async pipe, we need to generate the filter query from the state passes to the service. So that the filter action will be done in the service. We have prepared a simple sample based on your requirement. Please refer to the below code example and sample link.  
 
export class OrderService {  
    .   .   .  
    
    public execute(state: DataStateChangeEventArgs): Promise<DataResult> {  
        return this.getData(state);  
    }  
    
    private getData(state: DataStateChangeEventArgs): Promise<DataResult> {  
        const pageQuery = `$skip=${state.skip}&$top=${state.take}`;  
        let sortQuery: string = '';  
        let filterQuery: String = '';  
          
        if (state.where) {  // here you can prepare the filter query  
            filterQuery = `&$filter=` + state.where.map((obj:any) => {  
                return (obj).predicates.map((predicate:any) => {  
                    return predicate.operator === 'equal' ? `${predicate.field} eq ${predicate.value}` :                     `${predicate.operator}(tolower(${predicate.field}),'${predicate.value}')`;  
                }).reverse().join(' and ');  
            });  
        }  
        this.ajax.url = `${this.BASE_URL}?${pageQuery}${sortQuery}${filterQuery}&$inlinecount=allpages&$format=json`;  
           
        return this.ajax.send().then((response: any) => {  
            const data: any = JSON.parse(response);  
            return {  
                count:  parseInt(getValue('d.__count', data), 10),  
                result: getValue('d.results', data)  
            };  
        });  
    }  
  };  
 
 
 
Please get back to us if you need any further assistance on this. 
 
Regards, 
Pavithra S. 


kenan dogan
Replied On September 5, 2019 11:26 AM UTC

Thank you. So, How do I use checkbox filter?

Pavithra Subramaniyam [Syncfusion]
Replied On September 6, 2019 08:33 AM UTC

Hi kenan, 
 
For Custom Binding with Async pipe, the grid actions query should be generated in service by manually as per your requirement. For CheckBox or Excel filter you need to return the dataSource from the server based on some condition for the request to populate the Filter dialog with checkbox. Please refer to the below code example for more information. 
 
[service.ts] 
import { Injectable } from '@angular/core'; 
@Injectable() 
export class OrdersService extends Subject<DataStateChangeEventArgs> { 
   
  public getData(state: DataStateChangeEventArgs): Observable<DataStateChangeEventArgs> { 
      .    .   . 
 
     if (state.where) {  
 // here you can prepare the filter query as per your requirment 
        }  
 
    return this.http 
      .get(`${this.BASE_URL}?${pageQuery}${sortQuery}${filterQuery}&$count=true`) 
      .pipe(map((response: any) => response.json())) 
      .pipe(map((response: any) => { 
        return state.dataSource === undefined ? (<DataResult>{ 
          result: response['value'], 
          count: parseInt(response['@odata.count'], 10), 
        }) : response['value']; 
      })) 
      .pipe(map((data: any) => data)); 
  } 
} 
 
 
 
[component.ts] 
public dataStateChange(state: DataStateChangeEventArgs): void { 
    if ((<any>state.action).requestType === 'filterchoicerequest' ||(<any>state.action).requestType=== 'filtersearchbegin') { 
      this.service.getData(state).subscribe((e) => state.dataSource(e)); 
    } else { 
      this.service.execute(state); 
    } 
  } 
 
 
Regards, 
Pavithra S 
 


kenan dogan
Replied On September 11, 2019 11:36 AM UTC

Thank you for support.



Thavasianand Sankaranarayanan [Syncfusion]
Replied On September 12, 2019 06:35 AM UTC

Hi Kenan, 
 
Thanks for your update. 
 
We are happy that the problem has been resolved at your end. 
 
Regards, 
Thavasianand S.  


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