Programatically select row in UI-Grid without listener
<p>I want to select all rows of a grid by default, and I managed to do so by adding a data listener in onRegisterApi as specified in <a href="https://stackoverflow.com/questions/30329748/how-to-set-row-selection-to-newly-added-row?answertab=active#tab-top">this answer</a>:</p>

<pre><code>onRegisterApi : function(gridApi)
    {
      $scope.gridApi = gridApi; 
      $scope.gridApi.grid.registerDataChangeCallback(function(data)
        {
          $scope.gridApi.selection.selectRow($scope.gridOptions.data[0]);
        }, [uiGridConstants.dataChange.ROW]);
    }
</code></pre>

<p>Working plunkr: <a href="http://plnkr.co/edit/dzf6PZwKdZmSNvKzQeYH?p=preview" rel="nofollow noreferrer">http://plnkr.co/edit/dzf6PZwKdZmSNvKzQeYH?p=preview</a></p>

<p>However, I don't understand why it doesn't work without a listener, like</p>

<pre><code>onRegisterApi : function(gridApi)
    {
      $scope.gridApi = gridApi; 
        _.each($scope.gridOptions.data, function(companies, index){
          $scope.gridApi.selection.selectRow($scope.gridOptions.data[index]);
      });

    }
</code></pre>

<p>Non-working plunkr: <a href="http://plnkr.co/edit/XOliwXn2MLyH6nqO7pp4?p=preview" rel="nofollow noreferrer">http://plnkr.co/edit/XOliwXn2MLyH6nqO7pp4?p=preview</a></p>

<p>Can someone tell me why?</p>