Node Checkboxes

Set the showCheckboxes property to true and the TreeView will add checkboxes to each node.

When checkboxes are displayed, the TreeView manages their hierarchy so that when a checkbox is checked or cleared, the new value is automatically applied to all child nodes, and reflected on the state of the parent nodes.

When items are checked or unchecked, the checkedItemsChanged event is raised, and the checkedItems property is updated with a list of the items that are currently checked:

Electronics
Trimmers/Shavers
Tablets
Phones
Apple
Motorola
Nokia
Samsung
Speakers
Monitors
Shopkins
Train Sets
Science Kit
Play-Doh
Crayola
Coffeee Maker
Breadmaker
Solar Panel
Work Table
Propane Grill
    
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// This file locates: "Scripts/Lesson/C1Nav/Checkboxes.js".
c1.documentReady(function () {
    var tree = wijmo.Control.getControl('#theTree');
 
    tree.showCheckboxes = true;
    tree.checkedItemsChanged.addHandler(function (s, e) {
        var items = s.checkedItems,
            msg = '';
        if (items.length) {
            msg = '<p><b>Checked Items:</b></p><ol>\r\n';
            for (var i = 0; i < items.length; i++) {
                msg += '<li>' + items[i].Header + '</li>\r\n';
            }
            msg += '</ol>';
        }
        document.getElementById('tvChkStatus').innerHTML = msg;
    });
 
    // handle buttons
    document.getElementById('btnCheckAll').addEventListener('click', function (e) {
        tree.checkAllItems(true);
    });
    document.getElementById('btnUncheckAll').addEventListener('click', function (e) {
        tree.checkAllItems(false);
    });
    document.getElementById('btnSaveState').addEventListener('click', function (e) {
        checkedItems = tree.checkedItems || [];
    });
    document.getElementById('btnRestoreState').addEventListener('click', function (e) {
        tree.checkedItems = checkedItems;
    });
});
1
2
3
4
5
6
7
8
9
10
11
// This file locates: "Content/css/Lesson/C1Nav/Checkboxes.css".
/* default trees on this sample */
.demo-control .wj-treeview {
    display:block;
    height: 350px;
    font-size: 120%;
    margin-bottom: 8px;
    padding: 6px;
    background: #f0f0f0;
    box-shadow: 0 3px 6px rgba(0,0,0,0.16), 0 3px 6px rgba(0,0,0,0.23);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
using System.Web.Mvc;
 
namespace LearnMvcClient.Controllers
{
    public partial class C1NavController : Controller
    {
        // GET: Checkboxes
        public ActionResult Checkboxes()
        {
            return View(Models.TreeViewData.GetData(Url));
        }
    }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
@model IEnumerable<TreeViewData>
 
<h1>
    @Html.Raw(Resources.C1Nav.Checkboxes_Title)
</h1>
 
<p>
    @Html.Raw(Resources.C1Nav.Checkboxes_Text1)
</p>
<p>
    @Html.Raw(Resources.C1Nav.Checkboxes_Text2)
</p>
<p>
    @Html.Raw(Resources.C1Nav.Checkboxes_Text3)
</p>
 
@Html.C1().TreeView().Id("theTree").Bind(Model).DisplayMemberPath("Header").ChildItemsPath("Items")
<button id="btnCheckAll" class="btn btn-default">
    @Html.Raw(Resources.C1Nav.Checkboxes_Text4)
</button>
<button id="btnUncheckAll" class="btn btn-default">
    @Html.Raw(Resources.C1Nav.Checkboxes_Text5)
</button>
  &nbsp;&nbsp;&nbsp;&nbsp;
<button id="btnSaveState" class="btn btn-default">
    @Html.Raw(Resources.C1Nav.Checkboxes_Text6)
</button>
<button id="btnRestoreState" class="btn btn-default">
    @Html.Raw(Resources.C1Nav.Checkboxes_Text7)
</button>
 
<div id="tvChkStatus"></div>