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

collapse - expand When click on Node that have children, without PostBack

4 Answers 29 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 16 Jul 2014, 08:53 AM
Hello,

I am currently working on a project with a RadTreeView.

I need only when I click on a leaf with no children it do a PostBack.
When I click on a leaf that has children, it will be performed expand/ collapse - depending on the current mode.
(If it has been expanded – it will be collapse, if collapse - expand)

I have a js code, but it’s give me an error every time I click on a node that has children:

ASPX:
01.// TreeView_Menu Expand/Colapse When Pressing On Branch Node
02. function TreeViewExpanCollaps_OnClientNodeClicked(sender, args) {
03.     var node = args.get_node(),
04.         $element = $(node.get_element()),
05.         $selectedNodeElement;
06. 
07.     if (node.get_nodes().get_count() > 0) {
08.         if (!node.get_expanded()) {
09.             node.expand();
10.             args.set_cancel(true);
11.         }
12.         else {
13.             node.collapse();
14.             args.set_cancel(true);
15.         }
16.     }
17. 
18. 
19. }
20.  
21. <telerik:RadTreeView ID="RadTreeView1" Runat="server" Skin="MetroTouch" OnClientNodeClicked="TreeViewExpanCollaps_OnClientNodeClicked">


VB.net:
Protected Sub RadTreeView1_NodeClick(sender As Object, e As Telerik.Web.UI.RadTreeNodeEventArgs) Handles RadTreeView1.NodeClick
        lbl_txt.Text = e.Node.Text
End Sub


Errors:
Uncaught TypeError: undefined is not a function expand_colapse_treeview.aspx:28
TreeViewExpanCollaps_OnClientNodeClicked expand_colapse_treeview.aspx:28
(anonymous function) Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:6
Telerik.Web.UI.RadWebControl.raiseEvent Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:951
c.RadTreeView._raiseEvent Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:5434
c.RadTreeView._click Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:5385
Telerik.Web.UI.EventMap._onDomEvent Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:3114
(anonymous function) Telerik.Web.UI.WebResource.axd?_TSM_HiddenField_=RadScriptManager1_TSM&compress=1&_TSM_CombinedScri…:6
b
(The error refers to lines  10 and 14)


How to solve this problem ?
I’ll be glad for your help.

Thanks,

Daniel.

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 16 Jul 2014, 10:58 AM
Hi Daniel,

Please do the following modification in your JavaScript which works fine at my end.

JavaScript:
function TreeViewExpanCollaps_OnClientNodeClicked(sender, args) {
    var node = args.get_node();
    if (node.get_nodes().get_count() > 0) {
        if (!node.get_expanded()) {
            node.expand();
            args.set_cancel(true);
        }
        else {
            node.collapse();
            args.set_cancel(true);
        }
    }
}

Thanks,
Shinu.
0
Daniel
Top achievements
Rank 1
answered on 17 Jul 2014, 11:51 AM
Hey Shinu,

 
Thank you for the quick response.

Your code works but it throws the same error as before “ERROR:Uncaught TypeError: undefined is not a function”.

I Attached video that shows the situation where the error is thrown.
[RadTreeView Error Video]


I’ll be glad for a solution without any errors.

 

Thanks,

Daniel.
0
Accepted
Shinu
Top achievements
Rank 1
answered on 17 Jul 2014, 12:29 PM
Hi Daniel,

Try to attach the OnClientNodeClicking event which works fine at my end. OnClientNodeClicked event doesn't have args.set_cancel property because of that it was showing this error.

Thanks,
Shinu.
0
Daniel
Top achievements
Rank 1
answered on 17 Jul 2014, 12:53 PM
Hi Shinu,

 
Thank you for the very quick response!!!

It's work!

Thanks,

Daniel.
Tags
TreeView
Asked by
Daniel
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Daniel
Top achievements
Rank 1
Share this question
or