Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Grid filtering not working
Hi,
I've followed this example: http://demo.vaadin.com/book-examples-vaadin7/book/#component.grid.filtering
But wih beanitemcontainer, now i've the following code:
HeaderRow headerRow = getGrid().appendHeaderRow();
for(final Object pid : getGrid().getContainerDataSource().getContainerPropertyIds()){
HeaderCell cell = headerRow.getCell(pid);
final TextField filterTextField = new TextField();
filterTextField.setInputPrompt("Filter");
filterTextField.addTextChangeListener(new TextChangeListener() {
@Override
public void textChange(TextChangeEvent event) {
beans.removeContainerFilters(pid);
if(filterTextField.getValue().equals(""){
beans.addContainerFilter(new SimpleStringFilter(pid, filterTextField.getValue(), true, false));
// tried also with
// ((BeanItemContainer<BeanP>) getGrid().getContainerDataSource()).addContainerFilter(new SimpleStringFilter(pid, filterTextField.getValue(), true, false));
}
}
});
cell.setComponent(filterTextField);
}
Textfields are OK, but grid filters nothing.
Can anyone help me?
Thanks
If I have understood your intention right, you have slight error with logic there. You are trying to set filter only when the text field is empty, hence having filter with no effect. You should add not-operator in your if-clause. I.e. if(!filterTextField.getValue.equals("") { ... }
Would highly recommend checking out the GridUtil addon:
https://vaadin.com/directory#!addon/gridutil
Thanks, but i'm on a project my manager give to me, and said me to not use addons.
I'ts working now:
HeaderCell cell = headerRow.getCell(pid);
final TextField filterTextField = new TextField();
filterTextField.setImmediate(true);
filterTextField.setInputPrompt("Filtre");
filterTextField.addStyleName(ValoTheme.TEXTFIELD_TINY);
filterTextField.addTextChangeListener(new TextChangeListener() {
private static final long serialVersionUID = 1L;
@Override
public void textChange(TextChangeEvent event) {
Filterable filter = (Filterable) getGrid().getContainerDataSource();
filter.removeAllContainerFilters();
if(event.getText().length() > 0){
filter.addContainerFilter(new SimpleStringFilter(pid, event.getText(), true, false));
}
}
});
cell.setComponent(filterTextField);
The real problem was i used
beans.addContainerFilter(new SimpleStringFilter(pid, filterTextField.getValue(), true, false));
instead of
filter.addContainerFilter(new SimpleStringFilter(pid, event.getText(), true, false));
Sometime I really not understand vaadin logic...
Two functions, normally the same result, but one say null
@Tatu Lund: Thanx, it was useful, even if the problem wasn't here, your save me an half of an hour!