I am starting to work with a Kendo TreeView, I have an implementation which loads a number of treenodes at startup from a Asp MVC project
I'm not sure how to then dynamically load the other nodes, the documentation is pretty sparse in this area
I'm including the source below as I think it will be useful to others if nothing else. This code works for loading 'n' tree nodes
<script>
var dataSource = new kendo.data.HierarchicalDataSource( {
transport: {
read: function ( options )
{
debugger;
$.ajax( {
url: "/EmployeePicker/EmployeePicker/GetTreeRoot",
async: false, //ensure the response is received before exiting the content function
success: function ( r )
{
options.success( r );
}
} );
}
},
schema: {
model: {
children: "Children"
}
}
} );
dataSource.read();
var rootItems = dataSource.data();
rootItems[0].load(); // does not initiate AJAX request
$("#treeview").kendoTreeView({
dataSource: dataSource,
dataTextField: "Name"
} );
</script>
and the MVC side.
public JsonResult GetTreeRoot()
{
TreeNode root = new TreeNode("1", "Root", true);
TreeNode childA = new TreeNode("1.1", "ChildA", true);
TreeNode childA1 = new TreeNode("1.1.1", "ChildA1", false);
// this one has a child but we're not initialising it
TreeNode childB = new TreeNode("1.2", "ChildB", true);
root.Children.Add(childA);
root.Children.Add(childB);
childA.Children.Add(childA1);
List<TreeNode> list = new List<TreeNode>();
list.Add(root);
return Json(list, System.Web.Mvc.JsonRequestBehavior.AllowGet);
}