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

BindTo(...) vs. DataSource(...)

3 Answers 656 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Heiko
Top achievements
Rank 1
Iron
Veteran
Heiko asked on 17 Aug 2018, 08:41 AM

I noticed that the TreeView widget is behaving totally different when using BindTo(myViewModel.GroupList) versus using DataSource(<calling an action on a controller>). The problem: when using DataSource all additional fields like "Expanded" or "HtmlAttributes" are ignored by the TreeView widget so the TreeView looks different depending on which way I use it.

myViewModel.GroupList is a List<TreeViewItemModel>, the action on my Controller returns a JsonResult(List<TreeViewItemModel>,...). In fact both are exactly the same lists.

The code for DataSource is as follows:

.DataTextField("Text")
.DataSource(ds => ds
    .Read(read => read.Url(SettingsManager.BaseServiceUrl + "/groups/all/").Type(HttpVerbs.Get))
    .Model(model =>
    {
        model.Id("Id");
        model.Children("Items");
        model.HasChildren("HasChildren");
    })
)

 

Any idea why this happens?

Regards
Heiko

3 Answers, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 21 Aug 2018, 06:50 AM
Hello Heiko,

The difference comes from the fact that remote binding (through the DataSource configuration) binds only one level at a time. This means that child nodes (2nd, 3rd level and so on) are loaded only their parent node is expanded through separate requests to the Read action. As for the BindTo method it binds the TreeView completely thus you can specify the state (e.g. Expanded, Checked) of the nodes at different levels.

Regards,
Ivan Danchev
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
Heiko
Top achievements
Rank 1
Iron
Veteran
answered on 21 Aug 2018, 07:31 AM

Thanks for the reply. Unfortunately that is no explanation why a property like "htmlAttributes" is not used when using a DataSource.

Regards
Heiko

0
Ivan Danchev
Telerik team
answered on 23 Aug 2018, 06:42 AM
Hello Heiko,

The TreeView depends on the specified data fields when binding to remote data (dataTextField, dataUrlField, dataImageUrlField, dataSpriteCssClassField). There is no dataHtmlAttributes field implemented so if you want to set HtmlAttributes to the nodes we recommend using the BindTo method.

Regards,
Ivan Danchev
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.
Tags
TreeView
Asked by
Heiko
Top achievements
Rank 1
Iron
Veteran
Answers by
Ivan Danchev
Telerik team
Heiko
Top achievements
Rank 1
Iron
Veteran
Share this question
or