RealGrid2 Guide
Tip
Check by linking child nodes in CheckBar

Checking by linking child nodes in CheckBar

This is an example where the parent node is also checked when all child nodes are checked. We processed the check by adding a check action in the onItemChecked() event that occurs when the check bar is checked.

function checkNode(grid, dataRow, checked) {
     var provider = grid.getDataSource();
 
     //Check parent node after checking sibling nodes
     checkSiblingNode(grid, dataRow, checked);
 
     //Check child node
     var desRows = provider.getDescendants(dataRow);
     if (desRows) {
         grid.checkRows(desRows, checked, false);
     }
};
 
function checkSiblingNode(grid, dataRow, checked) {
     console.log("start-rowId2 checkedValue: " + grid.isCheckedRow(2));
     var provider = grid.getDataSource();
     //parent node
     var parent = provider.getParent(dataRow);
     //Sibling nodes
     var sibling = parent == -1 ? provider.getChildren() : provider.getChildren(parent);
     console.log(sibling);
     var index = sibling.indexOf(dataRow);
     //Exclude yourself
     if (index !== -1) sibling.splice(index, 1);
 
     if (checked) {
         for (var i in sibling) {
             var value = grid.isCheckedRow(sibling[i]);
 
             if (checked != value) {
                 checked = false;
                 break;
             }
         }
     } else {
         checked = false;
     }
 
     if (parent > -1) grid.checkRow(parent, checked, false, false);
     //Control V display in checkBar.head area
     if (parent == -1) grid.setAllCheck(checked, false);
     if (parent > -1) checkSiblingNode(grid, parent, checked);
}
 
 
treeView.onItemChecked = function (grid, itemIndex, checked) {
   var dataRow = grid.getDataRow(itemIndex);
   checkNode(grid, dataRow, checked);
};