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

RadTreeList - check enabled childnodes only

1 Answer 11 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 24 Jun 2019, 12:41 PM

In a RadTreeList, when a user clicks on a checkbox, I want to check its child nodes, but only ones that are enabled. The issue is that there is no API to determine if a node is enabled. I’m have been trying with JQuery selector, so far unsuccessfully.

I include the code as follows.



<telerik:RadTreeList  ID="rtlFolderView" runat="server" OnNeedDataSource="rtlFolderView_NeedDataSource" Width="100%" Height="100%"
ParentDataKeyNames="ParentDocumentFolderId" DataKeyNames="DocumentFolderId" AllowPaging="false" AllowMultiItemSelection="true" 
                            OnItemDataBound="rtlFolderView_ItemDataBound" AutoGenerateColumns="false" AllowSorting="true" ExpandCollapseMode="Server">
                            <ClientSettings>
                                <Selecting AllowItemSelection="true" />
                                <ClientEvents OnItemSelected="clientNodeChecked"  />
</ClientSettings>

//javascript.
function clientNodeChecked(sender, eventArgs) {
                var dataItem = eventArgs.get_item();
                var childNodes = dataItem.get_childItems();
                if (childNodes === null) {
return;
                }
                var isChecked = dataItem.get_selected();
                UpdateAllChildren(childNodes, isChecked);
            }

            function UpdateAllChildren(nodes, checked) {
                var i = 0;
var nodeCount = nodes.length;
                for (i = 0; i < nodeCount; i++) {
                    //console.log(nodes[i]._element.childNodes);
                    var found = false;
                    //$(nodes[i]._element.childNodes).each(function (index, elmnt) {
                        //console.log((elmnt));
                        //if (index > 0 &&  $(elmnt).attr('class').indexOf('aspNetDisabled') >= 0) {
                        //if (el.length > 0) {
                        //    found = true;
                        //    console.log(el);
                        //}
                    //});
                    //var chk = $(nodes[i]).find('input[type=checkbox]').first();
                    //var disabled = $(chk).attr('disabled');
if (!found) {
                            nodes[i].set_selected(checked);
                    }
                }
            }

 

Any help would be appreciated.

1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 27 Jun 2019, 10:49 AM
Hi Justin,

You can see whether a child checkbox is disabled by

        var isCheckboxDisabled = $telerik.$(nodes[i].get_element()).find("input[type=checkbox]")[0].disabled;
        alert(isCheckboxDisabled);

where disabled is an attribute of the HTML input type="checkbox" element

e.g.

function UpdateAllChildren(nodes, checked) {
    var i = 0;
    var nodeCount = nodes.length;
     
    for (i = 0; i < nodeCount; i++) {
 
        //console.log(nodes[i]._element.childNodes);
        var found = false;
        var isCheckboxDisabled = $telerik.$(nodes[i].get_element()).find("input[type=checkbox]")[0].disabled;
        alert(isCheckboxDisabled);
         
        //$(nodes[i]._element.childNodes).each(function (index, elmnt) {
        //console.log((elmnt));
        //if (index > 0 &&  $(elmnt).attr('class').indexOf('aspNetDisabled') >= 0) {
        //if (el.length > 0) {
        //    found = true;
        //    console.log(el);
        //}
        //});
        //var chk = $(nodes[i]).find('input[type=checkbox]').first();
        //var disabled = $(chk).attr('disabled');
        if (!found) {
            nodes[i].set_selected(checked);
        }
    }
}


Another approach to find the disabled checkboxes is

$telerik.$('input[type=checkbox]:disabled')

as explained at get all disabled checkboxes.

Regards,
Rumen
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
TreeList
Asked by
Justin
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or