Data source with JSON requests in TreeList HTML helper

1 Answer 100 Views
TreeList
Lukas Körfer
Top achievements
Rank 2
Lukas Körfer asked on 17 Jan 2022, 08:45 AM | edited on 17 Jan 2022, 08:46 AM

When adding a data source to a TreeList using the HTML helper method Html.Kendo().TreeList<...>().DataSource(....) there is no possibility to define the data type that should be used. The data source accepts the JSON data generated by my API, but any updates are submitted using form data, The same problem appears when defining a standalone data source using the helper method Html.Kendo().DataSource<...>().TreeList(....). It is possible to change the TreeList(...) configuration to a Custom(...) configuration, however it is not possible to define the parent identifier of the model in this case.

Html.Kendo().DataSource<MyViewModel>()
        .Name("datasource")
        .TreeList(source =>
        {
            source.Batch(true);
            source.ServerOperation(false);
            source.Model(model =>
            {
                model.Id(x => x.Id);
                model.ParentId(x => x.Parent);
                model.Expanded(x => x.Expanded);
            });
            source.Read("Read", "Api");
            // No way to use JSON here
            source.Create(ajax => ajax.Action("Write", "Api").Type(HttpVerbs.Post));
            source.Update(ajax => ajax.Action("Write", "Api").Type(HttpVerbs.Put));
            source.Destroy(ajax => ajax.Action("Write", "Api").Type(HttpVerbs.Delete));
        })

1 Answer, 1 is accepted

Sort by
1
Accepted
Aleksandar
Telerik team
answered on 19 Jan 2022, 12:53 PM

Hello Lukas,

You are indeed correct. Currently the TreeListDataSource is configured internally to an Ajax() DataSource (type:"aspnetmvc-ajax"). I have logged an issue to extend the configuration, so the desired can be achieved using the HTML and TagHelpers:

GitHub issue

Until this is implemented, I can suggest defining an external dataSource using jQuery with the desired configuration and passing it to the TreeList HtmlHelper using the .DataSourceId() method, as demonstrated in the TreeList oData binding Demo

Regards,
Aleksandar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
TreeList
Asked by
Lukas Körfer
Top achievements
Rank 2
Answers by
Aleksandar
Telerik team
Share this question
or