ExpandMode.ServerSide and Expanding nodes

11 posts, 0 answers
  1. Mikko
    Mikko avatar
    32 posts
    Member since:
    Jun 2012

    Posted 26 Feb 2020 Link to this post

    When using ExpandMode.ServerSide with a TreeView, is it possible to setup expand level also or other ways to expand certain nodes automatically?
  2. Peter Milchev
    Admin
    Peter Milchev avatar
    894 posts

    Posted 02 Mar 2020 Link to this post

    Hello Mikko,

    One option that I can suggest is altering the LoadOnDemand method and programmatically set the ExpandMode to ClientSide and populate the nested children. 

    Attached you can find a simple example, that when expanding the "Products" node, loads its children and expands the "UI for ASP.NET AJAX" node also.

    private static void PopulateNodeOnDemand(RadTreeNodeEventArgs e, TreeNodeExpandMode expandMode)
    {
        DataTable data = GetChildNodes(e.Node.Value);
    
        foreach (DataRow row in data.Rows)
        {
            RadTreeNode node = new RadTreeNode();
            node.Text = row["Title"].ToString();
            node.Value = row["CategoryId"].ToString();
            if (Convert.ToInt32(row["ChildrenCount"]) > 0)
            {
                if (node.Value == "2")
                {
                    node.ExpandMode = TreeNodeExpandMode.ClientSide;
                    var args = new RadTreeNodeEventArgs(node);
                    PopulateNodeOnDemand(args, expandMode);
                }
                else
                {
                    node.ExpandMode = expandMode;
                }
            }
            e.Node.Nodes.Add(node);
        }
    
        e.Node.Expanded = true;
    }


    Regards,
    Peter Milchev
    Progress Telerik

    Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
  3. Mikko
    Mikko avatar
    32 posts
    Member since:
    Jun 2012

    Posted 05 Mar 2020 in reply to Peter Milchev Link to this post

    Hello Peter,

    Is there a way to "read" node depth, not value?

    "if (node.Value == "2")"

     

     

  4. Peter Milchev
    Admin
    Peter Milchev avatar
    894 posts

    Posted 06 Mar 2020 Link to this post

    Hello Mikko,

    The RadTreeNode has the Level property you can use:

    Regards,
    Peter Milchev
    Progress Telerik

    Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
  5. Mikko
    Mikko avatar
    32 posts
    Member since:
    Jun 2012

    Posted 06 Mar 2020 in reply to Peter Milchev Link to this post

    Hello Peter,

    Our problem is that we have so many nodes that it takes vary long time load those, over 15 sec.

    When using ServerSide expand mode it's much faster, but we need to open first 2-3 node levels on page load. This works fine without using ServeSide expand mode. With it we cannot pre-open nodes.

  6. Rumen
    Admin
    Rumen avatar
    14434 posts

    Posted 11 Mar 2020 Link to this post

    Hi Mikko,

    With this approach, the nodes are still not available on the time of rendering of the control and that's why the Level property does not work

    If you keep using the ExpandMode.ServerSide approach, you can expand only the root node using this approach:

            <script>
                function OnClientLoad(tree, args) {
                    var item = tree.get_nodes().getItem(0);
                    item.set_expanded(true);
                }
            </script>
            <telerik:RadTreeView RenderMode="Lightweight" OnClientLoad="OnClientLoad" ID="RadTreeView1" runat="server"  Height="300px"
                OnNodeExpand="RadTreeView1_NodeExpand">
            </telerik:RadTreeView>

    Regards,
    Rumen
    Progress Telerik

    Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
  7. Mikko
    Mikko avatar
    32 posts
    Member since:
    Jun 2012

    Posted 11 Mar 2020 in reply to Rumen Link to this post

    Hi Rumen,

    We are getting closer, thanks.

    Script only opens first node, not all root level nodes.

    Best regards, Mikko

     

  8. Rumen
    Admin
    Rumen avatar
    14434 posts

    Posted 16 Mar 2020 Link to this post

    Hi Mikko,

    You can expand all root items on load via the following script:

     

    <script>
        function OnClientLoad(tree, args) {
            var items = tree.get_allNodes();
            for (var i = 0; i < items.length; i++) {
                var item = items[i];
                item.set_expanded(true);
            }
        }
    </script>
    <telerik:RadTreeView OnClientLoad="OnClientLoad" ...

    You can also check the level of the respective item with the items[0].get_level() method.

     

    Regards,
    Rumen
    Progress Telerik

    Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
  9. Mikko
    Mikko avatar
    32 posts
    Member since:
    Jun 2012

    Posted 19 May 2020 in reply to Rumen Link to this post

    Hi!

    I have a another question/problem.

    If user opens a node (OnNodeExpand="RadTreeView1_NodeExpand") and closes and re-opens it, there are double entiries of all child nodes. So, each time node is closed and opened, childs are added. It there a solution for this?

    Best regards, Mikko

     

  10. Peter Milchev
    Admin
    Peter Milchev avatar
    894 posts

    Posted 22 May 2020 Link to this post

    Hello Mikko,

    The sample project that I have attached in my reply from March 2, 2020, this duplicate issue is not present. 

    Please modify the project so that it implements your logic and replicates the issue and send it back to us as an attachment to an official support ticket.

    That would allow us to investigate your exact scenario and provide more accurate and specific suggestions.

    Regards,
    Peter Milchev
    Progress Telerik

    Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
    Our thoughts here at Progress are with those affected by the outbreak.
  11. Mikko
    Mikko avatar
    32 posts
    Member since:
    Jun 2012

    Posted 22 May 2020 in reply to Peter Milchev Link to this post

    Hello,

    I looked at your sample and found a solution. Thanks!

    Mikko

Back to Top