Unplanned
Last Updated: 23 Jul 2021 07:52 by ADMIN
RSR
Created on: 23 Jul 2021 07:27
Category: TreeView
Type: Bug Report
1
Indeterminate checkboxes are not cleared when unchecking all items

The TreeView has CheckBoxMode="@TreeViewCheckBoxMode.Multiple" and CheckParents="true". Only some checkboxes are checked and there are parent checkboxes in indeterminate state.

When I try to clear all checked checkboxes, the indeterminate checkboxes are not cleared and maintain their state.

1 comment
ADMIN
Dimo
Posted on: 23 Jul 2021 07:52

Hi,

Indeed, we reproduced the issue successfully and confirm the bug.

Fortunately, there is a workaround that you can use before we fix it:

  1. Check all items, so that there are no indeterminate checkboxes.
  2. Await a small delay.
  3. Uncheck all items.
<TelerikButton OnClick="@UncheckAll">Uncheck all</TelerikButton>

<TelerikTreeView Data="@TreeViewData"
                 CheckBoxMode="@TreeViewCheckBoxMode.Multiple"
                 @bind-CheckedItems="@CheckedItems"
                 CheckParents="true"
                 CheckChildren="true" />

@code {

    public IEnumerable<object> CheckedItems { get; set; } = new List<object>();

    public IEnumerable<TreeItem> TreeViewData { get; set; }

    private async Task UncheckAll()
    {
        // workaround start
        CheckedItems = TreeViewData;
        await Task.Delay(1);
        // workaround end
        CheckedItems = new List<object>();
    }

    protected override void OnInitialized()
    {
        LoadFlatData();

        var precheckedItem = TreeViewData.Where(x => x.Id == 2);

        CheckedItems = new List<object>(precheckedItem);
    }

    private void LoadFlatData()
    {
        List<TreeItem> items = new List<TreeItem>();

        items.Add(new TreeItem()
        {
            Id = 1,
            Text = "Project",
            ParentId = null,
            HasChildren = true,
            Icon = "folder",
            Expanded = true
        });

        items.Add(new TreeItem()
        {
            Id = 2,
            Text = "Design",
            ParentId = 1,
            HasChildren = false,
            Icon = "brush"
        });
        items.Add(new TreeItem()
        {
            Id = 3,
            Text = "Implementation",
            ParentId = 1,
            HasChildren = false,
            Icon = "folder"
        });

        TreeViewData = items;
    }

    public class TreeItem
    {
        public int Id { get; set; }
        public string Text { get; set; }
        public int? ParentId { get; set; }
        public bool HasChildren { get; set; }
        public string Icon { get; set; }
        public bool Expanded { get; set; }
    }
}

 

Regards,
Dimo
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.