How do you clear a tree in ExtJs?

19,680

Solution 1

From the wonderful blog of Saki an ExtJS guru.

while (node.firstChild) {
    node.removeChild(node.firstChild);
}

http://blog.extjs.eu/know-how/how-to-remove-all-children-of-a-tree-node/

Solution 2

In Ext JS 4:

if you want to reload the data of the tree panel, you need to reload the tree store:

getCmp('treeId').getStore().load();

where treeId is the id of the tree. If you have a store id, you may directly use load() on store id.

to remove all child nodes:

getCmp('treeId').getRootNode().removeAll();

However, removing child nodes is not necessary for reloading the tree nodes from its store.

Solution 3

In my case, my Ext tree has a hidden root node of type AsyncTreeNode. If I want to clear the tree and repopulate from the server, it's pretty simple:

tree.getRootNode().reload();

Solution 4

I finally found an answer in their forums. For anyone interested it is here:

if (tree)
{
    var delNode;
    while (delNode = tree.root.childNodes[0])
        tree.root.removeChild(delNode);
}

Solution 5

you can simply use node.removeAll() to remove all child nodes from this node.

http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.data.NodeInterface-method-removeAll

Share:
19,680
Admin
Author by

Admin

Updated on July 04, 2022

Comments

  • Admin
    Admin almost 2 years

    I have managed to create an Ext.tree.TreePanel that loads child nodes dynamically, but I'm having a difficult time clearing the tree and loading it with new data. Can someone help me with the code to do this?