Overview
Syntax: treelayer(TreeObject, Int, Boolean, String).
Definition: to return the value at the No.n level of a tree object (usually a tree dataset, a drop-down tree, or a view tree). You can set the type of the returned value and the separator.
Explanation
Object | Value | Definition |
---|---|---|
TreeObject | Tree object | For example: $tree |
Int | Value of the aimed level | 1 for the top level, 2 for the second level, with each subsequent layer following this numerical sequence. With a null value, the function returns the value at the bottom level. |
Boolean | Type of the returned value | false: to return an array (the default value) true: to return a string |
String | Separator of the returned string | Value in double quotes (the comma by default): "," |
Example
This example explains the role of the TREELAYER function by displaying the department hierarchy in the FRDemo database with a drop-down tree widget.
Dataset Creation
Database Query Creation
Create a general report, and enter the SQL statement SELECT * FROM department to create a dataset ds1, as shown in the following figure.
Tree Dataset Creation
Create a tree dataset named Tree1, select the dataset ds1, set Original Tag Field to did, and set Parent Tag Field to fid, as shown in the following figure.
Dataset Preview
Preview the effect of the tree dataset, as shown in the following figure.
Widget Adding
Add two widgets on the parameter bar: a drop-down tree widget and a text widget, as shown in the following figure.
Drop-down Tree Widget
Modify the name of the drop-down tree widget to tree. Select Multiselect and Return Full Hierarchical Path.
Select Automatic Creation as the value of Data Dictionary, select Tree1 as the value of Tree Dataset to Build, and select department as Actual Value and Display Value, as shown in the following figure.
Text Widget
Select Formula and enter the formula treelayer($tree, true, "\',\'") for Widget Value, as shown in the following figure.
Effect Display
Save the template, click Pagination Preview, choose Headquarter > Human resources department > Human resources clerk, and choose Marketing department > Clerk, as shown in the following figure.
According to the formula field in the text widget, the returned value and the separator in preview differ, as shown in the following table.
Formula | Returned Value | Separator | Illustration |
---|---|---|---|
treelayer($tree, true, "\',\'") | Human resources clerk Clerk | ',' | ![]() |
treelayer($tree, 2) | Human resources department Marketing department | , | ![]() |
treelayer($tree, 2, true, "\',\'") | Human resources department Marketing department | ',' | ![]() |
Template Download
For details, you can download the template TREELAYER Function.cpt