我想从选定的行中获取值并将其存储在一个数组中。当我取消选择一行时,我想将其从结果数组中删除。但是根据我的代码,我点击了多少次行值中的文件名多次添加到我的结果数组(selectedRows)中。我的代码是:
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>
组件.ts:
export class ShowFilesComponent implements OnInit {
searchResults : Array<String>;
private seletectedRows :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.seletectedRows.push(event.node.data.fileName);
console.log(this.seletectedRows);
}
}