Extension ToTreeDataSourceResult ?

2 posts, 0 answers
  1. Viesturs
    Viesturs avatar
    1 posts
    Member since:
    Apr 2015

    Posted 20 Apr 2015 Link to this post

    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 ?

  2. Nikolay Rusev
    Admin
    Nikolay Rusev avatar
    2284 posts

    Posted 22 Apr 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
Back to Top