In Vaadin instance, the coding
grid.addColumn(new NativeButtonRenderer<>(“Button”))
.setHeader(“Action”);
Add a button in Grid column. But if I want to add a checkbox or combobox into grid, which class can be used?
Many thanks.
Hi, apparently you seem to use Flow and Vaadin Platform. I recommend you to check section Using Components with Grid here
https://vaadin.com/docs/v11/flow/components/tutorial-flow-grid.html
It does not have example for CheckBox, but has example for TextField and Button. CheckBox and ComboBox usage should be analogous to TextField.
I found that in Vaadin 14 if you try something like this:
grid.addColumn(person -> {
Checkbox checkbox = new Checkbox();
checkbox.setValue( person.hasFiles() );
return checkbox;
}).setHeader("Has Files").setKey("hasFiles");
you will see that the column doesn’t render and will see something like this for each row:
com.vaadin.flow.component.checkbox.Checkbox@47436d14
to fix that, you only need to wrap the checkbox component into a ComponentRenderer like this
grid.addColumn(
new ComponentRenderer<>(
person -> {
Checkbox checkbox = new Checkbox();
checkbox.setValue( person.hasFiles() );
return checkbox;
}
)
).setHeader("Has Files").setKey("hasFiles");