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

[Solved] Expand to SelectedNode

2 Answers 135 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Martin
Top achievements
Rank 1
Martin asked on 11 Oct 2011, 12:56 PM
I have a TreeView with multiple layers
I'm then using this function to Select a Node:
function ClickNode(nodeid) {
    $("#TreeView").find(".t-input[name='itemValue'][value='" + nodeid + "']")
                  .closest("div")
                  .find(".t-in:first")
                  .trigger("click");
}

What i want now is to collapse the whole tree, and expand nodes up until the Selected Node..
how do I accomplish that ?

thanks.

ps. I wish that i didn't need to use jQuery this much just to navigate in the MVC controls :-(

2 Answers, 1 is accepted

Sort by
0
Martin
Top achievements
Rank 1
answered on 11 Oct 2011, 01:02 PM
after reading this thread : http://www.telerik.com/community/forums/aspnet-mvc/treeview/how-to-get-child-checkboxes-selected-when-parent-checkbox-is-selected.aspx

wouldn't it be possible to wire up some events that does these expandings automatically ?
0
Martin
Top achievements
Rank 1
answered on 11 Oct 2011, 01:20 PM
after reading some more on this forum, i've hacked myself a solution using jQuery...

function treeView() {
    return $('#TreeView').data('tTreeView');
}
function itemByValue(val) {
    return $("#TreeView").find(".t-input[name='itemValue'][value='" + val + "']").closest("li");
}
function expandItem(item) {
    $("#TreeView").data("tTreeView").expand(item);
}
function expandNodeID(id) {
    $("#TreeView").data("tTreeView").expand(itemByValue(id));
}
function parentNode(item) {
    return $(item).closest('.t-item').parent().closest('.t-item').find(':input[name*="Value"]').val();
}

my Tree is only 3 layer deep... so it would be fairly easy to do an iterative expander...
Tags
TreeView
Asked by
Martin
Top achievements
Rank 1
Answers by
Martin
Top achievements
Rank 1
Share this question
or