Hello,
I am having trouble with the Deleting Button and generating of Checkboxes in my table. I have been using some examples from the forum but i couldn’t manage to make it work. I would appreciate some help
Thank you!
BR, Elena
The button code is:
delete = new Button("Delete");
delete.setVisible(true);
delete.addClickListener(new Button.ClickListener() {
@Override
public void buttonClick(ClickEvent event) {
List<Object> toDelete = new ArrayList<Object>();
treeTable.addContainerProperty("Checkbox", CheckBox.class, null);
treeTable.addContainerProperty("String", String.class, null);
for (int i = 0; i < 10; i++) {
Object id = treeTable.addItem();
treeTable.getContainerProperty(id, "Delete").setValue(new CheckBox());
treeTable.getContainerProperty(id, "String").setValue("row " + id);
}
for (Object id : treeTable.getItemIds()) {
// Get the checkbox of this item (row)
CheckBox checkBox = (CheckBox) treeTable.getContainerProperty(id, "Delete").getValue();
if (checkBox.booleanValue()) {
toDelete.add(id);
}
}
// Perform the deletions
for (Object id : toDelete) {
treeTable.removeItem(id);
}
Notification.show("Removed row", "",Notification.Type.WARNING_MESSAGE);
}
});