How to erase blank spaces after column resizing

Hi,

I have a table with two columns as 1 in the attached screenshot. After resize Column NAME, there are blank spaces right (see 2). I try to erase spaces using following code segment:

        table.addListener(new Table.ColumnResizeListener() {

			@Override
			public void columnResize(ColumnResizeEvent event) {
				if (NAME.equalsIgnoreCase((String) event.getPropertyId())) {
					Table table = (Table) event.getSource();
					int dif = event.getCurrentWidth() - event.getPreviousWidth();					
					int width = table.getColumnWidth(SHORT);
					table.setColumnWidth(SHORT, width - dif);
					table.requestRepaint();
					//fireEvent(new Table.ColumnResizeEvent(table, SHORT, width, width - dif));
				}
			}
        	
        });

Both setColumnWidth() and fireEvent() do not work.

  1. Any idea to adjust column size of “SHORT”, so that it can cover the blank spaces?
  2. Track with Firebug, I can see runtime width and height of table or column, another question is whether I can get and change them in codes. And how?

Thanks,
Watt
11889.png

I know this post is pretty old but I am also wondering how this empty space can be removed / disabled / worked around / …
The OP was trying to make it’s own hack but maybe there is some clean way to get ride of that extra column.

Any thoughts ?

Do you mean resize the column by hand or from your code?

In any cases, with Vaadin, you should not try to calculate sizes on the server side. Using column expand ratios is usually the correct way to make some column expand to fill the space.

When a column has been resized manually, automatic size calculation (for it and possibly for other columns as well) is disabled - a behavior that some criticize (search the forum), but the main alternative becomes completely unusable in many scenarios with several columns.

In my case, I want to resize column width by code.

I also test the solution below, it doesn’t work:

        table.addListener(new Table.ColumnResizeListener() {

			@Override
			public void columnResize(ColumnResizeEvent event) {
				if (NAME.equalsIgnoreCase((String) event.getPropertyId())) {
					Table table = (Table) event.getSource();
					table.setColumnExpandRatio(SHORT, 1);
				}
				
			}        	
        });

As “automatic size calculation (for it and possibly for other columns as well) is disabled”, is there any alternative solution (not manual solution) to adjust column size for “specified” column? no blank space on right side.

If we refer to the screenshot, the problem is actually the following :
The sizer between columns “name” and “short” is good.
But the sizer between “short” and nothing (the kind of third column) should not exist, there is no content to display there and from a user point of view, feels like a bug.

6 years later, still having this issue in Vaadin 8 with new the Grid. Any ideas?

Still having this issue too. I have solved it using some code similar to the one posted before, where I set the width of the last colum manually. I just tried removing that piece of code, thinking that it would have been fixed in V8 so I would no longer need it, but it’s still broken. (I’m using 8.1.rc1).

It even happens in the online demo sampler (example here: https://demo.vaadin.com/sampler/#ui/grids-and-trees/grid/multi-select).

Can you post the piece of code that you used? I can not get this to work in V8.

Sure:

grid.addColumnResizeListener(event ->{ int lastColumnIndex = grid.getColumns().size()-1; ((Grid.Column)grid.getColumns().get(lastColumnIndex)).setWidth(1500); }); I just manually set the width of the last column to a big width when there’s a resize, it’s not the best solution but at least it looks better.