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:

            .Columns(columns =>
                columns.Add().Field(e => e.Name);
            .DataSource(dataSource => dataSource
                .Read(read => read.Action("GetServiceList", "Health", new {Area="Policy"}))
                                                        .Model(m =>
                                                            m.Id(f => f.Id);
                                                            m.ParentId(f => f.ParentId).DefaultValue(null);
                                                            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
    Nikolay Rusev avatar
    2289 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.

    Nikolay Rusev
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top