Search code examples
jquerykendo-treeview

KendoTreeView Checkbox Clear All


I am using KendoTreeView control for hierarchical data. Also I need to provide ClearAll feature where all other fields in form including selections made in KendoTreeView should be cleared. So I have written something like this :

 public ClearAll(): void {
        $('#myTreeView').find('input:checkbox').each(function (index,element) {
            $(element).prop('checked', false);
        });
            }

Though this clears all selected checkboxes from treeview, however after this if I check parent node again - child checkboxes does not get checked.

Also this behavior (child nodes not getting checked) happens for first time only, so if I uncheck and check parent node again - child nodes will be checked.

I simulated sample example for this issue :

http://dojo.telerik.com/@rahul_ec27/ALihu


Solution

  • The HTML

    <button id="btnclear" class="k-button" onclick="ClearAll();">Clear All</button>
    

    JavaScript

    <script>
    function ClearAll()
    {
        $(".k-treeview .k-checkbox input").prop("checked", false).trigger("change");
    }
    </script>