Results 1 to 3 of 3

Thread: Method to set a tree node as leaf or non-leaf

  1. #1
    Sencha User
    Join Date
    Dec 2008
    Location
    Sofia
    Posts
    267

    Default Method to set a tree node as leaf or non-leaf

    Hi guys, please look at the attached screenshot:

    Capture.PNG

    As you can see - the node with text '2222' is a leaf node. The tree store is populated remotely.
    Well - i have function which handles an event for this node and which creates a new node that is a child of '2222'.

    Now i want the tree panel to be updated automatically so that '2222' to become from leaf to non-leaf and to be automatically expanded showing the newly created child and changing its icon respectively.

    However, when i use the expand() method for that node OR when i call treeStore.load() (with node 2222 as a param) - nothing happens. This is probably because the node is already marked as leaf and therefore - not expandable. These two methods are OK with any of the other nodes in the tree.

    So - how to solve this? Initially - i was looking for a method similar to node.setLeaf(true/false), but there is no such thing in the docs.

    After several times playing around - i suddenly found that i can implement this using the data property of the node instance. So - setting the following:

    Code:
    node.data.leaf = false;
    node.expand();
    did for me exactly what i wanted with just 2 lines of code.

    However, i'm afraid that this is bad ExtJS practice and therefore the question is:

    Why not just create a method, named for example setLeaf(bool) which to be included in the framework?

    Cheers

  2. #2
    Sencha User
    Join Date
    Dec 2008
    Location
    Sofia
    Posts
    267

    Default

    Quote Originally Posted by mx_starter View Post
    Well - i have function which handles an event for this node and which creates a new node that is a child of '2222'.
    Correction! The above text in red is obviously incorrect because the handler does NOT create a new node, but simply new entry into the server backend.

    That's why the treeStore.load() method is needed to retrieve the new data from server (or just node.expand() if the node is still not expanded)

    But i believe my question is still reasonable

  3. #3
    Sencha User
    Join Date
    Feb 2013
    Location
    California
    Posts
    11,985
    Answers
    506

    Default

    I don't see getters or setters for any of the other configs for Ext.data.NodeInterface. Perhaps a developer will shed some light, but perhaps the fact that it was so easy to accomplish otherwise plays into it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •