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

[Solved] Extension ToTreeDataSourceResult ?

1 Answer 724 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Viesturs
Top achievements
Rank 1
Viesturs asked on 20 Apr 2015, 01:18 PM

I tried multiple times with many different ways to get data to be read by TreeList. While searching around I stumbled discovered that people are using ToTreeDataSourceResult extension before sending the data as Json. What is in that extension and where can I get it ?

 Trivial examples that should work, but does not:

public ActionResult GetServiceList([DataSourceRequest] DataSourceRequest request, ServiceViewModel viewModel)
{
    List<TestViewModel> result = new List<TestViewModel>()
    {
        new TestViewModel()
        {
            Id = 1,
            ParentId = null,
            Name = "Parent"
        },
        new TestViewModel()
        {
            Id = 2,
            ParentId = 1,
            Name = "Child"
        }
    };
 
    return Json(result, JsonRequestBehavior.AllowGet);
}

And in CSHTML:

@(Html.Kendo().TreeList<IMIS.FrontEnd.Areas.Policy.Models.TestViewModel>()
        .Name("treelist")
        .Columns(columns =>
        {
            columns.Add().Field(e => e.Name);
        })
        .Filterable()
        .Sortable()
        .DataSource(dataSource => dataSource
            .Read(read => read.Action("GetServiceList", "Health", new {Area="Policy"}))
                    .ServerOperation(false)
                                                    .Model(m =>
                                                    {
                                                        m.Id(f => f.Id);
                                                        m.ParentId(f => f.ParentId).DefaultValue(null);
                                                        m.Expanded(true);
                                                        m.Field(f => f.Name);
                                                    }) ).Height(540))

This example should make trivial Tree list, but it does nothing even though the Json data is passed. Is it because I am not using that extension ?

1 Answer, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 22 Apr 2015, 08:56 AM

Hello Viesturs,

ToTreeDataSourceResult, as well as ToDataSourceResult, are extension methods inside Kendo.Mvc.Extensions namespace.

These methods are used for processing the collection before being send as server response. These method also take care of formatting the response in a way which client DataSource can read and populate the widgets, i.e the data array is placed inside Data field in the response etc.

For your convenience I'm attaching a working example for binding TreeList widget.

Regards,
Nikolay Rusev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
TreeList
Asked by
Viesturs
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Share this question
or