Get all elements up (to the root) in HierarchicalDatasource

Hi all, I have a HierarchicalDatasource in a table and I need to get all the elements up (to the root), is there any function that returns all the elements above the current one?
Thanks and regards.

Hi,

Sorry for a long reply. You can use on of the HierarchicalDatasource interface methods, which match your needs:

  • HierarchicalDatasource#getParent - gets parent ID for item with the given ID
  • HierarchicalDatasource#getRootItemIds - identifiers of all root items
  • HierarchicalDatasource#getChildren - gets children IDs for item with the given ID
  • HierarchicalDatasource#isRoot - true if item with the given ID is a root item
  • HierarchicalDatasource#hasChildren - true if item with the given ID has children

There is no method, which returns all parents recursive, but you can write your own, using getParent and isRoot.

Regards,

Gleb.

Thanks Gleb for explaination.