Parent 1
|
|-Child 1
|- - Child 1_GrandChild1
|
|-Child 2
|
Parent 2
|
|-Child 1
|- - Child 1_GrandChild1
|- - Child 1_GrandChild2
|
|-Child 2
|
|-Child 3
|- - Child 3_GrandChild1
|
Parent 3
I want to sort this nested set structure in alphabetical order, parents should be sorted first and then the child and then the grandchildren.
This has already been implemented in awesome nested set gem in rails but it doesn’t give me the grandchildren in sorted order, only the parents are in sorted order. I also tried using order_column property in the model section but I got the same result - that parents were sorted but not the grandchildren. I also checked the question mentioned here and here but it was of no help. How can we approach this problem?
Edit: So it's an array of objects.
Input:
A
- C
- B
Output:
A
- B
- C
The problem is if I have grandchildren, the existing implementations do not sort it.