Compare Equals (2 values)

Hello,
I need help to filter a column by a text and an empty field.

Container.Filterable filter = (Container.Filterable) (table.getContainerDataSource());
filter.removeAllContainerFilters();
Compare.Equal equal = new Compare.Equal(column, "text");
filter.addContainerFilter(equal AND "");

Any suggestions please?

I think what you need is an OR condition, not AND

Try with

filter.addContainerFilter(new Or(
    new Compare.Equal(column, "text"), 
    new Compare.Equal(column, "")
));

HTH
Marco

Grande, funziona! :slight_smile:

Is it possibile add conditions dinamically to And or Or?
I have 3 checkbox to filter one column and others 3 to filter the second column.
Now, I need to build the object And to filter the table.
For example:

Container.Filterable filter = (Container.Filterable) (table.getContainerDataSource());
filter.removeAllContainerFilters();
filter.addContainerFilter(new And(
    new Compare.Equal("column", "value1"),
    new Compare.Equal("column", "value2"),
    new Compare.Equal("column", "value3"),
    ... ... ....
));

The first thing that comes in mind to me is to create a filter for each checkbox and then add or remove it in value change listener.

final Container.Filterable filter = (Container.Filterable) (table.getContainerDataSource());

Filter f1 = new Compare.Equal("column", "value1")
Checkbox c1 = new Checkbox(...)
c1.addValueChangeListener(e -> if (c1.getValue()) { filter.addContainerFilter(f1); } else { filter.removeContainerFilter(f1); } );

Filter f2 = new Compare.Equal("column", "value2")
Checkbox c2 = new Checkbox(...)
c2.addValueChangeListener(e -> if (c2.getValue()) { filter.addContainerFilter(f2); } else { filter.removeContainerFilter(f2); } );

The code above should obviuosuly be improved to reduce duplication :smiley:

I’m sure there will be better solutions; if I have some time I’ll think about it.

Best regards
Marco