2
votes

How can we hide some of the nodes in ExtJs 4.1 TreePanel based on some condition? We can hide node in ExtJs 3.4 by doing this:

tree.getRootNode().cascade(function() { // descends into child nodes
    if(this.attributes['status'] == 100) { // test this node
        this.getUI().hide() // hide this node
    }
})

But this method is no longer supported in ExtJs 4.1.

2
if you remove the records from the store they will not show up in the tree. You could filter the store if you need to dynamically show and hide on command.dbrin

2 Answers

2
votes

There's a topic about this on Sencha's forum. It seems that this is not supported but have workarounds.

0
votes

For ExtJS 6, for example, when read config is false, hide the node:

hideItemsReadFalse: function () {
    var me = this,
        items = me.getReferences().treelistRef.itemMap;


        for(var i in items){
            if(items[i].config.node.data.read == false){
                items[i].destroy();
            }
        }
}

Root:

{
    "text": "root",
    "children": [
        {
            "text": "Atualização",
            "iconCls": "x-fa fa-list",
            "children": [
                {
                    "leaf":true,
                    "text": "Empresas",
                    "module": "empresas",
                    "iconCls": "x-fa fa-building",
                    "read": false
                },
                {
                    "leaf":true,
                    "text": "Produtos",
                    "module": "produtos",
                    "iconCls": "x-fa fa-cubes",
                    "read": true
                }
            ]
        }
    ]
}