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

Custom Sort and Filtering Service

Hi Team,

Can I write my custom sort and filtering service which will generate query and that is compatible with WebApiAdaptor?

If yes, please explain how.

Regards

1 Reply

TS Thavasianand Sankaranarayanan Syncfusion Team July 3, 2019 11:09 AM UTC

Hi Marko, 

Thanks for contacting Syncfusion support. 

From your query we suspect that you want to customize the default webApiAdaptor queryString with your own, while perform the sorting and filtering actions in Grid. So, we suggest to create the custom adaptor by extending the default webApiAdaptor to customize the default queryString. You can achieve this customer adaptor concept like as below code snippet, 

export class AppComponent { 
    public data: DataManager; 
    public pageSettings: Object; 
 
    @ViewChild('grid') 
    public grid: GridComponent; 
 
    ngOnInit(): void { 
        this.data = new DataManager({ url: SERVICE_URI + 'api/Orders', adaptor: new customAdaptor }); // provide the customer adaptor in adaptor property 
        this.pageSettings = { pageCount: 3 }; 
    } 
} 
 
class customAdaptor extends WebApiAdaptor { // create the custom adaptor by extending the default webApiAdaptor 
    public convertToQueryString(request: Object, query, dm: DataManager): string { 
       let res: string[] | string = []; 
        let table: string = 'table'; 
        let tableName: string = request[table] || ''; 
        let format: string = '$format'; 
        delete request[table]; 
         
        if (dm.dataSource.requiresFormat) { 
            request[format] = 'json'; 
        } 
        let keys: string[] = Object.keys(request); 
        for (let prop of keys) { 
            (<string[]>res).push(prop + '=' + request[prop]); 
        } 
        res = (<string[]>res).join('&'); // default queryString 
 
        if (dm.dataSource.url && dm.dataSource.url.indexOf('?') !== -1 && !tableName) { 
            return (<string>res); 
        } 
 
        // please customize the queryString here 
 
        return res.length ? tableName + '?' + res : tableName || ''; 
    } 
} 

If we misunderstood your query, please provide more details about your requirement. This will help us to provide a better suggestion for your requirement as early as possible. 

Regards, 
Thavasianand S. 


Loader.
Live Chat Icon For mobile
Up arrow icon