Pagination treedatagrid last item cannot be opened

Hi
I’ve created a small sample project here.

User now has a superUser so we can use treeDataGrid. And I’ve added pagination with 2,10,50 items per page to demonstrate (default 10).

When opening the view the second user initially has a subUser. But when changing pagination to 2, I’m not able to see the subUser anymore. Also it won’t appear on second page. I didn’t test this on larger projects, but I’m afraid the last one per page cannot be opened.

Further, after changing pagination to 2 the info label only says ‘1-2 rows of’ without total count.
This issue is not limited to treeDataGrid — it seems to occur in general with simplePagination.
This only happens when, on the initial view load, the total number of loaded entities fits into a single page (i.e. there is no need to paginate initially).
If, on the initial load, enough entities are returned so that pagination is required immediately (multiple pages exist right away), the label is rendered correctly and continues to work as expected.

Jmix Version 2.7.4

Do you have suggestions how I can handle this behavior?
Best regards
Stefanie

Hello Stefanie!

Technically, you see 2 problems.

First and main problem: your data is loaded as a flatten list; it does not consider the order of hierarchy. For instance, your database contains the following data order in a table:

  1. Root 1
  2. Sub entity 3, a child of Root 2
  3. Root 2
  4. Sub entity 1, a child of Root 1
  5. Sub entity 2, a child of Root 1
  6. Sub entity 4, a child of Root 2

When your page size is 2, a loader will load:

  1. Root 1
  2. Sub entity 3, a child of Root 2

Since Sub entity 3 is not a child of Root 1, it won’t be displayed by default. This is why you see only one item.

The second problem: when a child item does not have a loaded parent, it won’t be displayed. In this case, you should set showOrphans="true" for the TreeDataGrid.

In general, it is not recommended to use TreeDataGrid with SimplePagination (see showOrphans attribute, treeDataGrid :: Jmix Documentation).

I can suggest the following solutions:

  • If you have small data, load all items and set allRowsVisible="true" for the TreeDataGrid.
  • Use lazy loading when a node is expanded: UI samples :: TreeDataGrid with lazy nodes.
  • Somehow sort the loaded data considering the hierarchy before setting it to the TreeDataGrid.