JS-based One-Click Expanding or Collapsing of All Nodes in a View Tree

  • Last update:March 28, 2025
  • Overview

    Expected Effect

    When previewing a report that contains a complex view tree, you need to click each parent node to expand its child nodes. If multiple layers exist in the view tree, the process can be tedious.

    You can achieve a one-click expansion or collapse of all nodes in a view tree, as shown in the following figure.

    Screen Recording 2025-03-28 at 11.21.52 (1).gif

    Implementation Method

    You can implement this function by adding two button widgets and attaching JavaScript codes to the widgets.

    Example

    You can download the template: View Tree Report A.cpt.

    Widget Adding

    Add two button widgets to the parameter panel, rename them Expand All and Collapse All respectively, and deselect Display Nothing Before Query, as shown in the following figure.

    image.png

    Event Adding

    1. Add a Click event to the Expand All button widget, as shown in the following figure.

    image.png

    The JavaScript codes are as follows:

    var t = 2;
       for(var m = 1; m <= t; m++) {
          //Expand all nodes in a loop by clicking +.
          $('.fr-tree-elbow-plus').trigger('click');
          $('.fr-tree-elbow-end-plus').trigger('click');
    }

    2. Add a Click event to the Collapse All button widget, as shown in the following figure.

    image.png

    The JavaScript codes are as follows:

    //Set the maximum number of nodes that can be collapsed.
      var t = 2;
       for(var m = 1; m <= t; m++) {
          //Collapse all nodes in a loop by clicking -.
          $('.fr-tree-elbow-minus').trigger('click');
      }
      $('.fr-tree-elbow-end-minus').trigger('click');


    Effect Display

    Save the template and click Data Analysis Preview. The effect is the same as that shown in section "Expected Effect."

    iconNote:

    1. The effect can only be previewed in the Data Analysis Preview or Data Entry Preview mode.

    2. The effect cannot be previewed on mobile terminals.

    Template Download

    Attachment List


    Theme: Parameter
    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