我正在尝试取消选择aggrid中的特定行。 我浏览了文档,但找不到文档。
gridOptions.api.deselectAll();
这就是我用来取消选择所有行的方法。但是有什么方法可以取消选择Aggrid中的特定行
我尝试了很多方法。请帮助我解决这个问题。
答案 0 :(得分:0)
ag-Grid无需切换开箱即用的单行选择。那只是我对官方文档的理解,我肯定对此是错误的。
因此,对于多行选择,它很简单并且开箱即用地受支持:
您只需要在gridOptions(或任何您称为config对象)中将rowMultiSelectWithClick
设置为true
,将rowSelection
设置为'multiple'
。
对于单行,选择/取消选择以下内容(working plunker):
const gridOptions = {
columnDefs: [
{ field: 'name' },
{ field: 'continent' },
{ field: 'language' },
],
defaultColDef: {
flex: 1,
resizable: true,
},
rowData: rowData,
// here i'm just checking for the right selection mode
// and firing my custom little function when the row is clicked
onRowClicked: this.rowSelection === 'single' && toggleRowSelection,
rowMultiSelectWithClick: true,
rowSelection: 'single'
};
let selectedRow = null;
// this function is just for keeping track of selected row id
// and programmatically deselecting the row by doing node.setSelected(false)
function toggleRowSelection({ node }) {
if (selectedRow !== node.id) {
selectedRow = node.id;
} else {
selectedRow = null;
node.setSelected(false);
}
}
答案 1 :(得分:0)
您可以使用行节点api取消选择节点。
基于docs-
setSelected(newValue:布尔值,clearSelection:布尔值)
选择(或取消选择)该节点。 newValue = true以供选择,newValue = false 取消选择。如果选择,则将true传递给clearSelection 将专门选择该节点(即,不进行多重选择)。如果在做 取消选择,clearSelection没有影响。
您需要首先获取要取消选择的节点的ID,然后执行-
const node = gridOptions.api.getRowNode(id);
node.setSelected(false);