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

4 posts, 0 answers
  1. Heiko
    Heiko avatar
    153 posts
    Member since:
    Oct 2012

    Posted 17 Aug 2018 Link to this post

    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

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    1780 posts

    Posted 21 Aug 2018 Link to this post

    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.
  3. Heiko
    Heiko avatar
    153 posts
    Member since:
    Oct 2012

    Posted 21 Aug 2018 in reply to Ivan Danchev Link to this post

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

    Regards
    Heiko

  4. Ivan Danchev
    Admin
    Ivan Danchev avatar
    1780 posts

    Posted 23 Aug 2018 Link to this post

    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.
Back to Top