How to use more than one filter? (search bar + select box)

Hello everyone!

I read this post and I’m trying to implement two different filters (searchbar/selectbox) in the same view but I didn’t find a solution yet.

Any ideas?

I did something like this…

in your html use:

<ion-item ng-repeat="news in vm.getListNews() | filter: vm.combofilter">

and in the controller:

function combofilter(elem) {
	var pass_categ= true;
	var pass_search= true;
  	if ( vm.getShowCateg() > 0 ) {
  		if ( elem.id_categ != vm.getShowCateg() ) {
  			pass_categ= false;
  		}
  	}
  	if ( vm.searchKey ) {
  		if ( elem.title.toLowerCase().indexOf(vm.searchKey.toLowerCase()) == -1 ) {
  			pass_search= false;
  		}
  	}
	return pass_categ && pass_search;  		
}

In the view, I’ve a search field and a list of categories. Search field is linked to vm.searchKey and the list of categories are linked to vm.getShowCateg.
This is a slice of a real app, modified to show an example of implementation, but should works :smile:

2 Likes

Thanks a lot Fabio!

I thought I had to implement two filters in the view, but your solution seems to be a lot better!

but remember that every filter decrease your app performance

1 Like