Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extjs 4 tree select a specific node by its internal id (not by record index)

I'm trying to sync a dataview (explorer window) with a tree (directory tree). When I click on an element on my dataview, I'd like the same node gets selected on the tree

The problem is that using the tree.getSelectionModel().select(index) doesn't allow me to select the node by its internal id (the id I provided in my treestore), but only by the record index... So I just can't sync both views... There would be the solution of the expandPath(), but my treestore is fed by a relational database (id,name,parent_id etc..), so finding the full path is(or could be) a heavy load for the server (I'd like to avoid to have to provide any path...).

Basically I would like to be able to say "expand the node where the "id= " (or any other key/value of the treestore).

Is it possible ? Is there any workaround ?

Thank you for reading me !

like image 374
lapos34 Avatar asked Jun 16 '11 14:06

lapos34


1 Answers

The tree.getSelectionModel().select(record) function can accept a record instance instead of an index. I would do something like this:

var record = tree.getRootNode().findChild('id_name','record_id',true);
tree.getSelectionModel().select(record);

for more info on the findChild function, check out the NodeInterface docs here: http://docs.sencha.com/ext-js/4-0/#/api/Ext.data.NodeInterface-method-findChild

like image 148
FoxMulder900 Avatar answered Nov 07 '22 08:11

FoxMulder900