title: Programmatically selecting and deselecting row in ag-grid
body: <p>I am selecting and deselecting some rows in ag-grid based on some condition. I am doing this in onRowDataChanged event, which will be called after grid has been loaded and row data being populated. When I am trying to achieve this in onGridReady event, it is called before row data being populated. So, I did this in onRowDataChanged event.</p>
  
  <p>This is my implementation of gridOptions.</p>
  
  <pre><code>ngOnInit() {
    this.gridOptions = &lt;any&gt; {
      rowSelection: 'multiple',
      onRowSelected: event =&gt; {
        // save selected rows in an array for additional work.
      },
      onRowDataChanged: event =&gt; {
        if (selectRows) {
           this.gridApi.selectAll();
        } else {
          this.gridApi.deSelectAll();
        }
      }
      onGridReady: params =&gt; {
        params.api.sizeColumnsToFit();
      }
    }
  }
  </code></pre>
  
  <p>Rows are selected and deselected properly based on condition.
  If I want to select or deselect certain rows also, I can use following code:</p>
  
  <pre><code>this.gridApi.getRowNode(index).setSelected(true);
  this.gridApi.getRowNode(index).setSelected(false);
  </code></pre>
  
  <p>But, I am facing one issue while selecting and deselecting rows programmatically. 
  After this.gridApi.selectAll(); is executed and grid rows are all selected, onRowSelected event is being fired. And the code which I am doing when that event is fired is executed for each row selection and deselection. </p>
  
  <p>onRowSelection event should only be fired if user select or unselect checkbox. And I am saving the selected rows in an array to send to server.</p>
  
  <p>But, when I am selecting or deselecting rows during onRowDataChanged programmatically, onRowSelection is also being fired. This will cause code on that event to be executed multiple times and is giving me performance impact when I have more than 400 rows.</p>
  
  <p>How can I select or deselect certain rows in ag-grid programmatically without firing onRowSelected event multiple times?</p>