I. Overview
1) Tree datasets are used to construct tree-like hierarchical relationships, such as hierarchical structure of departments and regions.
2) Each original data needs an original tag field and a parent tag field, and a tree dataset is constructed according to the two fields.
3) Data sources in the Designer can be divided into two types according to their scope of application: Template dataset and server dataset. We use template dataset as an example here. The operation method of server datasets is similar to that of template datasets, and will not be discussed here.
You will learn |
---|
|
II. Steps
1. Create an original dataset.
1. We use DB query as an example. You can refer to Database Query. We use FRDemo as the data source. SQL statement:
SELECT * FROM CorporationDepartment
2. Preview original data
The original data meets the following two conditions:
Condition 1: each department has [DepartmentID] and [SuperiorID], with the former being the original tag field which should be filled with the ID of the department, and the latter being the parent tag field which should be filled with the ID of superior department of the department.
Condition 2: the departmentID field of the company department follows some rule, that is, only one number represents the first layer department, two numbers represent the second layer department, and so on.
Note: In actual operation, the departmentID and department_name must correspond, and the departmentID cannot be the same.
3. New tree dataset-method 1
“Build tree according to the parent tag field of the selected dataset” is applicable to the Condition 1 under 1. Create an original dataset-2. Preview original data.
1. New tree dataset. Click +at the top of the Template Dataset panel. Select Tree.
2. Enter the tree dataset name and select the DB query ds1 created earlier. Click button on the right and you will see original data.
Note: It is important to emphasize that a unique root node (that is, a node whose upper ID is empty) is required. If the root node is not unique, index will not be built properly when building the tree. Finally, when using the drop-down tree widget in front end, some functional problems may occur. For example, the widget cannot display default values and do not support fuzzy search.
3. Select Build tree according to the parent tag field of the selected dataset. Select [DepartmentID] in the original tag field. Select [SuperiorID] in the parent tag field.
4. New tree dataset-method 2
“Build tree according to tag field’s length from selected dataset” is applicable to the Condition 2 under 1. Create an original dataset-2. Preview original data.
1. New tree dataset. Click + at the top of the Template Dataset panel. Select Tree.
Enter the tree dataset name and select the DB query ds1 created earlier. Click button on the right and you will see original data.
Select Build tree according to tag field’s length from selected dataset. Select [DepartmentID] in the original tag field.
Note: FineReport automatically recognizes the rules in the departmentID field.
5. Preview effect
1. ClickPreviewat the bottom right and you can preview effects.
2. As shown in the figure below, 3 fields were automatically generated in the data table, namely: FR_GEN_0 (first layer), FR_GEN_1 (second layer) and FR_GEN_2 (third layer).
Take the data framed in red as an example:
Headquarter (DepartmentID: 1) is on the first layer, Financial department (DepartmentID: 13) is on the second layer, and Accountant (DepartmentID: 132) is on the third layer.
Typical application: Build a drop-down tree、Drop down tree