New to Telerik UI for ASP.NET Core? Start a free 30-day trial
Configuring Local Hierarchical Data with CheckBox Functionality
Environment
Product Version | 2020.1.114 |
Product | Progress® Kendo UI® TreeView for ASP.NET MVC |
Description
Is there a way to set the hierarchical configuration in the model to a Kendo UI TreeView locally with checkbox selection?
Solution
The Kendo UI TreeView can be bound to a defined model from a controller and can be modified to specify if the item is checked or not. For example, here is the same TreeView used in the Binding to Local Data Live Demo with checkbox functionality. It is configured with Local Data Binding using the BindTo() method.
Razor
@using NameSpace.Models
@using Kendo.Mvc.UI.Fluent
@(Html.Kendo().TreeView()
.Name("treeview")
.Checkboxes(checkboxes => checkboxes
.Name("checkedFiles")
.CheckChildren(true)
)
//Inline data is set with the BindTo method
.BindTo((IEnumerable<CategoryItem>)ViewBag.inline, (NavigationBindingFactory<TreeViewItem> mappings) =>
{
mappings.For<CategoryItem>(binding => binding.ItemDataBound((item, category) =>
{
item.Text = category.CategoryName;
item.Checked = category.Checked;
})
.Children(category => category.SubCategories));
mappings.For<SubCategoryItem>(binding => binding.ItemDataBound((item, subCategory) =>
{
item.Text = subCategory.SubCategoryName;
item.Checked = subCategory.Checked;
}));
})
)