PDA

View Full Version : Multiple selection of paths in TreePanel



gabrialice
6 Sep 2012, 3:42 AM
Hi! In a TreePanel I need to select multiple nodes in the same time. Since I know the paths of these nodes , I use selectPath(nodepath) in a for cycle (done on the array of paths of the nodes I want to select).
It is not working because each selection deselect the previous one. So I obtain only the last node in the array selected.
Is there another method to have an array of paths selected contemporaneusly?
Thanks!

tvanzoelen
6 Sep 2012, 4:39 AM
Yeah you must override that method with this


selectPath: function(path, field, separator, callback, scope) {
var me = this,
root,
keys,
last;

field = field || me.getRootNode().idProperty;
separator = separator || '/';

keys = path.split(separator);
last = keys.pop();
if (keys.length > 1) {
me.expandPath(keys.join(separator), field, separator, function(success, node){
var lastNode = node;
if (success && node) {
node = node.findChild(field, last);
if (node) {
me.getSelectionModel().select(node, true);
Ext.callback(callback, scope || me, [true, node]);
return;
}
}
Ext.callback(callback, scope || me, [false, lastNode]);
}, me);
} else {
root = me.getRootNode();
if (root.getId() === last) {
me.getSelectionModel().select(root, true);
Ext.callback(callback, scope || me, [true, root]);
} else {
Ext.callback(callback, scope || me, [false, null]);
}
}
}

Armen Orduyan
8 Feb 2013, 4:52 AM
Try something like this

var selectionModel = this.myTree.getSelectionModel();
for (var i = 0; i < pathToSelect.length; i++) {
this.myTree.expandPath(pathToSelect[i], null, null, function(success, lastNode) {
selectionModel.select(lastNode, true, true);
});
}