Book Image

Kendo UI Cookbook

By : Sagar Ganatra
Book Image

Kendo UI Cookbook

By: Sagar Ganatra

Overview of this book

Table of Contents (18 chapters)
Kendo UI Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using checkboxes to select nodes in TreeView


In TreeView, each node can have a checkbox associated with it. By using a checkbox, you can select multiple nodes in the tree and perform an action.

How to do it…

To add a checkbox next to a node in TreeView, specify the checkboxes attribute as true when initializing the TreeView widget:

$('#treeView').kendoTreeView({

  checkboxes: true

});

If you want the child nodes to be selected when the parent node is selected, then specify checkChildren as true:

$('#treeView').kendoTreeView({

    checkboxes: {
       checkChildren: true
    }

});

Now, when you select the parent node, all child nodes within the parent node would be selected. It is also possible to specify nodes as checked when they are rendered. In the DataSource configuration, specify checked as true:

$('#treeView').kendoTreeView({

  checkboxes: {
    checkChildren: true
  },

  dataSource: [{
    text: "Directory1",
    
    items: [ 
      {text: "File1.txt"}, 
      {text: "File2.txt"}...