JS Collapse or expand all tree nodes in one click

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

    1.1 Problem

    For the complex folding tree or view tree report we made, when previewing in the data analysis mode, you need to click the parent node to expand the next level of child nodes. When there are many levels, the operation is more troublesome.

    If the user wants to expand or collapse all in one click, how to do it?

    iShot2020-10-31 17.07.18.gif


    1.2 Solution

    You can add 2 buttons, and then add click events to the buttons to achieve the corresponding functions.

    II. Example

    2.1 Add button

    Open  %FR_HOME%\webapps\webroot\WEB-INF\reportlets\demo\Report\Group Report\Combo Tree.cpt  and add 2 buttons.

    image.png


    2.2 Set the click event

    Add click events to the "unfold" and "fold" buttons respectively:

    1) Expand JS:

    image (1).png

    //Expanded maximum node level value
    var t = 3; 
    for(var m = 1; m <= t; m++) {
    //Loop execute the "+" sign to expand
        $('.x-treenode-unexpand').trigger('click');
    }
    for(var n = 1; n <= 2; n++) {
    //Perform the click twice (the subscript starts from 0), and the first element with the style "fr-widget-click", position the cursor
        $('.fr-widget-click').eq(0).trigger('click');
    }

    2) Collapse JS:

    image (2).png

    var t = 3;
    for(var m = 1; m <= t; m++) {
    //Loop execute the "-" sign to collapse
        $('.x-treenode-expand').trigger('click');
    }
    for(var n = 1; n<= 2; n++){
    //Perform the click twice (the subscript starts from 0), and the first element with the style "fr-widget-click", position the cursor
    $('.fr-widget-click').eq(0).trigger('click');

     

    2.3 Preview effect

    Save the template, click the data analysis preview, the effect on PC is as follows:

    iShot2020-10-31 17.07.18 (1).gif

    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