I am looking to extract the values from selected rows and store them in an array. However, I also need to remove a row from the result array when it is deselected. The issue with my current code is that every time I click on a row, the fileName values are being added to the result array (selectedRows) as many times as I clicked on the row. Here's a snippet of my code:
HTML:
<ag-grid-angular #grid
style="width : 603px; height:250px;" class="ag-theme-balham"
[rowData]="searchResults" [columnDefs]="columnDefs" [rowSelection]="selectionMode"
[rowMultiSelectWithClick] = true
(rowClicked)="onRowClicked($event)"
>
</ag-grid-angular>
component.ts:
export class ShowFilesComponent implements OnInit {
searchResults : Array<String>;
private selectedRows :Array<String>;
columnDefs = [
{headerName:"S No", valueGetter: (args) => this.getIndexValue(),checkboxSelection : true,headerCheckboxSelection: true,
headerCheckboxSelectionFilteredOnly: true,cellRenderer: 'selectedClient'},
{headerName : 'File Name', field:'fileName', sortable:true},
{headerName : 'word count', field:'wordCount', sortable:true}
]
constructor(private http: HttpClient,private r : Router, private s : FileListService) {
this.http.get(this.path).subscribe(
(data: any) => {
this.searchResults = data;
console.log(this.searchResults);
},
error => console.log(error)
);
}
}
ngOnInit() {}
onRowClicked(event){
this.selectedRows.push(event.node.data.fileName);
console.log(this.selectedRows);
}
}