Mat-table 按列过滤来自 Firebase 的数据
Mat-table Filter data from Firebase by column
我使用angular6、firebase和materialangular。我可以将我的数据加载到 table,我可以对它们进行排序,使用分页器,并全局过滤它们
我现在想修改我的过滤器,以便它只过滤 'name' 列,并有第二个过滤字段来过滤 'common' 列。
你能帮我看看采用的策略吗?
@Component({
selector: 'app-table',
templateUrl: './table.component.html',
styleUrls: ['./table.component.scss']
})
export class TableComponent implements OnInit {
showSpinner = true;
Data = {nom: '',finessgeo:'', cat1: '', commune: '',CP: '',departement:'',tel: ''}
displayedColumns = ['nom', 'finessgeo', 'cat1', 'commune', 'CP', 'departement', 'tel'];
dataSource = new MatTableDataSource();
applyFilter(filterValue: string) {
filterValue = filterValue.trim();
filterValue = filterValue.toLowerCase();
this.dataSource.filter = filterValue;
}
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
ngAfterViewInit() {
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
constructor(public authService: AuthService,private geoService: GeoService, private router: Router,private database: AngularFireDatabase) { }
onNewGeo() {
this.router.navigate(['']);
}
onSignOut() { this.authService.signOutUser(); }
ngOnInit() { return this.geoService.getGeos().subscribe(res =>{this.dataSource.data = res;this.showSpinner = false;}); }}
export class DataDataSource extends DataSource<any> {
constructor(private geoService: GeoService) { super() }
connect() {return this.geoService.getGeos();}
disconnect() {}
}
试试下面的代码:
ngOnInit() {
this.dataSource.filterPredicate = function(data, filter: string): boolean {
return data.name.toLowerCase().includes(filter) || data.nom.toString() === filter;
};
}
我使用angular6、firebase和materialangular。我可以将我的数据加载到 table,我可以对它们进行排序,使用分页器,并全局过滤它们
我现在想修改我的过滤器,以便它只过滤 'name' 列,并有第二个过滤字段来过滤 'common' 列。
你能帮我看看采用的策略吗?
@Component({
selector: 'app-table',
templateUrl: './table.component.html',
styleUrls: ['./table.component.scss']
})
export class TableComponent implements OnInit {
showSpinner = true;
Data = {nom: '',finessgeo:'', cat1: '', commune: '',CP: '',departement:'',tel: ''}
displayedColumns = ['nom', 'finessgeo', 'cat1', 'commune', 'CP', 'departement', 'tel'];
dataSource = new MatTableDataSource();
applyFilter(filterValue: string) {
filterValue = filterValue.trim();
filterValue = filterValue.toLowerCase();
this.dataSource.filter = filterValue;
}
@ViewChild(MatPaginator) paginator: MatPaginator;
@ViewChild(MatSort) sort: MatSort;
ngAfterViewInit() {
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
}
constructor(public authService: AuthService,private geoService: GeoService, private router: Router,private database: AngularFireDatabase) { }
onNewGeo() {
this.router.navigate(['']);
}
onSignOut() { this.authService.signOutUser(); }
ngOnInit() { return this.geoService.getGeos().subscribe(res =>{this.dataSource.data = res;this.showSpinner = false;}); }}
export class DataDataSource extends DataSource<any> {
constructor(private geoService: GeoService) { super() }
connect() {return this.geoService.getGeos();}
disconnect() {}
}
试试下面的代码:
ngOnInit() {
this.dataSource.filterPredicate = function(data, filter: string): boolean {
return data.name.toLowerCase().includes(filter) || data.nom.toString() === filter;
};
}