feat: add clients search field (#683)

Fixes: #445
This commit is contained in:
Benura Abeywardena
2020-08-02 11:40:38 +05:30
committed by GitHub
parent 1874c6a03b
commit 6a47a69007
3 changed files with 38 additions and 3 deletions
+18 -1
View File
@@ -36,7 +36,7 @@ export class ClientsDataSource implements DataSource<any> {
this.clientsSubject.next([]);
this.clientsService.getClients(orderBy, sortOrder, pageIndex * limit, limit)
.subscribe((clients: any) => {
clients.pageItems = (clientActive) ? (clients.pageItems.filter((client: any) => client.active)) : clients.pageItems;
clients.pageItems = (clientActive) ? (clients.pageItems.filter((client: any) => client.active)) : (clients.pageItems.filter((client: any) => !client.active));
this.recordsSubject.next(clients.totalFilteredRecords);
this.clientsSubject.next(clients.pageItems);
});
@@ -57,4 +57,21 @@ export class ClientsDataSource implements DataSource<any> {
this.recordsSubject.complete();
}
/** Filter Active Client Data.
* @param {string} filterValue Filter Value which clients should be filtered.
* @param {string} orderBy Property by which clients should be sorted.
* @param {string} sortOrder Sort order: ascending or descending.
* @param {number} pageIndex Page number.
* @param {number} limit Number of clients within the page.
*/
filterClients(filter: string, orderBy: string = '', sortOrder: string = '', pageIndex: number = 0, limit: number = 10, clientActive: boolean = true) {
this.clientsSubject.next([]);
this.clientsService.getClients(orderBy, sortOrder, pageIndex * limit, limit)
.subscribe((clients: any) => {
clients.pageItems = clients.pageItems.filter((client: any) => client.active === clientActive && client.displayName.toLowerCase().includes(filter));
this.recordsSubject.next(clients.totalFilteredRecords);
this.clientsSubject.next(clients.pageItems);
});
}
}