To explain how to handle the events in the TreeView of Kendo UI, I’m going to use the following API's,
- GET: api/employees/Empdetails
- GET: api/employees/Empdetails/{EmployeeID}
If you are new to ASP.NET WEB API, please go through my previous article to get how to create a RESTful API using ASP.NET WEB API with Entity Framework.
The Employee model class in the project
- public class Employee
- {
- [Key]
- public int EmployeeId { get; set; }
- public string FullName { get; set; }
- public bool HasEmployees { get; set; }
- public int? ReportsTo { get; set; }
- }
The Employees Controller class
- public class EmployeesController : ApiController
- {
- private EmployeeContext db = new EmployeeContext();
- // GET: api/Employees
- [HttpGet]
- [ActionName("Empdetails")]
- public IQueryable<Employee> GetEmployees()
- {
- return db.Employees.Where(c=>!c.ReportsTo.HasValue);
- }
- // GET: api/Employees/5
- [HttpGet]
- [ActionName("Empdetails")]
- [ResponseType(typeof(Employee))]
- public IHttpActionResult GetEmployee(int EmployeeId)
- {
- var employee = db.Employees.Where(c=>c.ReportsTo== EmployeeId);
- if (employee == null)
- {
- return NotFound();
- }
- return Ok(employee);
- }
Change
- function onChange(e) {
- alert("Change Event Fired");
- }
Result in Browser

This event is fired before a subgroup gets collapsed.
- function onCollapse(e) {
- alert("Collapsing : " + this.text(e.node));
- }
DataBound
This event is fired after the dataSource change event has been processed.
- function onDataBound(e)
- {
- alert("DataBound Event Fired");
- }
- Drag start: Event is fired before the dragging of a node starts.
- function onDragStart(e) {
- console.log("Started dragging :" + this.text(e.sourceNode));
- }
- Drag: Triggered while a node is being dragged.
- function onDrag(e) {
- console.log("Dragging : " + this.text(e.sourceNode));
- }
- Drag End: Triggered after a node has been dropped.
- function onDragEnd(e) {
- console.log("Finished dragging :" + this.text(e.sourceNode));
- }
- Expand: This event is fired before a subgroup gets expanded.
- function onExpand(e) {
- alert("Expanding : " + this.text(e.node));
- }
Result in Browser
- Select: This event is fired when a node is being selected by the user.
- function onSelect(e) {
- alert("Selecting : " + this.text(e.node));
- }
Result in Browser
- <!DOCTYPE html>
- <html>
- <head>
- <title></title>
- <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1316/styles/kendo.common.min.css" />
- <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1316/styles/kendo.default.min.css" />
- <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1316/styles/kendo.dataviz.min.css" />
- <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1316/styles/kendo.dataviz.default.min.css" />
- <script src="http://cdn.kendostatic.com/2014.3.1316/js/jquery.min.js"></script>
- <script src="http://cdn.kendostatic.com/2014.3.1316/js/kendo.all.min.js"></script>
- <script src="http://cdn.kendostatic.com/2014.3.1029/js/jszip.min.js"></script>
- <script src="Scripts/console.js"></script>
- <meta charset="utf-8" />
- </head>
- <body>
- <h3>Kendo Tree View</h3>
- <br />
- <div id="treeview" class="demo-section"></div>
- <br />
- <br />
- <div class="box">
- <div id="myconsole" class="console">
- </div>
- </div>
- <script>
- function onSelect(e) {
- alert("Selecting : " + this.text(e.node));
- }
- function onChange(e) {
- alert("Change Event Fired");
- }
- function onCollapse(e) {
- alert("Collapsing : " + this.text(e.node));
- }
- function onExpand(e) {
- alert("Expanding : " + this.text(e.node));
- }
- function onDragStart(e) {
- console.log("Started dragging :" + this.text(e.sourceNode));
- }
- function onDrag(e) {
- console.log("Dragging : " + this.text(e.sourceNode));
- }
- function onDragEnd(e) {
- console.log("Finished dragging :" + this.text(e.sourceNode));
- }
- function onDataBound(e)
- {
- alert("DataBound Event Fired");
- }
- homogeneous = new kendo.data.HierarchicalDataSource({
- transport: {
- read: {
- url: "api/Employees/Empdetails",
- dataType: "json"
- }
- },
- schema: {
- model: {
- id: "EmployeeId",
- hasChildren: "HasEmployees"
- }
- }
- });
- $("#treeview").kendoTreeView({
- dataSource: homogeneous,
- dataTextField: "FullName",
- drop: ondrop,
- select: onSelect,
- check: onCheck,
- change: onChange,
- collapse: onCollapse,
- expand: onExpand,
- dragstart: onDragStart,
- drag: onDrag,
- dragend: onDragEnd,
- dataBound:onDataBound
- });
- }
- </script>
- </body>
- </html>


Arul RPosted Jan 17, 2016, 5:47 AM EST
Nice share
Santhakumar MunuswamyPosted Jan 5, 2016, 6:21 PM EST
Thanks for nice share
Muhammad Aqib ShehzadPosted Jan 5, 2016, 2:41 AM EST
Nice one
Arul RPosted Jan 4, 2016, 5:41 AM EST
Good one
Shridhar SharmaPosted Jan 4, 2016, 1:30 AM EST
nice share
Ankit BansalPosted Jan 4, 2016, 1:21 AM EST
Nice one..
Anu VPosted Jan 4, 2016, 12:15 AM EST
nice.
Raja TPosted Jan 3, 2016, 10:24 PM EST
Nice, thanks for sharing
Karthikeyan KPosted Jan 3, 2016, 9:53 PM EST
Good one...