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

Kendo Treeview with checkboxes, pre-select items on load and pass selected items on button click

2 Answers 884 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Dayana
Top achievements
Rank 1
Dayana asked on 22 Apr 2016, 09:29 AM

Hi,

 

I am using kendo treeview with checkboxes in ASP .Net MVC. The datasource for the treeview is a list of item and want some of them to be selected on loading the treeview and then I want to pass the newly selected items to the controller. I can achieve each one of the two separately(with a line of code for each functionality), but they seem to be mutually exclusive.

 

This is my code for the view:

@(Html.Kendo().TreeView()
                        .Name("PrescriptionProductInstructions")
                        .DataTextField("Name")
                        .Checkboxes(x => x.CheckChildren(true))
                        .CheckboxTemplate("<input type='checkbox' name='checkedFiles[#= item.id #]' value='#= item.id #' #if(item.IsChecked){# checked #}#/>")
                        .Events(events => events.DataBound("onDataBound"))
                        .Checkboxes(x => x.Name("PrescriptionProductInstructions"))                        
                        .DataSource(source => source.Read(read => read.Action("GetInstructions", "Note", new { productId = Model.ProductId, personId = Model.PersonId }))))

    <script>
         function onDataBound() {
            $("#PrescriptionProductInstructions").data("kendoTreeView").expand(".k-item");
        }
    </script>                         

 

The first bold line of code helps me pre-select some item when loading the tree and the second line of code helps me pass the list of ids of the selected items.

 

My question is whether I can have both functionalities as the same time? If yes, how?

 

Thanks in advance.

 

Regards,

 

Dayana Hadzhipetrova

2 Answers, 1 is accepted

Sort by
0
Accepted
Daniel
Telerik team
answered on 26 Apr 2016, 08:30 AM
Hello,

If you need to use template and set specific name to the input then you should set the name in the template:
.CheckboxTemplate("<input type='checkbox' name='PrescriptionProductInstructions' value='#= item.id #' #if(item.IsChecked){# checked #}#/>")


Regards,
Daniel
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Dayana
Top achievements
Rank 1
answered on 26 Apr 2016, 02:31 PM

Thanks for the reply. It all works now.

 

Regards,

 

Dayana

Tags
TreeView
Asked by
Dayana
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Dayana
Top achievements
Rank 1
Share this question
or