View Full Version : Hiding a child node in a Tree Panel.

24 Feb 2012, 9:27 AM
I'm trying to hide a child node in a tree panel. I know how to hide a visible child node, but when I want to hide/show one that isn't currently visible, I have no idea what to do. Here's some code...


var store = Ext.create('Ext.data.TreeStore', {
storeId: 'myStore',
root: {
"id": null,
"text": "root",
"expanded": false,
"leaf": false,
"children": [{
"id": "all",
"text": "All",
"cls": "folder",
"expanded": false,
"leaf": false,
"children": [{
"id": "child1",
"leaf": true,
"text": "child1"
"id": "some",
"text": "Some",
"cls": "folder",
"expanded": false,
"leaf": false,
"children": [{
"id": "child2",
"leaf": true,
"text": "child2"
}, // end of root
proxy: {
type: 'memory',
reader: {
type: 'json'

Ext.create('Ext.tree.Panel', {
store: store,
id: 'myPanel',
width: 200,
height: 200,
rootVisible: false,
renderTo: Ext.getBody()

When I open the page, the tree panel is how it should be.. works fine, I can see all the child nodes, etc. When I have all of the branches collapsed, and I want to hide "child1," I try this:

var tree = Ext.getCmp('myPanel');
var record = tree.store.getNodeById('child1'); // returns with the record of the child
Ext.fly(tree.getView().getNodeByRecord(record)).setVisible(false); // returns null
I think the reason it returns null is because the child's record is currently not in the view of the tree. If I expand the branch "All," and run the same code, the child disappears as it should, but if the tree is collapsed, I get null.

How can I make a child hidden even if it's not in the current view? So if a branch isn't expanded, I hide a child, and then expand the branch, the child shouldn't be there. I basically want to control whether or not a certain child node is hidden. Any help would be greatly appreciated!

24 Feb 2012, 12:32 PM
The issue is it's not rendered. So you can listen to itemexpand and then hide the node

24 Feb 2012, 4:52 PM
So is there any way to just hide it without rendering it? I tried expanding the tree and then collapsing it, but that didn't work... I'm assuming the list of nodes re-renders each time you expand it then?

Maybe there's a way to hide the nodes by accessing the store? (Probably not because I can only delete and add to the store, right?) I just want the user to be able to hide/show nodes whether the node is currently seen or not... which means, if they expand the branch, the node shouldn't render (if they hid the node).

27 Feb 2012, 6:45 AM
There's probably no way of filtering out my record from the store, is there? I tried doing itemexpand, but I get the "is null" error... I'm thinking because getView doesn't have the record yet.

So what I'm gathering is, every time I expand a branch, the tree re-renders, correct? Like it doesn't cache the child nodes in memory...?