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

Updating bound data does not update displayed node

1 Answer 177 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 27 Mar 2013, 06:17 AM
A remote hierarchical data source delivers JSON that looks like the following:  Note the .data property which contains additional information.
jQuery182041788989288830735_1364362919255([
{"id":"6a488457-5b85-48fc-be24-b469219564c4"
,"sprite":"custom3"
,"text":"Silk"
,"hasChildren":true
,"data"
  :{"nodetype":"Fabric"
   ,"level":3
   ,"activity":0
   ,"maintenance":NaN
   ,"status":3
   }
}
,
{"id":"8a9e479a-4448-462e-9151-b1913cc1660e"
,"sprite":"custom3"
,"text":"Wool"
,"hasChildren":true
,"data"
  :{"nodetype":"Fabric"
   ,"level":3
   ,"activity":0
   ,"maintenance":NaN
   ,"status":3
   }
 }
,
{"id":"da373cd1-4264-4096-9955-5527e6c49dd9"
,"sprite":"custom3"
,"text":"Canvas"
,"hasChildren":true
,"data"
  :{"nodetype":"Fabric"
   ,"level":3
   ,"activity":0
   ,"maintenance":NaN
   ,"status":4
   }
}
])

The template in the .kendoTreeView constructor is thus and will display additional status information when the treeview is rendering a 'level 3' node:
window.reportUrl = '/reporter';
window.statusCode = [ 'bla', 'bla', 'bla' ];
 
template:
"<span class='name'>#: item.text #</span>"
+ "# if (item.data.level == 3) {#"
  + "# if (item.hasChildren) {#"
    + " | <a href='#= window.reportURL #?id=#= item.id #' title='View Report' target='_blank'>"
      + "<img alt='View Report' class='cm-icon' src='/images/report.png'>"
    + "</a>"
  + "#}#"
  + "# if (('status' in item.data) && !isNaN(item.data.status)) {#"
    + " | <span class='cs-status'>Status: #= window.statusCode[item.data.status] #</span>"
  + "#}#"
+ "#}#"
My problem is that when a some property .data changes, the tree node is not redrawn.
User does some activity runs a getJSON that returns an updated status for an id.

$.getJSON ( .... )
.done (function (info) {
  // info looks like {result:{id:<some-id>,status:<some-status>}}
 
  var tv = $('#treeview').data('kendoTreeView');
  var dsData = tv.dataSource.get(info.result.id);
   
  dsData.data.set('status', info.result.status); // does not cause node to be redrawn
  dsData.set('data.status', info.result.status); // does not cause node to be redrawn
 
  dsData.set('text', 'BLA BLA BLA'); // DOES cause node to be redrawn
});
What would need to be done to have the treeview observe the 'additional information' in dsData.data (or dsData.data itself) and rerender when something gets set ?

I would prefer to _not_ have to do something like this (untested):
dsData.set('data.status', info.result.status);
dsData.set('text', dsData.text');

Thanks,
Richard

1 Answer, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 29 Mar 2013, 08:50 AM
Hi Richard,

 
Our dev team currently works on improving this behavior of the TreeView and update will be released in next internal builds, however until this update is released you can trigger manually the change event of the dataItem as a workaround. For convenience I created small JSBin demo which demonstrates how to trigger manually the change event after using the set method.

Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
TreeView
Asked by
Richard
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Share this question
or