Changing frozen columns in Grid deactivates frozen columns

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 :slight_smile:

Best wishes
Stefan

Hi, Stefan!

I think you’ve hit the issue depicted [here]
(https://github.com/vaadin/framework/issues/10653), so no need to file a bug. I’ve been meaning to look into this for a week now, but seem to get sidetracked all the time. But I’ll keep this one in the backburner, maybe I’ll figure something out.

-Markus

Hi Markus,

thanks for looking at this issue. I know you had a lot of work to do with Vaadin 10 but from the GitHub entry I can see this problem is known for months now. Would be nice to have a fix for this in the nearer future.

Best wishes
Stefan

Checking the row count before setting the frozen count worked for me on Vaadin 8.5.
https://github.com/vaadin/framework/issues/10653#issuecomment-449451978

Hi there,

sorry for the delay, I was away for a couple of weeks.

Apparently you found a workaround for this already, but I suppose it would be a good idea to implement some further checks to the fix so that NPEs could be avoided.

Do you have a small sample UI which recreates the error? It would greatly simplify the process of eliminating the issue.

-Markus

Hi Markus,

Unfortunately, I don’t have any sample but the reproduction is easy. Set the frozen column count to 1, try to update the data provider with no data, and then try updating it with some data and you will see that the column freeze is gone.

Not related to this thread but is there any way to freeze columns from right at the same time too?

Here is a minimal example for reproducing the NPE:

https://github.com/vaadin/framework/issues/10653#issuecomment-454795622

I finally managed to free up enough time to fix the NPE issue and create tests for it. The pull request is in verification, hopefully it doesn’t break.

Not related to this thread but is there any way to freeze columns from right at the same time too?

No, frozen columns are always on the left. I don’t think something like this would be doable even with an extension, unfortunately.

-Markus

Any predictions for solving the problem?

The fix is coming out in Vaadin 8.7.1 maintenance release (most likely next week)

https://github.com/vaadin/framework/pull/11444