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

TreeList with dynamic binding

5 Answers 375 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
vlad
Top achievements
Rank 1
vlad asked on 20 Jul 2016, 11:48 AM

Hi!

I want to create TreeList with custom columns count. There is my code:

@(Html.Kendo().TreeList<dynamic>()
    .Name("treelist")
    .Columns(columns =>
    {
        foreach (System.Data.DataColumn column in Model.Columns)
        {
            var c = columns.Add().Field(column.ColumnName);
        }
    })
    .Filterable()
    .Sortable()
    .DataSource(dataSource => dataSource
        .Read(read => read.Action("Read", "Home"))
        .Model(m =>
        {
            var id = Model.PrimaryKey[0].ColumnName;
            m.Id(id);
 
            //m.ParentId(); what i should do here???
 
            foreach (System.Data.DataColumn column in Model.Columns)
            {
                var field = m.Field(column.ColumnName, column.DataType);
                if (column.ColumnName == id)
                {
                    field.Editable(false);
                }
 
            }
        })
    )
)

HomeController returns:

public ActionResult Read([DataSourceRequest] DataSourceRequest request)
        {
            DataTable products = DataCache.FullTable;
 
            if (request.Aggregates.Any())
            {
                request.Aggregates.Each(agg =>
                {
                    agg.Aggregates.Each(a =>
                    {
                        a.MemberType = products.Columns[agg.Member].DataType;
                    });
                });
            }
 
            return Json(products.ToDataSourceResult(request));
        }

I see examples on GutHub, but i don't find anything about dynamic binding.

5 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 25 Jul 2016, 07:38 AM

Hello Vlad,

We do not have an example of dynamic column binding just yet. The ParentId should be configured to the field that will hold the parent-child relationship -- otherwise the TreeList will only show the root-level items.

Regards,
Alex Gyoshev
Telerik by Progress
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
John A
Top achievements
Rank 1
answered on 30 Apr 2019, 05:00 AM

Hi Alex,

I am also looking for the same solution, Where loading tree list from the dynamic object.

Can i check if there is any update on the above original question. Thank you.

 

0
Boyan Dimitrov
Telerik team
answered on 01 May 2019, 11:06 AM
Hello,

I already replied in your support ticket thread. In order to avoid any confusions I would suggest to continue the discussion in the support thread. 

Regards,
Boyan Dimitrov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
David PettyJohn
Top achievements
Rank 1
answered on 12 Dec 2019, 10:52 PM

We are looking to use a TreeList control with some dynamic columns.  Is that possible in the latest version v2019.3?

Our technology stack:

ASP.Net MVC 5; (C#)

Razor;

.Net Framework 4.7.1

0
Tsvetomir
Telerik team
answered on 16 Dec 2019, 03:58 PM

Hi David,

I have noticed that you have submitted a ticket in our private system - duplicate to this one. It is recommended to avoid submitting duplicates as this would pollute your history and searching for a certain past thread would be more difficult. Nevertheless, I am posting below the answer that I provided there:

Binding the Kendo UI TreeList to a collection is possible after specifying valid Id and ParentId properties. Therefore, the model declaration would be as follows:

@(Html.Kendo().TreeList<dynamic>()
    .Name("treelist")
    .Columns(columns =>
    {
        columns.Add().Field("Id").Width(250).Title("First Name");
        columns.Add().Field("Position").Title("Last Name");
        columns.Add().Field("Phone");
        //columns.Add().Field(e => e.Extension).Title("Ext").Format("{0:#}");
    })
    .DataSource(dataSource => dataSource
        .Read(read => read.Action("GetStudents", "Home"))
        .ServerOperation(false)
        .Model(m => {
            m.Id("Id");
            m.ParentId<Nullable<double>>("ParentId").Nullable(true);
        })
    )
)

And the sample code that I used on the server-side:

        public ActionResult GetStudents([DataSourceRequest] DataSourceRequest request, int? id)
        {
            var collection = new List<dynamic>() { 
                new { Id = 1, Position= "CEO", Phone= "(555) 924-9726", ParentId = (string) null },
                new { Id= 2, Name= "Guy Wooten", Position= "Chief Technical Officer", Phone= "(438) 738-4935", ParentId= 1 },
                new { Id= 32, Name= "Buffy Weber", Position= "VP, Engineering", Phone= "(699) 838-6121", ParentId= 2 },
                new { Id= 11, Name= "Hyacinth Hood", Position= "Team Lead", Phone= "(889) 345-2438", ParentId= 32 },
                new { Id= 60, Name= "Akeem Carr", Position= "Junior Software Developer", Phone= "(738) 136-2814", ParentId= 11 },
                new { Id= 78, Name= "Rinah Simon", Position= "Software Developer", Phone= "(285) 912-5271", ParentId= 11 },
                new { Id= 42, Name= "Gage Daniels", Position= "Software Architect", Phone= "(107) 290-6260", ParentId= 32 },
            };

            return Json(collection.ToTreeDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }

Regards,

Tsvetomir
Progress Telerik

Get quickly onboarded and successful with your Telerik UI for ASP.NET MVC with the dedicated Virtual Classroom technical training, available to all active customers.
Tags
TreeList
Asked by
vlad
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
John A
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
David PettyJohn
Top achievements
Rank 1
Tsvetomir
Telerik team
Share this question
or