Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
How to check or unckeck a checkbox in all registers in table?
Cheers,
I'm new in Vaadin programming. I just want to know how i can check or uncheck all checkbox in table registers?
Sorry by my english. My natural language is spanish.
Thanks
tblInformacion = new Table();
tblInformacion.addContainerProperty("SEL", CheckBox.class, null);
tblInformacion.addContainerProperty("SUCURSAL", String.class, null);
tblInformacion.addContainerProperty("NIT", String.class, null);
tblInformacion.addContainerProperty("CODIGO", String.class, null);
tblInformacion.addContainerProperty("NOMBRE", String.class, null);
tblInformacion.addContainerProperty("SALDO", String.class, null);
int i = 1;
while (dataTable.next()) {
cbSel = new CheckBox();
tblInformacion.addItem(new Object[]{
cbSel,
dataTable.getString("SUCURSAL").trim(),
dataTable.getString("NIT").trim(),
dataTable.getString("CODIGO").trim(),
dataTable.getString("NOMBRE").trim(),
dataTable.getString("SALDO01").trim()
}, new Integer(i));
i++;
}
tblInformacion.setWidth("100%");
tblInformacion.setPageLength(20);
tblInformacion.setSelectable(true);
tblInformacion.setMultiSelect(true);
tblInformacion.setColumnCollapsingAllowed(true);
panelInformacion.addComponent(tblInformacion);
Hi Juan,
The checkbox is only checkeable when the table is in editable mode, so you should make the table editable, to do this you should add this line of code after your table creation:
tblInformacion.setEditable(true);
If you want to simulate the checkbox in your table, because you don't want an editable table, you can do it using some style in your theme and add a Boolean value in that column
For example, you can do this on your style:
.v-table-cell-content-true {
background-image: url("icons/ok.png"); // icon to represent checked status
background-repeat: no-repeat;
background-position: center;
text-indent: -30px; // To hide the true text
}
.v-table-cell-content-false {
background-image: url("icons/nok.png"); // icon to represent unchecked status
background-repeat: no-repeat;
background-position: center;
text-indent: -30px; // To hide the false text
}
And in the table generation, something like this:
tblInformacion = new Table();
tblInformacion.addContainerProperty("SEL", Boolean.class, null);
tblInformacion.addContainerProperty("SUCURSAL", String.class, null);
tblInformacion.addContainerProperty("NIT", String.class, null);
tblInformacion.addContainerProperty("CODIGO", String.class, null);
tblInformacion.addContainerProperty("NOMBRE", String.class, null);
tblInformacion.addContainerProperty("SALDO", String.class, null);
tblInformacion.setCellStyleGenerator(new MyCellStyleGenerator());
...
private final class MyCellStyleGenerator implements CellStyleGenerator {
private static final long serialVersionUID = 1L;
@Override
public String getStyle( Object itemId, Object propertyId )
{
Item item = (Item) itemId;
if ( "SEL".equals( propertyId ) ) {
return item.getItemProperty(propertyId).getValue().toString();
}
return "";
}
}
HTH.
Javi
Javier Serrano: Hi Juan,
The checkbox is only checkeable when the table is in editable mode, so you should make the table editable, to do this you should add this line of code after your table creation:
tblInformacion.setEditable(true);
If you want to simulate the checkbox in your table, because you don't want an editable table, you can do it using some style in your theme and add a Boolean value in that column
For example, you can do this on your style:
.v-table-cell-content-true { background-image: url("icons/ok.png"); // icon to represent checked status background-repeat: no-repeat; background-position: center; text-indent: -30px; // To hide the true text } .v-table-cell-content-false { background-image: url("icons/nok.png"); // icon to represent unchecked status background-repeat: no-repeat; background-position: center; text-indent: -30px; // To hide the false text }
And in the table generation, something like this:
tblInformacion = new Table(); tblInformacion.addContainerProperty("SEL", Boolean.class, null); tblInformacion.addContainerProperty("SUCURSAL", String.class, null); tblInformacion.addContainerProperty("NIT", String.class, null); tblInformacion.addContainerProperty("CODIGO", String.class, null); tblInformacion.addContainerProperty("NOMBRE", String.class, null); tblInformacion.addContainerProperty("SALDO", String.class, null); tblInformacion.setCellStyleGenerator(new MyCellStyleGenerator()); ... private final class MyCellStyleGenerator implements CellStyleGenerator { private static final long serialVersionUID = 1L; @Override public String getStyle( Object itemId, Object propertyId ) { Item item = (Item) itemId; if ( "SEL".equals( propertyId ) ) { return item.getItemProperty(propertyId).getValue().toString(); } return ""; } }
HTH.
Javi
Thanks for your help!!!!