I'm facing a challenge with my MatTable
component where I need to filter the data using previously stored values
from user input. While I can verify that the values match the data, I'm unsure of how to apply filtering without relying on the filterPredicare
, as using another method leads to duplication issues.
Below is my implementation within the NgOnInit
component:
ngOnInit() {
this.marinService.getAllContainers().subscribe((result) => {
//Data
this.dataSource = new MatTableDataSource(result);
//Paginator
this.dataSource.paginator = this.paginator;
//AutoFilter Form 1st page
this.clientType = this.route.snapshot.queryParamMap.get('clientType');
this.storageType= this.route.snapshot.queryParamMap.get('storageTypes');
console.log('The Client name is : '+this.clientType+' '+'The storage Facility is :'+this.storageType);
this.tableFilter();
//snapShot Filter
//CheckBoxFilter
this.dataSource.filterPredicate = (data: Container, filter: any) => {
return filter.split(',').every((item: any) => data.SOG_MCOLH.indexOf(item)!== -1);
};
this.filterCheckboxes.subscribe((newFilterValue: any[]) => {
this.dataSource.filter = newFilterValue.join(',');
});
});
}
Here's the custom function
for filtering:
tableFilter(){
var data : Container = this.dataSource;
var newData: any[];
if(data.LQOCH_SHM_LOEZI_QTSR === this.clientType){
console.log(data.LQOCH_SHM_LOEZI_QTSR);
}else{
console.log("Hi Not working")
return this.dataSource;
}
}
Although I attempted to replicate the filtering logic used in the filterPrediacte
, it proved unsuccessful.