RadTreeview Expand & collapse not happening

5 posts, 0 answers
  1. Bikash
    Bikash avatar
    3 posts
    Member since:
    Jan 2013

    Posted 26 Nov 2013 Link to this post

    Hi,

    I have below  javascript  function in code-behind file for expand & collapse node:

    private void SetActions()

    {

    String sString =

    @"

    function SaveTreeState(action)

    {

    var tree = $find('" + RadTreeView1.ClientID + @"');

    if(tree == null) { return; }

    var nodes = tree.get_allNodes();

    if(action == 'expand')

    {

    for(var cnt=0; cnt<nodes.length; cnt++)

    {

    nodes[cnt].expand();

    }

    }

    if(action == 'collapse')

    {

    for(var cnt=0; cnt<nodes.length; cnt++)

    {

    nodes[cnt].collapse();

    }

    }

    var expandedNodes = '';

    for(var cnt=0; cnt<nodes.length; cnt++)

    {

    if(nodes[cnt].get_expanded())

    {

    expandedNodes += nodes[cnt].get_value() + '|';

    }

    }

    SaveCookie('mpnotetreestate',expandedNodes);

    }

    function SaveCookie(name,value,days) {

    if (days) {

    if (days>730) {

    days=730;

    }

    var date = new Date();

    date.setTime(date.getTime()+(days*24*60*60*1000));

    var expires = '; expires='+date.toGMTString();

    }

    else var expires = '';

    document.cookie = name+'='+value+expires+'; path=/';

    }

    ";

    ScriptManager.RegisterClientScriptBlock(this, typeof(ViewNotes), "SaveTreeStateBlock", sString, true);

    ViewToolBar1.btnExpandAll.Attributes.Add("onclick", "try{SaveTreeState('expand');}catch(err){return;}return false;");

    ViewToolBar1.btnCollapseAll.Attributes.Add("onclick", "try{SaveTreeState('collapse');}catch(err){return}return false;");

    }



    In UI I am using the below:
    <cc2:MPTreeView BorderStyle="None" OnNodeDataBound="RadTreeView1_NodeDataBound" OnClientNodeCollapsed="SaveTreeState"

    OnClientNodeExpanded="SaveTreeState" ShowLineImages="false" ID="RadTreeView1" runat="server">

    <CollapseAnimation Duration="100" Type="None" />

    <ExpandAnimation Duration="100" Type="None" />



    I am not able to collapse the treeview control on button click nor able to expand ? Could u please suggest.

    Thanks
    Bikash
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 26 Nov 2013 Link to this post

    Hi Bikash,

    Please have a look into the following code snippet to expand/collapse RadTreeView on RadButton click.

    ASPX:
    <telerik:RadTreeView ID="RadTreeView1" runat="server" DataSourceID="SqlDataSource1"
        DataFieldID="id" DataFieldParentID="parentid" DataTextField="text">
    </telerik:RadTreeView>
    <telerik:RadButton ID="RadButton1" runat="server" Text="Expand/Collapse TreeView"
        AutoPostBack="false" OnClientClicked="OnClientClicked1">
    </telerik:RadButton>

    JavaScript:
    <script type="text/javascript">
        function OnClientClicked1(sender, args) {
            var treeview = $find("<%=RadTreeView1.ClientID %>");
            var length = treeview.get_allNodes().length;
            for (var i = 0; i < length; i++) {
                treeview.get_allNodes()[i].toggle();
            }
        }
    </script>

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Bikash
    Bikash avatar
    3 posts
    Member since:
    Jan 2013

    Posted 27 Nov 2013 Link to this post

    Hi Shinu,

    Can you please look into the code sample I have provided what's missing in that.
    I can't use ur sample code as we r using .ascx page & it has other dependency as per our project standards.

    Thanks
    Bikash
  5. Nencho
    Admin
    Nencho avatar
    1458 posts

    Posted 02 Dec 2013 Link to this post

    Hello Bikash,

    I have performed several tests, regarding the provided code snippet and it seems that it's working properly at my end. Here is a video, demonstrating the behavior at my end. Please make sure that you are correctly assigning the functions for expanding and collapsing to the btnExpandAll/btnCollapseAll of the ToolBar that you are using.

    Regards,
    Nencho
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  6. Bikash
    Bikash avatar
    3 posts
    Member since:
    Jan 2013

    Posted 02 Dec 2013 Link to this post

    Hi Nencho,

    It's working with the piece of the code.  The code was correct & I was not getting any error while doing client side script debugging.But due to some external dependency it was not working earlier .

    However thanks for your help & support.

    Thanks
    Bikash
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017