TreeView get ID of checked node

4 posts, 0 answers
  1. Philip
    Philip avatar
    2 posts
    Member since:
    Mar 2013

    Posted 05 Sep 2014 Link to this post

    Hi, I want to get the id of the checkbox the user clicks on, but it doesn't seem like it's working.  Thank you all in advance.

    @(Html.Kendo().TreeView()
        .Name("treeview")
        .HtmlAttributes(new {@class="demo-section" })
        .Checkboxes(checkboxes => checkboxes
            .Name("checkedGuide")
            .CheckChildren(true)
        )
        .DataTextField("Name")
        .DataSource(dataSource => dataSource
            .Read(read => read
                .Action("GetTree", "AuthService")
            )
        )
    )

    <script>

        $("#treeview").on("change", ":checkbox", function (e) {
            var data = $("#treeview").data('kendoTreeView').dataItem(e.node);
            alert(data.id);
        });

    </script>
  2. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 08 Sep 2014 Link to this post

    Hello Philip,

    Instead of manually wiring up the checkbox change event, use the newly introduced check event (since 2014.Q2.SP1) -- it will give you the e.node parameter that is unavailable in jQuery event handlers.

    Regards,
    Alex Gyoshev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
  4. Philip
    Philip avatar
    2 posts
    Member since:
    Mar 2013

    Posted 08 Sep 2014 in reply to Alex Gyoshev Link to this post

    Hello Alex,

    Thanks for you reply.  I will not be able to update to the new version, currently I'm using (2014.1.318), is there any way I can get the ID without my current version?

    Thanks
  5. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 09 Sep 2014 Link to this post

    Hello Philip,

    Yes, you can. Instead of using e.node in the event handler, use e.target. Here is a Dojo snippet that shows this.

    Regards,
    Alex Gyoshev
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready