Luca32
(Luca Mezzolla)
June 14, 2017, 1:59pm
1
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?
mcollovati
(Marco Collovati)
June 14, 2017, 2:55pm
2
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
Luca32
(Luca Mezzolla)
June 20, 2017, 11:21am
4
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"),
... ... ....
));
mcollovati
(Marco Collovati)
June 20, 2017, 7:09pm
5
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
I’m sure there will be better solutions; if I have some time I’ll think about it.
Best regards
Marco