I'm using NatTable to display a tree with multiple columns. The tree is flattened into a SortedList which is used to create TreeList.
EventList<Person> eventList = GlazedLists.eventList(perfStats.getFlattenedTree());
TransformedList<Person, Person> rowObjectsGlazedList = GlazedLists.threadSafeList(eventList);
SortedList<Person> sortedList = new SortedList<(rowObjectsGlazedList, null);
TreeList treeList = new TreeList(sortedList, treeFormat, TreeList.nodesStartCollapsed());
This works to display the tree. However, now my issue is how do I sort this properly?
The desired outcome would be for the roots to be properly sorted, then the children inside properly sorted independently and so on.
Right now, I'm using the GlazedListsSortModel and it sorts the flattened tree then builds the display from that which does not work.
Any help or just pointing me in the right direction would be appreciated!
When using a
TreeListyou pass in aComparatorfor the tree structure viaTreeList#Format. This is needed to ensure that the tree is created properly, as it is derivated from aList. So even if there is a sorting applied viaSortedList, theComparatorof theTreeList#Formatwill win in the end.To solve your requirement you therefore need to implement a
TreeList#Formatthat takes the column sorting into account. This can be done by using the NatTableSortableTreeComparatorfor example. You can have a look at our TreeGridExample to get an idea of how this could look like.A more extended version can be seen in the GroupByComparator that is used to support sorting by column with the GroupBy feature.