TreeGrid and AbstractBackEndHierarchicalDataProvider

I want to use the TreeGrid with DataProvider.

I follow the example of

TreeGrid<Account> grid = new TreeGrid<>();
grid.addHierarchyColumn(Account::toString).setHeader("Account Title");

HierarchicalDataProvider dataProvider =
        new AbstractBackEndHierarchicalDataProvider<Account, Void>() {

    public int getChildCount(HierarchicalQuery<Account, Void> query) {
        return (int) accountService.getChildCount(query.getParent());

    public boolean hasChildren(Account item) {
        return accountService.hasChildren(item);

    protected Stream<Account> fetchChildrenFromBackEnd(
            HierarchicalQuery<Account, Void> query) {
        return accountService.fetchChildren(query.getParent()).stream();


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.

I added some Code like

public int getChildCount(HierarchicalQuery<Category, Void> query) {

                        CatalogProductDTO parent = query.getParent();

                              return service.getCategories().size();

  protected Stream<Category> fetchChildrenFromBackEnd(HierarchicalQuery<Category, Void> query) {
 if(parent == null){

and it works :slight_smile: