按列从Firebase筛选表数据

问题描述 投票:2回答:1

我使用角度6,火力和材料角度。我可以将数据加载到表中,可以对它们进行排序,使用分页器并在全局范围内进行过滤]

我现在想修改我的过滤器,以使其仅在“名称”列中进行过滤,并在“普通”列中具有第二个过滤器字段进行过滤。

您能帮助我制定采用策略吗?

@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() {}
}
firebase-realtime-database filter angular-material mat-table
1个回答
1
投票

尝试以下代码:

ngOnInit() {
    this.dataSource.filterPredicate = function(data, filter: string): boolean {
      return data.name.toLowerCase().includes(filter) || data.nom.toString() === filter;
    };
  }
© www.soinside.com 2019 - 2024. All rights reserved.