Null Reference
Null Reference

Reputation: 11340

Setting kendoui treeview's checkbox's checked property to true on load

Here's how I'm binding my kendoui treeview

  @(Html.Kendo().TreeView()
  .Name("treeview")
  .Checkboxes(chkbxs =>
    {
       chkbxs.CheckChildren(true);
    })
  .BindTo((IEnumerable<TreeViewItemModel>)ViewBag.inlineDefault)
   )

how do I set some of the checkboxes checked property to true, on load? There's a bool property in TreeViewItemModel

Upvotes: 1

Views: 2911

Answers (1)

nemesv
nemesv

Reputation: 139758

You can use the ItemAction method to provide a delegate which sets the Checked property to true on each TreeViewItem.

Additionally you can write any conditional logic inside the ItemAction to only check some of them:

@(Html.Kendo().TreeView()
  .Name("treeview")
  .Checkboxes(chkbxs =>
    {                
       chkbxs.CheckChildren(true);
    })
  .ItemAction(item =>
    {
       if (checkSomeCondition(item))
           item.Checked = true;
    })
  .BindTo((IEnumerable<TreeViewItemModel>)ViewBag.inlineDefault)
  )

Upvotes: 1

Related Questions