Get Nodes Parent

4 posts, 0 answers
  1. Craig Broadhead
    Craig Broadhead avatar
    23 posts
    Member since:
    Jul 2010

    Posted 24 Sep 2012 Link to this post

    Does anybody know of a way to get the parent node of the node you currently have selected?

  2. Iliana Nikolova
    Admin
    Iliana Nikolova avatar
    1869 posts
    Member since:
    Sep 2012

    Posted 24 Sep 2012 Link to this post

    Hi Craig,

    This could be achieved via jQuery. As a possible approach I can suggest the following:

    • Get the currently selected node via the select method of the Kendo UI TreeView;
    • Search for the closest group;
    • Search for the closest item.
    Like here:
    var treeView = $("#treeview").data("kendoTreeView");
    var selectedNode = treeView.select();
    selectedNode.closest(".k-group").closest(".k-item");

    I hope the suggested approach fits your requirements.

    Regards,
    Iliana Nikolova
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!

  3. Craig Broadhead
    Craig Broadhead avatar
    23 posts
    Member since:
    Jul 2010

    Posted 25 Sep 2012 Link to this post

    Hi Iliana,

    That works fine in one case but I have a case where i'm doing an OnNodeSelect on the treeview.

    var tv = $("#treeView").data("kendoTreeView");
    tv.bind("select", function(e) {Filters.OnNodeSelect(e);});

        OnNodeSelect: function(Node){ 
            Filters.RunFilters(Node);
        },

    In this case i'm having to pass the Node object that is given to me by the select into my RunFilters routine because treeView.select(); still reports the old selected node at this point. My problem occurs in this case because i get the error when doing Node.closest in RunFilters "Node.closest is not a function". Is there a better way for me to be handling the OnNodeSelect that would allow me to be able to use Node.closest in my RunFilters routine?




  4. Iliana Nikolova
    Admin
    Iliana Nikolova avatar
    1869 posts
    Member since:
    Sep 2012

    Posted 28 Sep 2012 Link to this post

    Hello Craig,

    I believe the error is due to the fact that in the select event the selected node should be passed as e.node. Like here: 

    //....
    tv.bind("select", function(e) {Filters.OnNodeSelect(e.node);});
    //....

    Please test you project as apply this minor change and let me know if you still observe any problems. 

    Regards,

    Iliana Nikolova
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!

Back to Top