Successfully!

Error!

You are viewing 10.0 help doc. More details are displayed in the latest help doc

JS Collapse or expand all tree nodes in one click

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: Secondary Development
Already the First
Already the Last
  • Helpful
  • Not helpful
  • Only read

Doc Feedback