Reputation: 1645
In my Vaadin 7 project, I need to ignore the parent nodes(rows) of a treetable while sorting. I am able to customize the sort using ItemSort, but I don't know how to skip the parent nodes!
FYI: I am able to identify my parent node with its ItemId.
***Update***
I'm using a Hierarchical Container, and my Tree is similar to this:
Name Nos salary
+ Male(Node 1) 5 $12000
+ Young 3 $6000
A 1 $3000
B 1 $1000
c 1 $2000
+ Old 2 $6000
A 1 $3000
B 1 $3000
+ Female(Node 2)5 $13000
+ Young 3 $5000
A 1 $2000
B 1 $1000
c 1 $2000
+ Old 2 $8000
A 1 $5000
B 1 $3000
The problem is when I sort the salary column it includes the summation of each person's salary on "Male, young & old", "Female, young & old" rows and adjusts the position of "Male, Female" and "Young, old" categories.
I just want to skip the parent nodes in my custom sort. It should only the children nodes. In simple words. All the parent nodes should be fixed, and only the child nodes have to be sorted.
Updated USECASE
Two elements having same parents and those two elements has no child nodes then I used DefaultItemSorter.compare(). And I ignored all other use cases.
Upvotes: 2
Views: 1953
Reputation: 2456
I had a related Problem, with special tree table sorting. I ended up writing my own Container and Comperator implementation.
Your question depends on the container you are using, since the sorting is done by the the underlying container and not the table. By default TreeTable uses the HierarchicalContainer implementation, where you could use your own ItemSorter implementation. You could extend DefaultItemSorter and distinguish different cases when comparing two elements:
I hope i didn't forget a case. Anyway I advise you to write several unit tests to be sure your ItemSorter does the right thing in all the cases.
If you know that your tree has special characteristics, like the maximal depth is two, you might simplify the ItemSorter. I couldn't see that from your question. Please add more details next time.
Upvotes: 1