diff --git a/src/app/app.utils.ts b/src/app/app.utils.ts index e6fce580..36f18381 100644 --- a/src/app/app.utils.ts +++ b/src/app/app.utils.ts @@ -13,7 +13,7 @@ import { SbiProjectModel } from './core/models/sbi-project'; import { Directory, Filesystem } from '@capacitor/filesystem'; import { Toast } from '@capacitor/toast'; import { sha256 } from 'js-sha256'; - +import { MatTableDataSource } from '@angular/material/table'; export default class Utils { static getCurrentDate() { let now = new Date(); @@ -1030,4 +1030,12 @@ export default class Utils { }); return dialogRef; } + + static applyFilter(event: Event, dataSource: MatTableDataSource): void { + const filterValue = (event.target as HTMLInputElement).value.trim().toLowerCase(); + dataSource.filter = filterValue; + if (dataSource.paginator) { + dataSource.paginator.firstPage(); + } + } } diff --git a/src/app/features/dashboard/biometric-dashboard/biometric-dashboard.component.ts b/src/app/features/dashboard/biometric-dashboard/biometric-dashboard.component.ts index b7624ca5..53ec711d 100644 --- a/src/app/features/dashboard/biometric-dashboard/biometric-dashboard.component.ts +++ b/src/app/features/dashboard/biometric-dashboard/biometric-dashboard.component.ts @@ -131,12 +131,7 @@ export class BiometricDashboardComponent implements OnInit { } applyFilter(event: Event) { - const filterValue = (event.target as HTMLInputElement).value; - console.log(filterValue); - this.dataSource.filter = filterValue.trim().toLowerCase(); - if (this.dataSource.paginator) { - this.dataSource.paginator.firstPage(); - } + Utils.applyFilter(event, this.dataSource); } ngOnDestroy(): void { this.subscriptions.forEach((subscription) => subscription.unsubscribe()); diff --git a/src/app/features/dashboard/my-reports/my-reports.component.ts b/src/app/features/dashboard/my-reports/my-reports.component.ts index fce5e2a1..7b889fcc 100644 --- a/src/app/features/dashboard/my-reports/my-reports.component.ts +++ b/src/app/features/dashboard/my-reports/my-reports.component.ts @@ -63,11 +63,7 @@ export class MyReportsComponent implements OnInit { this.dataSource.sort = this.sort; } applyFilter(event: Event) { - const filterValue = (event.target as HTMLInputElement).value.trim().toLowerCase(); - this.dataSource.filter = filterValue; - if (this.dataSource.paginator) { - this.dataSource.paginator.firstPage(); - } + Utils.applyFilter(event, this.dataSource); this.dataSource.filterPredicate = this.customFilterPredicate; } diff --git a/src/app/features/dashboard/partner-reports/partner-reports.component.ts b/src/app/features/dashboard/partner-reports/partner-reports.component.ts index 6f51a400..de943f28 100644 --- a/src/app/features/dashboard/partner-reports/partner-reports.component.ts +++ b/src/app/features/dashboard/partner-reports/partner-reports.component.ts @@ -65,13 +65,7 @@ export class PartnerReportsComponent implements OnInit { } applyFilter(event: Event) { - const filterValue = (event.target as HTMLInputElement).value - .trim() - .toLowerCase(); - this.dataSource.filter = filterValue; - if (this.dataSource.paginator) { - this.dataSource.paginator.firstPage(); - } + Utils.applyFilter(event, this.dataSource); this.dataSource.filterPredicate = this.customFilterPredicate; } diff --git a/src/app/features/dashboard/projects-dashboard/projects-dashboard.component.ts b/src/app/features/dashboard/projects-dashboard/projects-dashboard.component.ts index 8ff8042b..844b8763 100644 --- a/src/app/features/dashboard/projects-dashboard/projects-dashboard.component.ts +++ b/src/app/features/dashboard/projects-dashboard/projects-dashboard.component.ts @@ -269,11 +269,7 @@ export class ProjectsDashboardComponent implements OnInit { } applyFilter(event: Event) { - const filterValue = (event.target as HTMLInputElement).value.trim().toLowerCase(); - this.dataSource.filter = filterValue; - if (this.dataSource.paginator) { - this.dataSource.paginator.firstPage(); - } + Utils.applyFilter(event, this.dataSource); this.dataSource.filterPredicate = this.customFilterPredicate; }