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

lapos34 picture lapos34 · Jun 16, 2011 · Viewed 19.5k times · Source

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 !

Answer

FoxMulder900 picture FoxMulder900 · Jul 18, 2011

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