title: angular ui-grid selecting all under grouping
body: <p><a href="https://jsfiddle.net/4byyuqtc/1/" rel="nofollow noreferrer">https://jsfiddle.net/4byyuqtc/1/</a></p>
  
  <p><a href="https://i.stack.imgur.com/GQLW8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GQLW8.png" alt="enter image description here"></a></p>
  
  <p>I'm looking to have the ui-grid select all "children" under a grouping when the grouping line is selected. In this case Kit Kat(1), Mr. Goodbar(1), Krackel(2) and ultimately selecting the actual records (the non bold lines). One would expect that when selecting a parent in a grouping all it's children would get selected as well.</p>
  
  <p>Currently when selecting the 1 grouping above the actual records in the data (the non bold lines) it does select those actual records with the following code:</p>
  
  <pre><code>$scope.gridApi.selection.on.rowSelectionChanged($scope, function (rowChanged) {
      console.log(rowChanged.treeLevel);
      if (typeof (rowChanged.treeLevel) !== 'undefined' &amp;&amp; rowChanged.treeLevel &gt; -1) {
          // this is a group header
          children = $scope.gridApi.treeBase.getRowChildren(rowChanged);
          console.log(children);
          children.forEach(function (child) {
              if (rowChanged.isSelected) {
                  $scope.gridApi.selection.selectRow(child.entity);
              } else {
                  $scope.gridApi.selection.unSelectRow(child.entity);
              }
          });
      }
  });
  </code></pre>
  
  <p>I'm not experienced enough with ui-grid at this point to figure out how to cycle through children of the selected line and select all of them.</p>
  
  <p><strong>[EDIT]</strong></p>
  
  <p>With Paul's code below it doesn't select the groupings but it's closer. This screenshot is me selecting the first 337 record. Notice it selects that record and all the lowest child records (which is good because ultimately those are the ones that matter) but visually the grouped records (MFG and Item Desc group) aren't selected and need to be as the user won't ever open the lowest data records so they need to see the groups selected.</p>
  
  <p><a href="https://i.stack.imgur.com/4oyhI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4oyhI.png" alt="enter image description here"></a></p>