Highlighted

Collapsing a TreeView

Advocate ,
Feb 14, 2020

Copy link to clipboard

Copied

Dear friends,

My script to expand all nodes works fine. The contrary function to collapse all nodes, does not behave:

  • This is the starting point, the tree is generated an the top nodes are closed
    TreeViewKLD_3g_1.png
  • Using button Expand makes the whole tree visible
    TreeViewKLD_3g_2.png
  • As long as the whole tree is visible, using Collapse works correctly
    TreeViewKLD_3g_3.png
  • If only part of the tree is visible and Collapse is used, nothing happens:
    TreeViewKLD_3g_4.png

→ What could be wrong with FunCollapseAll?

function FunExpandAll(oTree) { // --- recursively used
// Reference    Peter Kahrel
var j, branches;
  oTree.expanded = true;
  branches = oTree.items;
  for (var j = 0; j < branches.length; j++) {
    if (branches[j].type == 'node') {
      FunExpandAll (branches[j]);
    }
  }
} // end of FunExpandAll

function FunCollapseAll(oTree) { // --- recursively used
var j, branches;
  oTree.expanded = false;
  branches = oTree.items;
  for (var j = 0; j < branches.length; j++) {
    if (branches[j].type == 'node') {
      FunCollapseAll (branches[j]);
    }
  }
} // end of FunCollapseAll

 

The following 'brute force' method works:

// --- behaviour of the buttons
  wDocNav.g1.btnExpand.onClick = function () {
    FunExpandAll(oTree);
  }
  wDocNav.g1.btnCollapse.onClick = function () {
    FunExpandAll(oTree); // to avoid error with partial view
    FunCollapseAll(oTree);
    wDocNav.show();
  }
TOPICS
Scripting

Views

346

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Collapsing a TreeView

Advocate ,
Feb 14, 2020

Copy link to clipboard

Copied

Dear friends,

My script to expand all nodes works fine. The contrary function to collapse all nodes, does not behave:

  • This is the starting point, the tree is generated an the top nodes are closed
    TreeViewKLD_3g_1.png
  • Using button Expand makes the whole tree visible
    TreeViewKLD_3g_2.png
  • As long as the whole tree is visible, using Collapse works correctly
    TreeViewKLD_3g_3.png
  • If only part of the tree is visible and Collapse is used, nothing happens:
    TreeViewKLD_3g_4.png

→ What could be wrong with FunCollapseAll?

function FunExpandAll(oTree) { // --- recursively used
// Reference    Peter Kahrel
var j, branches;
  oTree.expanded = true;
  branches = oTree.items;
  for (var j = 0; j < branches.length; j++) {
    if (branches[j].type == 'node') {
      FunExpandAll (branches[j]);
    }
  }
} // end of FunExpandAll

function FunCollapseAll(oTree) { // --- recursively used
var j, branches;
  oTree.expanded = false;
  branches = oTree.items;
  for (var j = 0; j < branches.length; j++) {
    if (branches[j].type == 'node') {
      FunCollapseAll (branches[j]);
    }
  }
} // end of FunCollapseAll

 

The following 'brute force' method works:

// --- behaviour of the buttons
  wDocNav.g1.btnExpand.onClick = function () {
    FunExpandAll(oTree);
  }
  wDocNav.g1.btnCollapse.onClick = function () {
    FunExpandAll(oTree); // to avoid error with partial view
    FunCollapseAll(oTree);
    wDocNav.show();
  }
TOPICS
Scripting

Views

347

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Feb 14, 2020 0
Advocate ,
Feb 14, 2020

Copy link to clipboard

Copied

The following 'brute force' method works:

// --- behaviour of the buttons
  wDocNav.g1.btnExpand.onClick = function () {
    FunExpandAll(oTree);
  }
  wDocNav.g1.btnCollapse.onClick = function () {
    FunExpandAll(oTree); // to avoid error with partial view
    FunCollapseAll(oTree);
    wDocNav.show();
  }

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 14, 2020 0
Explorer ,
Feb 14, 2020

Copy link to clipboard

Copied

I can't try this, but my guess is that you can't collapse a node if it's parent is already collapsed.

 

Is there a way you can work in the opposite direction for collapse?

Fold all of the lowest nodes first and work up the tree?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Feb 14, 2020 0