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 || '';
}
} |