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

Treeview- parent node selection is not retrieving children node IDs

3 Answers 545 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Vidya
Top achievements
Rank 1
Vidya asked on 11 Jan 2013, 07:36 AM
Hi,

We want to send the list of checked node IDs in a treeview to the controller.
We are facing an issue when we check the parent node, we are not able to retrieve the children node IDS for the checked parent node.
This is because we are using the treeviews on change event of checkbox.
When we check the parent node, the children nodes would not have been checked by then in onchange event of treeview.
We want some post node selection event so that by then children nodes wouild have been checked automatically by default and we get their node IDs.
We tried using databound or requestend events,we were not able to capture the children node IDs.

we are getting the node IDs this way.
var checkedNodes=$("input:checked",treeview)

Please help.!

Thanks.!

3 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 14 Jan 2013, 01:50 PM
Hi Vidya,


I'm not sure what exactly you are trying to achieve but if you need to get the currently checked node children IDs you can use the following example:

$(function () {
    treeView = $("#treeview").data("kendoTreeView");
 
    //Bind Change event to all checkboxes under the TreeView
    $("#treeview input:checkbox").bind("change", function () {
 
        //Check if parent checkbox is checked
        if ($(this).prop("checked")) {
 
            allChildCheckboxes = $(this).closest(".k-item").find(".k-item");
 
            var childItemsIds = [];
 
            allChildCheckboxes.each(function () {
                currentDataItem = treeView.dataItem($(this));
                childItemsIds.push(currentDataItem.id);
            })
            //Now the childItemsIds contains the child items id's
            console.log(childItemsIds);
        }
    })
})


Kind Regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Vidya
Top achievements
Rank 1
answered on 15 Jan 2013, 12:15 PM
Thanks Vlad.
It helped.

But I am facing one issue now.

We are bindign the treeview click to a grid.
The node IDS that are checked are passed to controller and the respective documents are loaded on the grid.

One issue is now if I uncheck one of the children, the code still returns the unchecked node child ID as well.

Can you please help me.
Thanks.!
0
Accepted
Vladimir Iliev
Telerik team
answered on 16 Jan 2013, 07:32 AM
Hi Vidya,


Basically the required functionality is not supported out-of-the-box and the example that I provided is custom code which you can use as a baseline (and modify it to meet your needs). 

 
Kind regards,
Vladimir Iliev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
TreeView
Asked by
Vidya
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Vidya
Top achievements
Rank 1
Share this question
or