0

I want a particular desired behavior for my Nattable tree structure. In the following diagram, contents of Row no 36, 37 are children of content in Row 20.

Row 21, 23, 23 … 34 are in turn children of Row 20.

Row 22 is a child of Row 21. (you could say it is grandchild of 20)

I want Row 36, 37 to be shown first ie. In place of Row 21 and so on, that is I want to change the order in which it is shown as a child of Row 20.

I am currently using a treelist implementation to render my data in the Nattable.

My current nattable: My current nattable

 private List<ISectionInfo> getFlatList(List<ISectionInfo> inputList)
 {
     List<ISectionInfo> flatList = new ArrayList<ISectionInfo>();

     for (ISectionInfo node : inputList)
     {

         if (node instanceof SectionInfo) 
         {
             SectionInfo secNode = (SectionInfo) node;

             if (!hasChildren(secNode))
             {
                 flatList.add(secNode);
                 flatList.addAll(secNode.getModuleInfoList());

             }
             if (hasChildren(secNode))
             {
                 flatList.addAll(secNode.getModuleInfoList());
                 flatList.add(secNode);

                 for (ISectionInfo iternode : secNode.getChildren())
                 {
                     flatList.addAll(((SectionInfo) iternode).getModuleInfoList());
                     flatList.add(iternode);

                 }

             }
         }

     }

     return flatList;

 }
greg-449
  • 109,219
  • 232
  • 102
  • 145
  • If the question really is how to show the "grandchildren" before the child nodes, well I suppose that is not possible because this is not how a tree works. – Dirk Fauth Jan 06 '23 at 14:03
  • I want to change the order in which the children are shown. Here Row 21 and Row 36,37 are same level children. I wish to change that order. The grandchild would be shown as the relevant parent's child, so the concern isn't about it. – Sridhar Kumar Jan 07 '23 at 03:40
  • Are you using GlazedLists TreeList? Then you need to use a tree comparator as shown in the examples. – Dirk Fauth Jan 07 '23 at 06:55
  • Yes, my code uses GlazedLists TreeList. The closest I could find as an example was 6041 `TreeGridExample` and 6042 `TreeStructureGridExample`. I am using a `SortableTreeComparator` in my `TreeDataFormat`. This comparator in turn uses a treeComparator which sorts alphabetically on the first column – Sridhar Kumar Jan 08 '23 at 11:58
  • Yes, if you want a different order you need to implement a custom comparator that is doing what you want – Dirk Fauth Jan 08 '23 at 18:08

0 Answers0