This article outlines options available for ordering nodes, including supplied controls and programmatic method. There is detail supplied of standard rules for ordering in place, with a more detailed worked example at the end
Ordering: Standard Rules
- The default structure of a given displayed hierarchy is built based on the pasted data depth first, top to bottom (lowest depth [1] to highest depth)
- All standard Tree Views display nodes at a given level adjacent to other nodes at the same level e.g. all level 2s on the same horizontal
- The default ordering of sibling nodes, before any subsets are applied, will be by ID ascending
- Ordering set in Trunk datasets is retained on save.
- The order of sibling nodes cannot be saved in a branch; only reparenting (before/after) can be saved in branch views. (Whilst you are able to manipulate sibling order in a branch, when you try to save the branch, the sibling order reverts to that in the trunk.)
Ordering: UI Controls
There are supplied interactive visual controls, available within tree views, to determine order:
- multiple controls are available by clicking on the node, including before, after, promote, demote
- dragging and dropping in tree view triggers an alternate dialogue for managing ordering
Ordering: Advanced Sort Using Expressions
There is general coverage of expression-based sort here, however if working with a Tree View an expression will have typically three elements e.g. in this expression
nodes().sort("department").setSortOrder()
1 | select all nodes |
nodes() |
2 | select sort property |
sort("department") |
3 | set the _sortOrder property of the nodes, which is only used for sibling ordering [visually] |
setSortOrder() |
When running an expression to set sort order visually, ensure before you proceed that
the dataset is free from any filtering or similar (pagination) before applying the sort function documented here, as it needs to run on the whole dataset.
Ordering with Expressions: Worked Example
In this simplified example, the required output is that siblings should be ordered by full name, in reverse order: the correct expression to apply should be:
nodes().sort("full name", "desc").setSortOrder()
First, ensure the sort order works as desired using Expressions Manager and check the sort order is correct for the sort-property using
nodes().sort("full name", "desc")
Once verified, 'fix' the sort order by adding .setSortOrder() to Expression Manager, ensure expression is run in Macro mode
nodes().sort("full name", "desc").setSortOrder()
No change will be visible at this point - click refresh button (circular arrow)
Save to retain settings ... and at this point you can run additional subsetting operations e.g. filter, paginate with the required ordering embedded.
Ordering: Combined Multiple Method
It is possible to use a range of differing sort criteria across a hierarchy. To do this you need to work from the top level down. Determine which elements of the hierarchy you wish to sort in a particular way, make selections in the Filter control so that those elements appear on the canvas or in the worksheet, then run the required
setSortOrder()
expression in Macro mode, refresh the screen, then move onto the next (lower or same level) part of the hierarchy.
If at any time you need to sort nodes in a particular sequence which can't be achieved using a regular 'sort' expression, then it is possible to define the precise sequence. Use an expression of this format : -
nodes().sort(n => ["Molly White", "Bill Bloggs", "Mia Tomlinson"].indexOf(n.fullName.value)).setSortOrder()
This expression will sort the selected nodes in the indicated sequence. This method should not include large arrays as that will adversely affect performance.
Comments
0 comments
Please sign in to leave a comment.