Dima Railguner
Dima Railguner

Reputation: 173

dijit.Tree set path and scroll to selected node

Actually I'm stuck. I'm trying to select node in dojo tree and immediately scroll to it. But I don't understand how to implement this.

next code:

this.set("path", ["root", "folder", "file"]);
this.focusNode(this.selectedNode.id);

isn't working

this one:

this.set("path", ["root", "folder", "file"]);
win.scrollIntoView(this.selectedNode.id);

works! but only if folder (parent leaf) of tree is already opened. And it isn't working if parent folder is closed.

So... Could somebody help me?

P.S. Here is very easy example: http://jsfiddle.net/hjnx9/6/

I click on the button and would like to select some node in the tree and scroll to it. At first time node just will be selected (but scrolling isn't working). At second time node will be selected again and scrolling going to work this time. How to fix it???

P.S.S. I think that problem is that set("path",...) opens the folder of tree not immediately (animation takes about 200 ms). So may be I need some kind of callback?

Upvotes: 0

Views: 2455

Answers (1)

Ivo Silva
Ivo Silva

Reputation: 350

set("paths", ...) returns a Promise, so, your problem can be solved in the following way:

    //select node
    _Tree.set("path", ["root", "folder49", "file25_folder49"]).then(
      function(path) {
        // executes when set("path", ..) is complete
        var item = _Tree.model.store.data[2526];
        _Tree.onClick(item);        
      }
    );

Upvotes: 2

Related Questions