1

Just implemented the new Container.Filter using this code:

Filter f  = 
new Or(new SimpleStringFilter(Columns.SEARCH.id(), "rpm-diastolic", true, false),  
new Or(new SimpleStringFilter(Columns.SEARCH.id(), "rpm-systolic", true, false)),
new Or(new SimpleStringFilter(Columns.SEARCH.id(), "rpm-weight", true, false))) ;
container.addContainerFilter(f);

and works fine.

Now I would like to use the following in order to build as many criterias I would need by building dynamically the filter:

List<String> filters;
for(String filter : filters) {
    Filter f  = new Or(new SimpleStringFilter(Columns.SEARCH.id(), filter, true, false) );
    container.addContainerFilter(f);
}

How can I do this for this code doesn't work...

Pat B
  • 1,915
  • 23
  • 40

1 Answers1

1

OK,

I was able to do this by simply passing an array to the Or constructor this way:

Filter[] filtersToAdd = new Filter[filters.size()];
for(String filterString : filters) {
filtersToAdd[i++] = 
    new Or(new SimpleStringFilter(Columns.SEARCH.id(), filterString, true, false));
}
Filter f = new Or(filtersToAdd);
container.addContainerFilter(f);
Pat B
  • 1,915
  • 23
  • 40
  • I want to apply multiple Filter on same column. Is it valid or not? I tried, its only work when 1 filter is applied. I am trying to use multiple filter with `And (Container.Filter... filters)`. I am not getting any errors, but it seems when there are more filters , container is not getting filtered. – Parth Vishvajit Aug 02 '16 at 14:23
  • My code is just like the same, difference is I am using `And` instead of `Or` and `Compare.Equal` instead of `SimpleStringFilter`. I want to apply Filters for multiple values but on a same column. [Note: Between is not useful in my case because There isn't any range in what I am comparing.] So, I am making multiple Filters for same column but with different values in each filter. [Note: I am also wrapping this each filter with `Not` filter, as I am collecting the values which I don't want to display. Because those are less in compare what I want to display. ] – Parth Vishvajit Aug 04 '16 at 11:11
  • You will need to use the Or in this case... otherwise you will get 0 returned objects. if your column contains (cat, mouse, dog) and you use And filters, your column will never be equal to "dog" AND "mouse" at the same time... – Pat B Aug 04 '16 at 19:38
  • ya. I got this problem later. So now I am adding each filter ,with different column value, separately, with loop. I mean I am just simply creating filter in loop and adding it to Filterable Container. But how can I achieve this with `Or` ? I want to hide all these specific values. It will also be helpful if you can tell about the which code is efficient and how. Thanxx. – Parth Vishvajit Aug 05 '16 at 05:08