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.

TUTORIALVaadin lets you build secure, UX-first PWAs entirely in Java.
Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Calling javascript synchronously by Enver Haase, 2 weeks ago
Grid: set single header cell invisible?
Hi,
I just found a strange behavior in the Grid (using Vaadin 7.5.9).
The Grid should have filters for each coulmn, but for one column I want to set the filter to invisible.
Now the effect is, that not only the specified header filter is invisible, but more.
Is this a bug?
What do I have to do to set one single column filter to invisble?
Here is a simplified example:
import javax.servlet.annotation.WebServlet;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.annotations.Widgetset;
import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.data.util.filter.SimpleStringFilter;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Grid;
import com.vaadin.ui.TextField;
import com.vaadin.ui.UI;
import com.vaadin.ui.VerticalLayout;
/**
*
*/
@Theme("mytheme")
@Widgetset("ch.sic.MyAppWidgetset")
public class MyUI extends UI {
@Override
protected void init(VaadinRequest vaadinRequest) {
final VerticalLayout layout = new VerticalLayout();
layout.setMargin(true);
setContent(layout);
Grid grid = new Grid();
BeanItemContainer<ExampleListItem> container = new BeanItemContainer<>(ExampleListItem.class);
grid.setContainerDataSource(container);
grid.setColumnOrder("id", "service", "reference");
// Create a header row to hold column filters
Grid.HeaderRow filterRow = grid.appendHeaderRow();
// Set up a filter for all columns
for (Object pid: grid.getContainerDataSource().getContainerPropertyIds()) {
Grid.HeaderCell cell = filterRow.getCell(pid);
// Have an input field to use for filter
TextField filterField = new TextField();
filterField.setColumns(8);
// Update filter When the filter input is changed
filterField.addTextChangeListener(change -> {
// Can't modify filters so need to replace
container.removeContainerFilters(pid);
// (Re)create the filter if necessary
if (! change.getText().isEmpty())
container.addContainerFilter(
new SimpleStringFilter(pid,
change.getText(), true, false));
});
cell.setComponent(filterField);
}
Grid.HeaderCell reference = filterRow.getCell("service");
reference.getComponent().setVisible(false);
layout.addComponent(grid);
}
@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {}
}
public class ExampleListItem {
private Long id;
private String service;
private String reference;
public String getService() {
return this.service;
}
public void setService(String service) {
this.service = service;
}
public String getReference() {
return this.reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
}
Last updated on
You cannot reply to this thread.