table filter based on multiple properties

Hello vaadiners,

I am making an internal messaging system as a part of a bigger application

I have a table/grid filled with incomming messages and I would like to filter those messages only to show those which subject OR body contains the search term

I know addContainerFilter but with it I can only search in one property of the items in the table

How can I create a custom filter to fullfill my requirements?

The current Container.Filterable interface is really limited. What you could do is extend the container you are using and implement your custom filter API.

Thank you for your answer :slight_smile:

The problem temporarily solved in another way , in a longterm I m going to implement my own solution :slight_smile:

Hi Kim,
Do you have some example on creating my own filter?


Using 6.5.7
, I need to filter my container with 2 criterias as in search names like “patrick” OR “john”.

I need to modify the following method which is protected:

protected boolean passesFilters(Object itemId) {
    IndexedContainerItem item = new IndexedContainerItem(itemId);
    if (filters == null) {
        return true;
    }
    final Iterator<Filter> i = filters.iterator();
    while (i.hasNext()) {
        final Filter f = i.next();
        if (!f.passesFilter(item)) {
            return false;
        }
    }
    return true;
}


TO THIS :

protected boolean passesFilters(Object itemId) {
    IndexedContainerItem item = new IndexedContainerItem(itemId);
    if (filters == null) {
        return true;
    }
    boolean previouslyPassedFilter = false; 
    boolean PassesFilter = true; 

    final Iterator<Filter> i = filters.iterator();
    while (i.hasNext()) {
        final Filter f = i.next();
        if (!f.passesFilter(item) && !previouslyPassedFilter ) {
            passesFilter = false;
        } else  {
            previouslyPassedFilter = true;
        }
    }
    return passesFilter ;
}

How would that be done without having to rewrite all of these classes.

Thanks a lot.