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

[Solved] NodeClick

4 Answers 132 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.
Jeroen Eikmans
Top achievements
Rank 1
Jeroen Eikmans asked on 07 Sep 2011, 04:21 PM
Hello,

I have a Treeview with Binding to a List<CustomerObject>  in my model, this is the same as the Binding to Model Demo.
In the ClientEvent OnLoad i have to following code
function MasterTreeviewLoad(e) {
        var treeView = $('#Treeview').data('tTreeView');
 
        var node = $("> ul > li", treeView.element)[0];
 
        treeView.nodeClick(e, node);
    }


What i am attempting to do is have the first node selected after the treeview is done loading.The code above however is not working.
Does anybody have an idea about what i'm doing wrong?

4 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 08 Sep 2011, 06:38 AM
Hello Roel,

The nodeClick method is not meant to be used that way (it's more of a private method). You can select the first node by triggering a click event (if you need to fire the onSelect event) or by simply adding a t-state-selected class:

// triggers onSelect
$("> ul > li", treeView.element).eq(0).trigger("click");
 
// does not trigger onSelect
$("> ul > li", treeView.element).eq(0).addClass("t-state-selected");


Regards,
Alex Gyoshev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Jeroen Eikmans
Top achievements
Rank 1
answered on 08 Sep 2011, 09:15 AM
Hello Alex,

OK, i understand i shouldn't use the nodeClick method.
I do need the OnSelect to be triggered so i'm using the first line but unfortunatly i am not able to get the click to work.

I attached a small app is used to try the functionality. Is it possible you take a quick look at it and tell me what i'm doing wrong?
Thanks for your help!
0
Accepted
Alex Gyoshev
Telerik team
answered on 08 Sep 2011, 09:37 AM
Hi Roel Martens,

Sorry, my bad -- the correct code should have been as follows:
// triggers onSelect
$("> ul > li > div > .t-in", treeView.element).eq(0).trigger("click");
  
// does not trigger onSelect
$("> ul > li > div > .t-in", treeView.element).eq(0).addClass("t-state-selected");

or, to keep things short (finding the first .t-in element),
// triggers onSelect
$(".t-in:first", treeView.element).trigger("click");
  
// does not trigger onSelect
$(".t-in:first", treeView.element).addClass("t-state-selected");

The modified Index.cshtml is attached.

Regards,
Alex Gyoshev
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Jeroen Eikmans
Top achievements
Rank 1
answered on 08 Sep 2011, 09:47 AM
Hi Alex,

Thanks! It's working perfectly now.

Kind regards,
Roel
Tags
TreeView
Asked by
Jeroen Eikmans
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Jeroen Eikmans
Top achievements
Rank 1
Share this question
or