PDA

View Full Version : [CLOSED] Select node after expand in TreePanel



multimediait
Mar 14, 2014, 6:16 PM
Good evening, I'm trying select a TreePanel's leaf after expand node (load ondemand) with this function:



var SelectNode = function (path, serial) {
var tree = Ext.getCmp("treeArchivi"),
sm = tree.getSelectionModel(),
node = tree.store.getNodeById(serial);

if (node == undefined) {
tree.expandPath(path);
}

node = tree.store.getNodeById(serial);
console.log(node);
if (node != undefined) {
sm.select(node);
App.direct.OpenArchivio(formatSerial(serial), node.data.text);
}
};


but console.log(node); returns undefined.
How can I resolve this issue?

Thanks in advance

Vladimir
Mar 14, 2014, 6:27 PM
Hi,

You should check node in callback method which is passed to expandPath
Please addtional info
http://docs-origin.sencha.com/extjs/4.2.1/#!/api/Ext.tree.Panel-method-expandPath

multimediait
Mar 17, 2014, 10:11 AM
Thanks Vladimir works perfectly in this way, can mark as closed



var ExpandNode = function (path, serial) {
var tree = Ext.getCmp("treeArchivi"),
node = tree.store.getNodeById(serial);

if (!path || (node != undefined)) {
SelectNode(serial);
} else {
tree.expandPath(path, null, '/', function (success, lastNode) {
if (success) {
setTimeout(function () {
SelectNode(serial);
}, 200);
}
}, this);
}
};

var SelectNode = function (serial) {
var tree = Ext.getCmp("treeArchivi"),
sm = tree.getSelectionModel(),
node = tree.store.getNodeById(serial);

if (node != undefined) {
sm.select(node);
App.direct.OpenArchivio(formatSerial(serial), node.data.text);
}
};