用NatTable实现的树排序 [英] Sorting of tree implemented with NatTable

查看:130
本文介绍了用NatTable实现的树排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试对通过NatTable实现的树进行排序,但是我真的不明白它是如何工作的.我的问题是,在对除"tree"列之外的任何列进行排序之后,子节点可以移至无效的父节点.尽管元素的顺序在层次结构的所有级别上都是正确的.因此,基本上我不了解TreeList.Format.getComparator()的目的以及它与为列注册的比较器之间的关系,并且我也不了解节点何时以及为什么可以更改其父级.

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);
}

如果我对列bar进行排序,则bb1节点将从b跳到n,并且当删除排序时,它又是b的子代

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

推荐答案

对于我们的示例,也许我们的SortableTreeComparator无法正常工作.答案并不简单.

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

首先,为了使TreeList正常工作,您需要将列表中的元素置于正确的顺序.这是树比较器.

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.

我们设法使其与GroupByComparator中的GroupBy功能一起使用,但是列表中有GroupByObjects.而且我记得要使所有事情一起工作是艰苦的工作.

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.

请创建故障单以修复SortableTreeComparator,不确定何时可以使用它.

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

这篇关于用NatTable实现的树排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆