Grid : dealing with default checkbox column

Hello there,

I’m really, really new to Vaadin, and I’m just starting enjoying its flavor… I’m dealing with a grid, basic , supposed to provide 3 columns, whose one should display checkboxes, one for each row, to be then wired to a “delete button”, sort of what is taught in
Figure 5.56. Multiple Selection in Grid
(
https://vaadin.com/book/vaadin7/-/page/components.grid.html
).
So I’m using :
reportsList = new Grid();
blablabla
reportsList.setSelectionMode(SelectionMode.MULTI);
My question is : is there a way to set the checkbox column another place than the default very left side of the grid, preferably, on the right side, (as 3rd column, counting from left) ; and then implement the delete button in its header ?

Regards,

Hi Carlino. Unfortunately the Checkbox column which is shown in when the Grid is in multi select mode isn’t configurable so that you could move it… But luckily for your purpose there is an
addon available
which enables you to have checkboxes in another column by using Renderers. You may also
build your own
renderer.

Thanx a lot Pekka for your answer ; I’m gonna have a glance right away at your suggestion.

more I know about Vaadin, more I understand that has nothing to do with Java and Swing or even HMLT5, all UI components has so many lacking of features, If this Grid is the successor of Table, this framework is getting worse on every release.

In Tables you can’t just create a checkbox column editable, u have to make all the table editable and that change the look of every cell and column AND in this Grid, u can’t place this so needed checkbox on the RIGHT SIDE, where most application design had it.

Hi,
Is there any change in this behavior in Vaadin 8.1, out of the box? My intent is to keep the “Check-box Column” to the very right of the Grid and I do want to avoid any add-ons.

Try this:

//Add your Checkbox inside grid
grid.addComponentColumn(m_customer -> {
	Checkbox m_checkbox = new Checkbox();
	m_checkbox.setValue(m_customer.isAnwesend());

	m_checkbox.addValueChangeListener(event -> {
		editor.changeIsAnwesend(m_customer);
	});

	return m_checkbox;
})
		.setHeader("Anwesend")
		.setSortable(true);

or this:

//Add the Checkbox inside grid
 grid.addColumn(new ComponentRenderer<>(Checkbox::new,
		(_checkbox, _customer) -> {
			_checkbox.setValue(_customer.isAnwesend());

			_checkbox.addValueChangeListener(event -> {
				editor.changeIsAnwesend(_customer);
			});
		})
)
		.setHeader("Anwesend")
		.setSortable(true);