Sorting children in TreeEditor?

10 views
Skip to first unread message

Daniel Farrell

unread,
Sep 2, 2022, 10:11:23 AM9/2/22
to Enthought Tool Suite users
Hello,

It is possible to sort the child order in TreeEditor?

The example here is very similar to my actual code,

For example, sorting the employees list by `name` or `title`?

Dan



Corran Webster

unread,
Sep 2, 2022, 10:27:59 AM9/2/22
to Enthought Tool Suite users
Hi Dan,

it's not supported out of the box, but you can implement it in one of two ways:
  • sorting things in the model (eg. having a trait that holds the sorted values and updates when either the list of children updates or the sort key updates; and use that as the children for the TreeNode)
  • implementing a TreeNode subclass so that it's get_children returns a sorted list (or, possibly, using one of the other ways of defining nodes as discussed here: in the TreeNode documentation)
The level of complexity will depend on how dynamic your tree is: if you need to support things like drag and drop on the tree it will be more complex, but if you are just displaying a static tree structure, or one which changes only occasionally, it should be fairly straight-forward.

Hope this helps,

-- Corran

Daniel Farrell

unread,
Sep 2, 2022, 11:01:58 AM9/2/22
to Enthought Tool Suite users
Hi Corran,

Thanks again! 

I will explore `get_children`, that route seems very promising.

Dan
Reply all
Reply to author
Forward
0 new messages