JS Custom number of layers of tree expansion

  • Last update:  2020-12-16
  • I. Overview

    1.1 Problem

    In the daily report making process, the organization tree format is a very convenient and commonly used display format. But in the process of use, we hope to be able to expand a certain level of tree nodes according to requirements when initializing.


    1.2 Solution

    Add a tree node button to each level of the organization tree; add a locator, and set the loading end event through JS, determine the location of the locator, and click the tree node button to expand the number of layers.

    II. Example

    2.1 Report design

    Open report %FR_HOME%\webapps\webroot\WEB-INF\reportlets\demo\Report\Group Report\Combo Tree.cpt

    Here is a three-layer tree structure, as shown below:

    image (3).png


    2.2 Set loading end event

    Click Menu Template>Template Web Attributes>Data Analysis Settings, and add the loading end event, as shown in the following figure:

    image (4).png

    JavaScript:

    $("#content-container").find("tr").has(".x-treenode-unexpand").each(function(){
       if($(this).children().eq(0).text()==1){ //eq(0) means the leftmost cell; text()==1 means the cell with content 1 grid
           $(this).find(".x-treenode-unexpand").trigger('click');
       }
    })


    2.3 Add locator

    Before the node of the organization tree that needs to be expanded, add a number 1 as a locator. And set the parent cell of the locator and expand with the area.

    Note: The locator can be set arbitrarily, but it needs to be consistent with the text() in JS.

    image (5).png

    Finally, hide column A.

    After clicking save, select data analysis preview. The effect is that when the template is opened, only one level of tree nodes is expanded:

    image (6).png


    2.4 Extra: Expand two-level nodes

    If you want to expand two-level nodes, the previous steps are the same, just add a locator in front of the second-level area (ie, cell B7).

    As shown in the figure: input the locator in cell A7: 1; similarly set the left parent cell of cell A7 to B7;

    image (7).png

    Then hide column A. After clicking save, select data analysis preview. 

    image (8).png

    III. Download template

    Attachment List


    Theme: Report Application
    • Helpful
    • Not helpful
    • Only read

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

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

    不再提示

    10s後關閉

    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