Tree views / Usage |
When a huge tree needs to be displayed, tree data filling can be optimized by creating the nodes on demand. There is no need to fill the complete program array with all possible nodes (down to the last leaf), when only the first levels/branches of the tree are displayed on the screen.
To implement a dynamically filled tree, first define an additional column in the TREE container, to indicate whether a given node has children. That field will be used to render a node with a [+] button, and let the end user click on the node to expand it, even if no child nodes are created yet.
DEFINE row_index INTEGER ... DISPLAY ARRAY tree_arr TO sr.* ATTRIBUTES(UNBUFFERED) ON EXPAND (row_index) DISPLAY "EXPAND - Expanded row is: ", row_index -- Fill with children nodes for tree_arr[row_index] ON COLLAPSE (row_index) DISPLAY "COLLAPSE - Collapsed row is: ", row_index -- Remove children nodes of tree_arr[row_index] END DISPLAY
The program array can be filled directly before the dialog execution, but once the dialog has started, use dialog methods such as DIALOG.insertNode() to modify the tree, otherwise secondary data information like multi-range selection and cell attributes will not be synchronized. This is typically the case when implementing a dynamically-filled tree with ON EXPAND/ ON COLLAPSE triggers.