Thank you very much Leif for the explanation, but i really don’t get the filtering working with vaadin 8. There are one or two concepts i don’t understand yet and i try to explain why.
With Vaadin 7 i was able to generate a “generic” way to add and remove filter for the containers for every column in the grid.
private void addGridFilters() {
final HeaderRow filterRow = gridFacility.appendHeaderRow();
for (final Object propertyId : gridFacility.getContainerDataSource().getContainerPropertyIds()) {
final HeaderCell headerCell = filterRow.getCell(propertyId);
if (headerCell != null) {
if (!"idFacility".equals(propertyId) && !"facilityImageExists".equals(propertyId) && !"disabled".equals(propertyId)) {
headerCell.setComponent(createFilterTextField(propertyId));
} else if ("facilityImageExists".equals(propertyId) || "disabled".equals(propertyId)) {
headerCell.setComponent(createFilterComboBox(propertyId));
}
}
}
}
private TextField createFilterTextField(final Object propertyId) {
final TextField tfFilter = new TextField();
tfFilter.setInputPrompt(tp.getText(TextKey.VIEW_TEXTFIELD_FILTER));
tfFilter.addStyleName(ValoTheme.TEXTFIELD_TINY);
tfFilter.setWidth(100, Unit.PERCENTAGE);
tfFilter.addTextChangeListener(event -> {
final String text = event.getText();
bicGridFacility.removeContainerFilters(propertyId);
if (!text.isEmpty()) {
bicGridFacility.addContainerFilter(new SimpleStringFilter(propertyId, text, true, false));
}
bicGridFacility.sort(new Object { "facilityName" }, new boolean { true });
});
return tfFilter;
}
@SuppressWarnings("unchecked")
private ComboBox createFilterComboBox(final Object propertyId) {
...
}
So you see i was able to remove the container filter for an explicit property id and if the text of the filter field is not empty i am setting an new container filter. This was very easy and not complicated.
In Vaadin 8 i am not able to do this. I try to get this done in the same way but there are some obstructions.
[code]
private void addGridFilters() {
final HeaderRow filterRow = gridFunctionalAreaType.appendHeaderRow();
for (final Column<FunctionalAreaTypeDto, ?> column : gridFunctionalAreaType.getColumns()) {
final HeaderCell headerCell = filterRow.getCell(column);
if (“idFunctionalAreaType”.equals(column.getId())) {
headerCell.setComponent(createFilterTextField(column));
} else if (“functionalAreaTypeImageExists”.equals(column.getId())) {
// headerCell.setComponent(createFilterComboBox(headerCell.getColumnId()));
}
}
}
private TextField createFilterTextField(final Column<FunctionalAreaTypeDto, ?> column) {
final TextField tfFilter = new TextField();
tfFilter.setPlaceholder(tp.getText(TextKey.VIEW_TEXTFIELD_FILTER));
tfFilter.addStyleName(ValoTheme.TEXTFIELD_TINY);
tfFilter.setWidth(100, Unit.PERCENTAGE);
tfFilter.addValueChangeListener(event -> {
final ValueProvider<FunctionalAreaTypeDto, String> valueProvider = (ValueProvider<FunctionalAreaTypeDto, String>) column.getValueProvider();
listDataProviderFunctionalAreaType.addFilter(valueProvider, functionalAreaId -> {
return functionalAreaId.toLowerCase().contains(event.getValue().toLowerCase());
});
listDataProviderFunctionalAreaType.refreshAll();
});
return tfFilter;
}
[/code]I loop over the columns and get the headercell. and if its the right column i generate a textfield or a combobox. For this i have to sett an id for the column. This is a pity because i was hoping with vaadin 8 to do whitout a string in the class. In the create method i try to set with the valueprovider of the column the SerializablePredicate with addfilter.
The problem here is i can’t set in addfilter the Valueprovider directly with “column.getValueProvider()” because it returns “SerializableFunction<T, ? extends V>” and not a valueProvider. So i have to cast it. The other problem is i can’t remove a filter. i am missing “removefilter(ValueProvider<T, V> valueProvider)”. i only can call “clearFilters” for all filters. so the other filters won’t be active anymore.
So my question here is, am i missing some things or is my use case not possible in the moment? I think there are some methods missing to get this done!