Tree Dataset

  • Last update:April 28, 2025
  • Overview

    Application Scenario

    A tree dataset is used to display hierarchical structures through drop-down or collapsible trees, such as the department hierarchy shown in the following figure.

     1.png

    If you bind a tree dataset to a widget, a tree-like hierarchical structure will automatically be generated when viewed on the web. How to convert the two-dimensional structure of a data table to this tree-like hierarchical relationship? This document will explain the transformation.

    Applicable Data Table Structure

    In FineReport, two types of table structures can be used to build tree datasets: 

    The following figure shows the table structure in which a series of hierarchical data contains regular ID numbers. For details about how to convert the table structure to a tree dataset, see Example one in this document.

     2.png

    The following figure shows the table structure which includes the current ID and the parent ID numbers. For details about how to convert the table structure to a tree dataset, see Example two in this document.

     补3.png

    To convert the two-dimensional structure of a data table to this tree-like hierarchical relationship, FineReport provides the concept of a tree dataset. If you bind a tree dataset to a widget, a tree-like hierarchical structure will automatically be generated when viewed on the web.

    Example one: Data with Regular ID Number Lengths

    Dataset Creation

    Enter the SQL statement SELECT DepartmentID,Department_name FROM CorporationDepartment to create a dataset named ds1, as shown in the following figure.

     3.png

    Tree Dataset Creation

    1. Click the 1.5.png icon, and select Tree Dataset, as shown in the following figure.

    4.png

    2. Select Create Tree Depending on Length of Selected Dataset's Tag Field, and select DepartmentID in Original Tag Field, as shown in the following figure.

     5.png

    3. Click the Preview button, as shown in the following figure.

     6.png

    4. Click OK, and the tree dataset is created.

    Example Two: Data with ID and Parent ID Numbers

    Dataset Creation

    1. Enter the SQL statement SELECT * FROM CorporationDepartment to create a dataset named ds2, as shown in the following figure.

     7.png

    2. Create a tree dataset as shown in example one. Select ds2, and tick Create Tree Depending on Parent Tag Field of Selected Dataset, as shown in the following figure.

    Select DepartmentID in Original Tag Field, and select SuperioID in Parent Tag Field

    8.png

    3. Click the Preview button, and the effect is the same as that shown in example one. Click OK to save the tree dataset.

    Usage Format

    The tree dataset must be set in the fixed column structure of ID, Parent ID, and Name. The ID value can be a number or a string.

    For data not in this format, SQL Union or recursive methods can be used to combine the results before placing them into the dataset.

    The following example illustrates a format conversion for better understanding. The former data format displays the parent-child relationship between two columns.

     图2.png

    The SQL must be converted before being included in the dataset

     图1.png

    Typical Applications

    Attachment List


    Theme: Data Preparation
    Already the First
    Already the Last
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    9s后關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy