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

MVVM - Treeview only updates on dataTextField change

9 Answers 178 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Scott
Top achievements
Rank 1
Scott asked on 24 May 2013, 05:24 PM
I have a treeview using a template for the nodes (see below).  Also have a form bound to the selected item in the treeview.  "Name" is speciified as the dataTextField.  My problem is the treeview is only updated when the Name field is changed.  It ignores changes to the Color field.  Is there some way to setup the template so that the nodes will change based on any of the referenced fields changing?

<script id="treeViewTemplate" type="text/x-kendo-tmpl">
    <span style="background-color:#: item.Color #">&nbsp;&nbsp;&nbsp;</span>
    #: item.Name #
</script>

9 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 28 May 2013, 12:42 PM
Hello Scott,

Indeed I was able to reproduce your case with the following code:

              <div id="treeview-left"></div>
           
 
          <script>
              var inlineDefault = new kendo.data.HierarchicalDataSource({
                  data: [
                    { text: "Furniture", someOtherField: "foo", items: [
                          { text: "Tables & Chairs" },
                          { text: "Sofas", someOtherField: "bar" },
                          { text: "Occasional Furniture" }
                      ]
                    },
                      { text: "Decor", items: [
                          { text: "Bed Linen" },
                          { text: "Curtains & Blinds" },
                          { text: "Carpets" }
                      ]
                      }
                  ]
              });
 
              var tv = $("#treeview-left").kendoTreeView({
                  dataSource: inlineDefault,
                  template: "-> #= item.text# #= item.someOtherField || '' #"
              }).data('kendoTreeView');
              debugger;
              tv.dataSource.at(0).set('someOtherField', 'CHANGED!');
              tv.dataSource.at(0).trigger('change');
</script>

Without adding the last line. I will inform the Dev team about this. As a work-around you can force the change when triggering the change manually like shown above.

Kind Regards,
Petur Subev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Rahul
Top achievements
Rank 1
answered on 01 Aug 2014, 06:28 PM
Hi Petur Subev,
I want to set the tree view node color based the value defined in the data source, I am not using MVVM way as Scott mentioned, will you please help me?

I created jsfiddle here,

http://jsfiddle.net/KendoDev/qZeK6/
0
Petur Subev
Telerik team
answered on 05 Aug 2014, 06:42 AM
Hello Rahul,

Please open separate ticket/thread for question not related to the original one. Before doing so please check the template property:

http://demos.telerik.com/kendo-ui/treeview/templates

Kind Regards,
Petur Subev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Ryan
Top achievements
Rank 1
answered on 03 Oct 2014, 05:21 PM
This bug does not appear to be fixed in the latest kendoui (2014.2.903).

It means that data binding and templates cannot be used together for treeview items. Only the text field appears to support updating.

Am I missing something?
0
Ryan
Top achievements
Rank 1
answered on 03 Oct 2014, 05:34 PM
I forgot to add that the workaround

        tv.dataSource.at(0).trigger('change');

seems to cause a weird thing where the other nodes after the first disappear from the tree when triggering that change event.

Thanks for any insight you have.
0
Alex Gyoshev
Telerik team
answered on 07 Oct 2014, 12:00 PM
Hello Ryan,

In order to update items when their dataItem is changed, you need to use the getters and setters provided by the Kendo UI ObservableObject. See this Dojo snippet for a sample.

Regards,
Alex Gyoshev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Ryan
Top achievements
Rank 1
answered on 07 Oct 2014, 02:42 PM
Hi Alex,

Thank you. That explains it, and it works great. However, I am also trying to bind the checkbox checked state using the same method, and it doesn't seem to work for updating (it works for the initial state). See dojo here: http://dojo.telerik.com/eMoPi/3

The line:

tree.dataSource.get(3).set("isSelected", true)

has no effect. 

Is there something I'm doing wrong?

Thanks!




0
Alex Gyoshev
Telerik team
answered on 08 Oct 2014, 09:00 AM
Hello Ryan,

I'm afraid that the checked state must be stored in the checked field, and changing the name is not supported, as the TreeView relies internally on that name. This is also the reason the checkChildren functionality does not work.

Regards,
Alex Gyoshev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Ryan
Top achievements
Rank 1
answered on 08 Oct 2014, 03:07 PM
Hi Alex,

You are right. Keeping the field named "checked" works. Thanks! Working snippet here: http://dojo.telerik.com/ARake/2


Tags
TreeView
Asked by
Scott
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Rahul
Top achievements
Rank 1
Ryan
Top achievements
Rank 1
Alex Gyoshev
Telerik team
Share this question
or