This is a migrated thread and some comments may be shown as answers.

Get Nodes Parent

3 Answers 441 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Craig Broadhead
Top achievements
Rank 1
Craig Broadhead asked on 24 Sep 2012, 09:47 AM
Does anybody know of a way to get the parent node of the node you currently have selected?

3 Answers, 1 is accepted

Sort by
0
Iliana Dyankova
Telerik team
answered on 24 Sep 2012, 08:18 PM
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!
0
Craig Broadhead
Top achievements
Rank 1
answered on 25 Sep 2012, 08:11 AM
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?




0
Iliana Dyankova
Telerik team
answered on 28 Sep 2012, 10:11 AM
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!
Tags
TreeView
Asked by
Craig Broadhead
Top achievements
Rank 1
Answers by
Iliana Dyankova
Telerik team
Craig Broadhead
Top achievements
Rank 1
Share this question
or