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

Treeview - Check children only if parent node is expanded

2 Answers 100 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ryan
Top achievements
Rank 1
Ryan asked on 22 Feb 2011, 06:08 AM
Hi folks,

Two questions. Firstly, I'm using this JavaScript currently to check all children.

function onTreeDataBound(e) {
    $('#AjaxTreeView').find("li:has(ul)")
                .find('> div > .t-checkbox :checkbox')
                .bind('click', function (e) {
                    var isChecked = $(e.target).is(':checked');
                    var treeView = $($(e.target).closest('.t-treeview')).data('tTreeView');
                    var checkboxes = $(e.target).closest('.t-item')
                                                .find('> ul > li > div > .t-checkbox :checkbox');
                    $.each(checkboxes, function (index, checkbox) {
                        $(checkbox).attr('checked', isChecked ? true : false);
                        treeView.checkboxClick(e, checkbox);
                    });
                });
}

What I would like, though, is for the children to be checked only when the item is expanded (only let items the user can see, to be checked). How would I accomplish this?

Second, is there any way to save all expanded nodes (even if it was just the first level) in a cookie, and re-expand them next load? I am using LoadOnDemand/AJAX binding, so the solution I saw already about setting a cookie wouldn't work in this case.

Thanks!

2 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 22 Feb 2011, 01:35 PM
Hello Ryan,

You can use the jQuery ":visible" selector to test whether the nodes are visible.

Regarding the second question, please take a look at the attached solution. It's the closest thing that we have to your requirement.

Regards,
Alex Gyoshev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Ryan
Top achievements
Rank 1
answered on 22 Feb 2011, 05:40 PM
Ah, yes, thank you. I'm still getting up to speed with jQuery's flexibility. Thanks for the sample project regarding persisting the treeview state as well - I will look into this shortly.
Tags
TreeView
Asked by
Ryan
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Ryan
Top achievements
Rank 1
Share this question
or