This is a migrated thread and some comments may be shown as answers.

Add checkbox only leaf node.

1 Answer 308 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Brijesh
Top achievements
Rank 1
Brijesh asked on 12 May 2020, 11:36 AM

I have a treeView with multiple hierarchy, and only leaf/last node should have checkbox, not any parent should have checkbox.

I have refered many threads and examples. Tried Checkboxes Template but that makes another issue that values did not get binded with checkbox.
I need treeview like (https://jsbin.com/edamuj/131/edit?html,output)

 

 

@(Html.Kendo().TreeView()
                                .Name("treeview")
                                .Events(e => e.Select("OnSelectTree").DataBound("OnDataBound")).ExpandAll(true)
                                .Checkboxes(checkboxes => checkboxesName("checkedFiles"))
                                .BindTo((List<DPS.Model.ReviewDocumentTreeViewItemModel>)ViewBag.DocumentTreeData, (Kendo.Mvc.UI.Fluent.NavigationBindingFactory<TreeViewItem> mappings) =>
                                {
                                    mappings.For<DPS.Model.ReviewDocumentTreeViewItemModel>(binding => binding.ItemDataBound((item, category) =>
                                    {
                                        item.Id = category.Id;
                                        item.Text = category.Name;
                                        item.Selected = category.IsSelected;
                                        item.HtmlAttributes.Add("data-allowselection", category.AllowSelection);
                                        item.Expanded = true;
                                        item.Checked = category.IsReviewed;
                                    }).Children(g => g.Items));
                                }))


1 Answer, 1 is accepted

Sort by
0
Aleksandar
Telerik team
answered on 14 May 2020, 08:00 AM

Hello Brijesh,

When using a checkbox template you will need to handle the change in checkbox state manually, for example as demonstrated in this article:

https://docs.telerik.com/kendo-ui/knowledge-base/check-checkbox-on-select-node

I also tried to reproduce the issue where the state is not bound correctly when a template is used, ut to no avail. I modified the Treeview demo and added the following checkbox template:

.CheckboxTemplate("# if (!item.hasChildren) { #" +
                "<input type='checkbox' name='checkedFiles[#=item.text#]' class='k-checkbox' #= item.checked ? 'checked' : '' #>" +
            "# } #")

The expanded state and checked state is bound as expected. I am attaching a sample project for you to review. If I missed the essence of the issue reported, would it be possible to modify the example so the behavior is isolated and send it back to me for further review?

Regards,
Aleksandar
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
TreeView
Asked by
Brijesh
Top achievements
Rank 1
Answers by
Aleksandar
Telerik team
Share this question
or