I want to use the TreeGrid with DataProvider.
I follow the example of https://vaadin.com/components/vaadin-tree-grid/java-examples:
TreeGrid<Account> grid = new TreeGrid<>();
grid.addHierarchyColumn(Account::toString).setHeader("Account Title");
grid.addColumn(Account::getCode).setHeader("Code");
HierarchicalDataProvider dataProvider =
new AbstractBackEndHierarchicalDataProvider<Account, Void>() {
@Override
public int getChildCount(HierarchicalQuery<Account, Void> query) {
return (int) accountService.getChildCount(query.getParent());
}
@Override
public boolean hasChildren(Account item) {
return accountService.hasChildren(item);
}
@Override
protected Stream<Account> fetchChildrenFromBackEnd(
HierarchicalQuery<Account, Void> query) {
return accountService.fetchChildren(query.getParent()).stream();
}
};
grid.setDataProvider(dataProvider);
add(grid);
But it does’nt work for my Example. Is there anything missing in the code-snippet like setItems? Since, the dataProvider methods depends on query.getParent() but what about the root-Items? Where I have to fetch the root-items?
I hope you can help me.