30 December 2011 ~ 7 Comments

ExtJS TreeStore / TreePanel remove record

Some of you might have noticed that there is no

remove()

method in the ExtJS TreeStore class.

So, what if you want to remove a node from a ExtJs TreePanel or ExtJs TreeStore? I was struggeling to find out the same today. The workaround is simple, but dirty:

   var store = Ext.data.StoreManager.lookup("yourtreestore");
   var rec   = store.getNodeById("node_id");
   rec.destroy();

The ExtJs TreeStore does not look very mature to me, and the docs are not very good. If anyone are interested in reading some of the stuff I have worked out lately, let me know and I will write a post about ExtJs TreeStore and ExtJs TreePanel.

7 Responses to “ExtJS TreeStore / TreePanel remove record”

  1. The One 30 December 2011 at 17:35 Permalink

    Please do!

    P.S. interested in link exchange?

  2. Fanny144 4 January 2012 at 16:51 Permalink

    How I could know the node selected in the tree??What would be the function??
    Are there one relationed with the view of the tree (treeModel), for example as of tree.getView().getSelectionModel()…

    I’m something lost, I just want to know the tree’s selected node.

    Thanks

  3. Ozone 9 January 2012 at 09:09 Permalink

    To get the selection of a tree, call:
    tree.getSelectionModel().getSelection();
    That will give you an array containing the selected model objects of the tree.

    I agree with Nils-Fredrik that Senchas Tree does not seem to be that mature, but there are ways of handling the nodes in the tree. As far as I understand, every TreeStore node model object gets decorated with the Ext.data.NodeInterface that has quite a lot functionality for managing the tree nodes (a remove method among others). Exactly how the decoration is done is a bit fuzzy to me, but data.TreeStore has a data.Tree object that seems to play a keen role in the connection between our model objects and the tree.

    So I think Nils-Fredriks example would actually work with: store.getNodeById(“node_id”).remove() The method is just described under Ext.data.NodeInterface in the API

    Happy hunting! 🙂

    /Ozone

  4. Amir Shaheen 11 April 2012 at 14:32 Permalink

    Hey Nils,
    I am new to EXT-JS and i wanna use this library as a front end and use ZEND on its back end please guide me through how can i integrate both i goggled a lot but couldn’t find any fruitful thing.

  5. Ozone 12 April 2012 at 09:01 Permalink

    Amir: OMG – For how many nanoseconds were you googling? :-O

    Searching for “Ext-js Zend” brought me this page http://www.tine20.org/wiki/index.php/Developers/Getting_Started/Getting_started_with_ExtJS_and_Zend_Framework with easy to follow examples (and that’s only the first search result)!

  6. Gatil 31 July 2012 at 12:56 Permalink

    Hey, do you also know a method to add a node to the treestore so it could be saved in a db?
    i tryed something like this:


    var newId = tree.getSelectionModel().getSelection()[0].data.id;
    tree.getStore().getNodeById(newId).data.leaf = false;
    tree.getStore().getNodeById(newId).appendChild({
    leaf: true,
    text: "text",
    });

    but the create method of the apie is not called

  7. Kris 3 December 2016 at 09:52 Permalink

    Ja som si tiež vÅ¡imla ten preklep:)Výborný článok. Zaujímavý, výstižný a vôbec nie nudný. Niet čo vytknúť. Páči sa mi, že vieÅ¡ daÅ¥ takejto téme správnu dávku zasdi­mavoutÃ.Hojnotenie: A


Leave a Reply