I noticed there is no event that fires when the treeview is loaded.
How can I set the selected node of tree if there's no callback that lets me know when it's done loading?
BTW I am using an ajax call to load the datasource.
Is there a workaround for this?
Thanks
7 Answers, 1 is accepted
The dataBound event is triggered after the treeview datasource has been processed. You can use it to achieve the desired effect. Please keep in mind that the event will be triggered after each binding, so you might want to add a check if there is a selected node already.
All the best,Alex Gyoshev
the Telerik team
$("#treeview").kendoTreeView({
dataSource: folderTree,
dataTextField: "Name",
dataBound: function(){ alert('here'); }
})
I am using a HierarchicalDataSource for the folderTree. Am I missing something?
-john-
Hi,
The databound method gets called before data is processed.
Code:
TreeViewBuilder treeViewCntrl = HtmlHelperExtension.Kendo(page.Html).TreeView();
treeViewCntrl
.DataTextField("Name")
.Checkboxes(c => c.Enabled(true).CheckChildren(true).Template("<input type='checkbox' name='checkedNode' value='#= item.Id #' />"))
.DataSource(dataSource => dataSource
.Read(read => read
.Action("Action", "Controller").Data("additionalData")))
.Events(e => e.Expand("expand"))
.ExpandAll(true)
.Events(e => e.DataBound("DisableCheckboxes('" + mdl.SelectedFunctionIdForGrpReport + "')"));
<script type="text/javascript">
var additional = {};
function expand(e) {
var id = this.dataItem(e.node).Id;
var name = this.dataItem(e.node).Name;
additional.Id = id;
//additional.Name = age;
}
function additionalData() {
return additional;
}
function DisableCheckboxes(selectedIds) {
if(selectedIds != '')
{
var treeview = $('#treeViewCntrl ').kendoTreeView().data('kendoTreeView');
var ids=selectedIds.split(',');
alert(selectedIds);
/*$.each(ids, function(i, id) {{
var data = treeView.dataSource.getByUid(id);
if (data == id) {
data.set('checked', true);
}
}});*/
}
}
</script>
I want to select the checkboxes by default based for the selectedIds. And disable the control.
Please help.
Thanks,
Rajashree.
I suggest that we continue our conversation on your ticket with ID: 997808.
Regards,
Eyup
Telerik
Hello,
I'm interested in a solution to this aswell. I need to perform certain operations in the treeview after it has completed loading the nodes (expand certain nodes).
How can I achieve that?
Thanks.
You can check the dataBound event handler to achieve this requirement. Please note that you should write it with a capital B:
http://docs.telerik.com/kendo-ui/api/javascript/ui/treeview#events-dataBound
Here is the sample to demonstrate this suggestion and some changes:
http://dojo.telerik.com/Evuwu/25
I hope this will prove helpful.
Regards,
Eyup
Telerik
Hey Eyup,
In my scenario, i need to repopulate the tree date if they editing tree with already selected data, in the case i use databound means it calling data bound many times, is there any methods there for tree is loaded data or not
Regards
Logesh