Table refresh

Hello,

I have a table that the user can look at and edit in two different views, a basic and a more detailed view. There is a button to switch between the views and the buttonClick()-method just calls table.setVisibleColumns(…). The problem is that when the user clicks the button, the new columns are displayed, but the widths of the columns are kind of random and don’t match the specified widths. The weird thing: Once I highlight the table with the Vaadin debug tool, the table reloads and is displayed correctly. What is the problem here and how can I fix this?

Thanks, Matthias

Hi Matthias,

I couldn’t reproduce your problem. Toggling visible columns seems to work fine. Could you send a simple example code which shows your problem?

Okay here are some simplified parts of my code:

private void initTable() {
		table.setSortDisabled(true);
		table.setPageLength(5);
		table.setFooterVisible(false);
		table.setImmediate(true);
		table.setWriteThrough(true);
		table.setEditable(true);
		
		table.addContainerProperty(date, String.class, null);
		table.addContainerProperty(cf, String.class, null);
		table.addContainerProperty(val, String.class, null);
		table.addGeneratedColumn(twr, new TWRColumnGenerator());
		table.addGeneratedColumn(twracc, new TWRAccColumnGenerator());
		table.addGeneratedColumn(valbef, new ValueBeforeColumnGenerator());
		table.addGeneratedColumn(valmcf, new ValueMinusCfColumnGenerator());
		table.addGeneratedColumn(delta, new ValueChangeColumnGenerator());
		table.setVisibleColumns(new Object[] { date, cf, val, twr, twracc });

                table.setColumnWidth(date, 80);
		table.setColumnWidth(cf, 80);
		table.setColumnWidth(val, 80);
		table.setColumnWidth(twr, 80);
		table.setColumnWidth(twracc, 80);
		table.setColumnWidth(valbef, 80);
		table.setColumnWidth(valmcf, 80);
		table.setColumnWidth(delta, 80);

	}

This is the method I call at the beginning, to initialize the table. The methods in the buttonClickHandler look like this:


public void displayDetailedView() {
		table.setVisibleColumns(new Object[] { date, valbef, delta, valmcf, cf, val, twracc, twr });
	}

	public void displayBasicView() {
		table.setVisibleColumns(new Object[] { date, cf, val, twracc, twr });
	}

I’m not posting how I fill the table with data/how the columns are generated because that would be too much code. I hope this helps.

Thanks for the example. Now I was able to see where the problem is. For me, it seems a bug that the width of fixed sized column changes when it’s visibility changes. I created a
ticket
for it.

One workaround for the problem is not to set the column widths at all but set the width of the whole table and change it in displayDetailedView() and displayBasicView() -methods.

Thank you very much! Well I think the bug sometimes also occurs when I set the width of the whole table, but I’ll have to check that again.