Quantcast
Channel: GoJS - Northwoods Software
Viewing all articles
Browse latest Browse all 6977

Treelayout doesnt scrollToRect() if I expandTree() of parent node

$
0
0

@rkaren wrote:

I have a tree based on Tree View sample. I have a search routine that locates a child node, selects it and scrollsToRect. It works fine if the parent is expanded but if I expandTree(parent), it selects the node but fails to scroll to it. Here is how I am doing that part. thanks for your help.

  doSearchTargetsTree: function() { // called from Search button.
var searchStr = $('#searchTerm').val();
var searchStrRegExp = new RegExp(searchStr, 'i');
var obj = new Object();
obj.title = searchStrRegExp ;
var iter = tree.myDiagram.findNodesByExample(obj);
var node = iter.first();
if (node) {
  var parentKey = node.data.parent;
  var parent = tree.myDiagram.findNodeForKey(parentKey);
  if (parent) {
    parent.expandTree();
    // expand root node, if necessary.
    var root = tree.myDiagram.findNodeForKey('0');
    root.expandTree();
    tree.myDiagram.clearSelection();
    tree.myDiagram.select(node);
    // scroll tree to center on bounds of the selected node.
    var rect = node.actualBounds;
    if (rect) {
      console.log('actual bounds of selected node: ' + rect);
      tree.myDiagram.scrollToRect(rect);
      // sometimes scroll doesn't work. using setTimeout() did NOT help.
      ms = '2000';
      window.setTimeout(addressBook.scrollTreeToKey(node.data.key), ms);
    } else {
      alert('There was a problem scrolling to selected target. Please scroll down/up to locate it.');
    }

  scrollTreeToKey: function(key) {
var node = tree.myDiagram.findNodeForKey(key);
if (node) {
  var rect = node.actualBounds;
  tree.myDiagram.scrollToRect(rect);
} else {
  alert('scrollTreeToKey: invalid node');
}

},

Posts: 11

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 6977

Latest Images

Trending Articles



Latest Images