Nathan Hart
Nathan Hart

Reputation: 346

Kendo Treeview checkbox check by Id

I'm trying to bind a Kendo Treeview with Checkboxes to a datasource, and then check specific checkboxes by the node id.. Here is what I have so far, I just can't seem to get it to work.

    function bindCheckboxToId(treeView, id) {


            var el = treeView.findByUid(id);
            var cb = el.find(".k-checkbox input");
            if (cb) {
                $(cb.selector).prop('checked', true);
            }

      }

Upvotes: 2

Views: 4411

Answers (1)

Joe
Joe

Reputation: 5487

If you know the UID already, would it work for you to get at this via the dataSource. That way the UI and backing source stay in sync?

function bindCheckboxToId2(treeView, id){
  var data = treeView.dataSource.getByUid(id);
    if (data) {
      data.set("checked", true);
    }
}

Which can then be called with bindCheckboxToId2($("#treeview").data("kendoTreeView"), "0c9802d5-770d-41ba-9aec-8233c708a5ce")

Upvotes: 3

Related Questions