Hi everyone,
we have the situation that we modify the grid by removing all columns and other things and then adding them again. We found out that when we call grid.setFrozenColumnCount(…) more than once the freezing becomes deactivated.
We are on Vaadin 8.4.2, testet with FireFox 61.0 64 bit on Windows 10.
I create a sample application demonstrating the problem. Screenshot one shows the first two columns frozen which is ok. Screenshot two shows the situation after clicking the “Reinit” button. Frozen state is gone.
Before clicking Reinit: https://ibb.co/c7NVbd
After clicking Reinit: https://ibb.co/mGzAbd
Here is the example code.
package com.example.responsive_test;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.annotation.WebServlet;
import com.vaadin.annotations.Theme;
import com.vaadin.annotations.VaadinServletConfiguration;
import com.vaadin.data.provider.ListDataProvider;
import com.vaadin.server.Responsive;
import com.vaadin.server.VaadinRequest;
import com.vaadin.server.VaadinServlet;
import com.vaadin.ui.Button;
import com.vaadin.ui.CssLayout;
import com.vaadin.ui.Grid;
import com.vaadin.ui.UI;
import com.vaadin.ui.components.grid.FooterRow;
import com.vaadin.ui.components.grid.HeaderRow;
/**
* This UI is the application entry point. A UI may either represent a browser window (or tab) or some part of an HTML page where a Vaadin application is embedded.
* <p>
* The UI is initialized using {@link #init(VaadinRequest)}. This method is intended to be overridden to add component to the user interface and initialize non-component functionality.
*/
@Theme("mytheme")
@SuppressWarnings("nls")
public class MyUI extends UI {
private HeaderRow headerRow = null;
private FooterRow footerRow = null;
private Grid<Person> grid;
private List<Person> persons;
private ListDataProvider<Person> dataProvider;
@Override
protected void init(VaadinRequest vaadinRequest) {
CssLayout mainView = new CssLayout();
mainView.setSizeFull();
setContent(mainView);
persons = new ArrayList<Person>();
persons.add(new Person("first a", "last a", 18));
persons.add(new Person("first b", "last b", 19));
persons.add(new Person("first c", "last c", 20));
grid = new Grid<Person>();
init();
mainView.addComponent(grid);
Button button = new Button("change frozen count");
button.addClickListener(event -> {
reInit();
});
mainView.addComponent(button);
Responsive.makeResponsive(this);
}
private void init() {
headerRow = grid.appendHeaderRow();
dataProvider = new ListDataProvider<Person>(persons);
grid.addColumn(p -> p.firstName);
grid.addColumn(p -> p.lastName);
grid.addColumn(p -> p.age);
grid.setFrozenColumnCount(2);
footerRow = grid.appendFooterRow();
grid.setDataProvider(dataProvider);
}
private void reInit() {
grid.removeAllColumns();
grid.removeHeaderRow(headerRow);
grid.removeFooterRow(footerRow);
grid.setFrozenColumnCount(-1);
init();
}
@WebServlet(urlPatterns = "/*", name = "MyUIServlet", asyncSupported = true)
@VaadinServletConfiguration(ui = MyUI.class, productionMode = false)
public static class MyUIServlet extends VaadinServlet {
}
private class Person {
String firstName;
String lastName;
int age;
public Person(String firstName, String lastName, int age) {
super();
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
}
}
}
Maybe I am missing something. If not is there a workaround available? If not I would like to file a bug ![]()
Best wishes
Stefan