How to add a CheckBox for TreeTable

Hello,

I would like to display a TreeTable with CheckBox between “expand icon” and node. Does anyone have a simple solution?

Thanks,
Watt

You can just add like this or do you mean something different?


table.addContainerProperty("colA", CheckBox.class, "", "Column A", null, null);
table.addContainerProperty("colB", String.class, null, "Column B", null, null);
...
table.addItem(new Object[] { checkBox, stringValue }, itemId);

My TreeTable would look like the sample tree at http://demo.vaadin.com/book-examples/book/#component.tree.itemstylegenerator. Forget the checkboxes in the attached picture below, they are added manually.
12223.png

This can be achieved with my code. I do the same in a project of mine. Just set the caption of the checkbox

Could you give me some more details?

Something like this: (havent tested it)


TreeTable table = new Treetable("Select Awesome persons")
table.addContainerProperty("colA", CheckBox.class, "", "Column A", null, null);
table.addContainerProperty("colB", String.class, null, "Column B", null, null);
...
for(Person p : persons){
  Checkbox checkBox = new CheckBox("Caption");
  checkBox.setValue(person.isAwesome();
  table.addItem(new Object[] { checkBox, person.getName() }, p);
  for(Person child : p.getChildren()){
    Checkbox checkBox = new CheckBox("Aweseome");
    checkBox.setValue(child.isAwesome();
    table.addItem(new Object[] { checkBox, child.getName() }, child );
    table.setParent(child, p);
  }
}

Looks like this CSS trick doesn’t work for TreeTable as it does for Tree. It’s also very hard to do as the expand indicator is handled a bit differently in the HTML structure and the requestRepaint() does not seem to work with TreeTable.

But as Danny noted, TreeTable supports components in the tree column. I added an
example for that
.

Here is the solution:

        table.addGeneratedColumn(Constant.NAME, new Table.ColumnGenerator() {
			@Override
			public Object generateCell(Table source, Object itemId, Object columnId) {
				CheckBox checkbox = new CheckBox(itemId.toString());
				return checkbox;
			}        	
        });