TreeGrid: how to get parent item

Hi all,

how exactly would one get the parent item in a tree grid?

I just found this explanation:

But I can’t figure out how to use the HierarchicalQuery to get the parent of e.g. the selected item.

Thanks in advance!

There doesn’t seem to be public API for this in the current implementation and the internal implementations are not just a trivial field access, so it might be best right now to keep that information in your items if that is an option for you.

The internal class HierarchyMapper is capable of finding the parent, but only has private methods for this. The method HierarchicalDataProvider.getParentIndex(int) is public, so the index in the current view can be obtained with treeGrid.getDataCommunicator.getParentIndex(T) if that helps, but it might not be very easy to consume as information.

If you have a good use case for querying the parent, you could
make an enhancement request

Thanks for the response Henri… I ended up saving the parents reference in each item, so querying the parent is not a must have for me.