[英]Ag-grid Row selection
While selecting the rows of an ag-grid
with the help of cell selection using : this.gridOptions.rowMultiSelectWithClick = true
; 在使用以下单元格选择的帮助下选择
ag-grid
的行: this.gridOptions.rowMultiSelectWithClick = true
; Is it possible to access the last selected row only for computation and keep the previously selected rows state intact. 是否可以仅访问最后选定的行进行计算,并保持先前选定的行状态不变。
Adding to what Paritosh mentioned, you could listen to rowSelected
event and maintain an array of nodes. 添加Paritosh提到的内容,您可以监听
rowSelected
事件并维护一组节点。
<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. 您可以根据需要随时调用
getLastItem()
方法并获取最后选择的节点。
Sure, you have to use onRowSelected
event for that, in which you'll get the required data as event
argument. 当然,你必须使用
onRowSelected
事件,在其中你将获得所需的数据作为event
参数。
onRowSelected(event) {
console.log("row " + event.node.data + " selected = " + event.node.selected);
}
The data: event.node.data
数据:event.node.data
Selected or not: event.node.selected是否选中:event.node.selected
<ag-grid-angular
.....
[rowSelection]="rowSelection"
(rowSelected)="onRowSelected($event)"
[rowMultiSelectWithClick]="true"
(selectionChanged)="onSelectionChanged($event)"
></ag-grid-angular>
Here is the live example: Plunk - ag-grid rowMultiSelectWithClick 以下是实例: Plunk - ag-grid rowMultiSelectWithClick
Update 更新
You can use gridApi
to then get the last selected node. 您可以使用
gridApi
然后获取最后选择的节点。 This will even work when you are deselecting a row. 当您取消选择行时,这甚至可以工作。 It would give us the last row which was selected before deselecting the latest row.
它将为我们提供在取消选择最新行之前选择的最后一行。
getLastSelectedNode(){
let rows = this.gridApi.getSelectedRows();
if(rows.length > 0)
console.log(rows[rows.length - 1]);
else
console.log('No rows selected');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.