Sorting of tree implemented with NatTable

不打扰是莪最后的温柔 提交于 2019-12-08 04:08:50

问题


I'm trying to implement sorting of tree implemented with NatTable but I can't really understand how it works. My problem is that after the sorting of any column other than 'tree' column child nodes can move to invalid parent. Though the order of elements is correct on all levels of hierarchy. So basically I don't understand the purpose of TreeList.Format.getComparator() and how it related to comparators registred for the columns, and I don't understand when and why node can change its parent.

I've started with the example TreeGridExample and I've managed to create test data with which I have the same problem

private void createDatums() {       
    createDatum(null, "a", 2);        
    createDatum("a", "aa1", 0);        
    createDatum(null, "b", 0);        
    createDatum("b", "bb1", 0);
    createDatum(null, "m", 1);
    createDatum(null, "n", 0);
}

If I sort column bar, bb1 node jumps from b to n and when sorting removed, it again is child of b


回答1:


Your comparator need to take into account the tree hierarchy.

See here and here some more information.




回答2:


Regarding our example, maybe our SortableTreeComparator is not working correctly. And the answer is not trivial.

First, in order to make the TreeList work correctly you need to bring the elements in the list into the correct order. This is the tree comparator.

What you additionally want is to add a custom sorting on the lowest level. So in that case you need to extend your comparator to check for the tree level.

The reason why the parent changes is because your comparator changes the order in the collection and therefore breaks the whole tree structure.

We managed to make it work with the GroupBy feature in the GroupByComparator, but there we have the GroupByObjects in the list. And I remember it was hard work to get everything working together.

Please create a ticket to fix the SortableTreeComparator, not sure when I'm able to work on it.



来源:https://stackoverflow.com/questions/37105593/sorting-of-tree-implemented-with-nattable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!