Ag-grid Row selection

Komal Aneja picture Komal Aneja · May 17, 2018 · Viewed 15.3k times · Source

While selecting the rows of an ag-grid with the help of cell selection using : this.gridOptions.rowMultiSelectWithClick = true ; Is it possible to access the last selected row only for computation and keep the previously selected rows state intact.

Answer

Senal picture Senal · May 18, 2018

Adding to what Paritosh mentioned, you could listen to rowSelected event and maintain an array of nodes.

<ag-grid-angular
   [rowSelection]="rowSelection"
   (rowSelected)="onRowSelected($event)"
   [rowMultiSelectWithClick]="true"
   (selectionChanged)="onSelectionChanged($event)"></ag-grid-angular>
selectedNodes: RowNode[];     

onRowSelected(event) {
   if(event.node.selected) {
      this.selectedNodes.push(event.node);
   }
}

getLastItem() {
   return this.selectedNodes[this.selectedNodes.length - 1];
} 

You can call getLastItem() method any time according to your requirement and get the lastly selected node.