SAN
SAN

Reputation: 2247

extJs tree: get a node from name

Is there a way to check/uncheck a node in extJS tree, if all we have is just the node name (with parent names till root). I am using ExtJS 3.3.0, couldnt find any method in the API documentation

Upvotes: 1

Views: 2885

Answers (1)

sra
sra

Reputation: 23973

First: I guess the name does not match the Id of the node otherwise you are done with treePanel.getNodeById() API link

You have the path of the node given the the node.getPath()

You just need to call

treePanel.expandPath(path, null, function(bSuccess, oLastNode){ oLastNode.select() });
treePanel.expandPath(path, null, function(bSuccess, oLastNode){ oLastNode.unselect() });

API -Link

with name you are meaning the text property of the node that does not match the node id or any other accessible attribute on the node:

  • get your root node and the array of all child nodes from that
  • take your path and get the first child after root
  • iterate through the array till you found the matching on the node.text
  • take the child array from this node
  • take the next child from your path
  • iterate through the array till you found the matching on the node.text
  • and so on

finally you will reach your target node. Know you just need to call

Please note that I did not test the select / unselect behavior but it should check / uncheck the combo. for collapsing use either toggle() if you just want to change the state or collapse() / expand()

Upvotes: 2

Related Questions