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

ExpandMode.ServerSide and Expanding nodes

10 Answers 175 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Mikko
Top achievements
Rank 1
Veteran
Mikko asked on 26 Feb 2020, 10:44 AM
When using ExpandMode.ServerSide with a TreeView, is it possible to setup expand level also or other ways to expand certain nodes automatically?

10 Answers, 1 is accepted

Sort by
0
Peter Milchev
Telerik team
answered on 02 Mar 2020, 08:36 AM

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.
0
Mikko
Top achievements
Rank 1
Veteran
answered on 05 Mar 2020, 09:44 PM

Hello Peter,

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

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

 

 

0
Peter Milchev
Telerik team
answered on 06 Mar 2020, 11:19 AM

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.
0
Mikko
Top achievements
Rank 1
Veteran
answered on 06 Mar 2020, 11:33 AM

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.

0
Rumen
Telerik team
answered on 11 Mar 2020, 09:34 AM

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.
0
Mikko
Top achievements
Rank 1
Veteran
answered on 11 Mar 2020, 10:24 AM

Hi Rumen,

We are getting closer, thanks.

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

Best regards, Mikko

 

0
Rumen
Telerik team
answered on 16 Mar 2020, 08:43 AM

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.
0
Mikko
Top achievements
Rank 1
Veteran
answered on 19 May 2020, 09:55 AM

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

 

0
Peter Milchev
Telerik team
answered on 22 May 2020, 10:15 AM

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.
0
Mikko
Top achievements
Rank 1
Veteran
answered on 22 May 2020, 04:10 PM

Hello,

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

Mikko

Tags
TreeView
Asked by
Mikko
Top achievements
Rank 1
Veteran
Answers by
Peter Milchev
Telerik team
Mikko
Top achievements
Rank 1
Veteran
Rumen
Telerik team
Share this question
or