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

Trying to add child nodes to TreeView

3 Answers 616 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 09 Feb 2017, 03:00 PM

Apologies for what I hope is a stupid question, given I'm new to MVC & web development.

I have a TreeView with manually added child nodes off the root. I then want to add child nodes to each of those nodes via a foreach loop

The code (that is wrong) is

    @(Html.Kendo().TreeView()
        .Name("treeview")
        .Items(treeview =>
        {
            treeview.Add().Text("Root")
                .Expanded(true)
                .Items(root =>
                {
                    root.Add().Text("Child")
                        .Expanded(true);

                    foreach(var item in Model.Entity.GrandChildData)
                    {
                        {add to Child } item.data;
                    }

 

Thanks

3 Answers, 1 is accepted

Sort by
0
Accepted
Joana
Telerik team
answered on 13 Feb 2017, 06:04 AM

Hello Andy,

You could append child nodes via the Items collection.

                                                                           

.Items(root => { 
root.Add().Text("Child")
   .Expanded(true)
   .Items(childNodes => {
foreach (var treeNodeEntity in Model)
{
childNodes.Add()
    .Text(treeNodeEntity.Name)
    .HasChildren(true)
    .Id(treeNodeEntity.ID);
}
});

You could review if BindTo action might be suitable for your scenario. I suggest that you go through our documentation and demos for TreeView:

 

Regards,

Joana

Telerik by Progress

Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Raj
Top achievements
Rank 1
answered on 15 Feb 2017, 03:10 PM

Hello All

I am trying to build a tree view using ASP.Net MVC from a list returning from controller. The List is a plain Normal List with no sub Model objects, But it has the duplicate column fields where i want to build a tree view removing duplicates.

For example Below is the List with duplicates in WASHINGTON NAVY YARD - 001 , SUPER CONCRETE CORP. - 001 and also the duplicates in Flow - Per Day for both.

 

 

2015-01-21 50050 Parameter Found MGD 0.02 1 WASHINGTON NAVY YARD - 001 Flow - Per Day
2015-02-28 50050 Parameter Found MGD 99.00 1 WASHINGTON NAVY YARD - 001 Flow - Per Day
2015-03-21 50050 Parameter Found MGD 0.00 1 WASHINGTON NAVY YARD - 001 Flow - Per Day

2015-01-21 80082 Parameter Found mg/L 3.74 1 WASHINGTON NAVY YARD - 001 BOD5 - Biochemical Oxygen Demand, 5 Day
2015-02-28 80082 Parameter Found mg/L 99.00 1 WASHINGTON NAVY YARD - 001 BOD5 - Biochemical Oxygen Demand, 5 Day
2015-03-21 80082 Parameter Found mg/L 2.16 1 WASHINGTON NAVY YARD - 001 BOD5 - Biochemical Oxygen Demand, 5 Day

2015-02-28 50050 Parameter Found MGD 99.00 1 SUPER CONCRETE CORP. - 001 Flow - Per Day
2015-03-31 50050 Parameter Found MGD 99.00 1 SUPER CONCRETE CORP. - 001 Flow - Per Day
2015-04-30 50050 Parameter Found MGD 99.00 1 SUPER CONCRETE CORP. - 001 Flow - Per Day

I want to have a nodes on WASHINGTON NAVY YARD - 001 , SUPER CONCRETE CORP. - 001, then sub nodes on Flow which looks like below

WASHINGTON NAVY YARD - 001
          Flow - Per Day

           2015-01-21 50050 Parameter Found MGD 0.02 1 WASHINGTON NAVY YARD - 001 Flow - Per Day
           2015-02-28 50050 Parameter Found MGD 99.00 1 WASHINGTON NAVY YARD - 001 Flow - Per Day

          BOD5 - Biochemical Oxygen Demand, 5 Day

SUPER CONCRETE CORP. - 001
         Flow - Per Day

can you help me out in building tree view for this scenario?

Thanks

Raj

0
Joana
Telerik team
answered on 16 Feb 2017, 05:54 PM

Hello Raj,

The Treeview widget does not support such grouping of list items based on custom requirements. The developer needs to implement the grouping and then pass the data to the TreeView.  You might find useful the demos of the widget showing databinding:

http://demos.telerik.com/aspnet-mvc/treeview/local-data-binding

Regards,
Joana
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
TreeView
Asked by
Andy
Top achievements
Rank 1
Answers by
Joana
Telerik team
Raj
Top achievements
Rank 1
Share this question
or