Your example works indeed, but it does not use hierarchical data. Please check out the following:
TreeGrid<Test> foo = new TreeGrid<Test>(Test.class);
foo.removeAllColumns();
foo.addColumn("s1");
foo.addComponentColumn(this::getFoo).setHeader(new Span("Header Component")).setId("someID");
foo.addColumn("s3");
TreeDataProvider<Test> dataProvider = (TreeDataProvider<Test>) foo.getDataProvider();
TreeData<Test> data = dataProvider.getTreeData();
foo.setHierarchyColumn("s1");
Test a = new Test("A", "Parent", "bla");
Test b = new Test("B", "Parent", "blo");
Test a1 = new Test("A", "Child", "blu");
data.addItem(null, a);
data.addItem(null, b);
data.addItem(a, a1);
public class Test {
String s1;
String s2;
String s3;
public String getS1() {
return s1;
}
public void setS1(String s1) {
this.s1 = s1;
}
public String getS2() {
return s2;
}
public void setS2(String s2) {
this.s2 = s2;
}
public String getS3() {
return s3;
}
public void setS3(String s3) {
this.s3 = s3;
}
public Test(String s1, String s2, String s3) {
super();
this.s1 = s1;
this.s2 = s2;
this.s3 = s3;
}
}
public Component getFoo(Test s) {
Div div = new Div();
div.setText("My text: " + s.s2);
return div;
}
The Component column does not show up. Maybe I’m doing something wrong here, and you can give me a hint?
You should set the hierarchy column before adding the component column. Apparently setHierarchyColumn removes and recreates all the columns, but fails to rebuild the component column in the process. I get the component column to appear if I move the foo.setHierarchyColumn("s1"); line right below foo.addColumn("s1");.