Articles in this section
Category / Section

How to disable the parent node checking function in TreeView?

1 min read

Disable checking functionality for parent nodes in TreeView

 

In the TreeView component, you can disable the checking functionality for parent nodes. To achieve this requirement, the autoCheck property and nodeChecking event of the TreeView are used. The autoCheck property prevents autochecking of nodes, so when you check the child node, the parent node checkbox state will not be changed. The checking option for parent node in the nodeChecking event can be cancelled by using the cancel argument passed in the event. Refer to the following code block.

Javascript

// Render the TreeView with checkboxes 
var treeObj = new ej.navigations.TreeView({ 
    fields: { dataSource: checkBoxData, id: 'id', parentID: 'pid', text: 'name', hasChildren: 'hasChild' }, 
    showCheckBox: true,
    autoCheck:  false,
    nodeChecking: function (args) {
        unchecknode(args);
    }
}); 
treeObj.appendTo('#tree'); 
 
function unchecknode(args) { 
    var obj = ej.base.getComponent(document.querySelector('#tree'), 'treeview'); 
    var childNode = obj.getTreeData(args.node)[0].hasChild; 
    if (childNode === true) { 
        args.cancel = true 
    } 
} 

 

Final output



Sample: 

https://stackblitz.com/edit/hywlxg-yku4ay?file=index.js

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied