是否可以取消选择 Aggrid 中的特定行?

Is it possible to deselect a particular row in Aggrid?

我正在尝试取消选择 aggrid 中的特定行。 我已经浏览了文档,但找不到。

  gridOptions.api.deselectAll();

这就是我用来取消选择所有内容的方法rows.But有什么方法可以取消选择 Aggrid 中的特定行

我尝试了很多ways.Please帮助我度过难关。

ag-Grid 没有开箱即用的单行选择切换。这只是我根据官方文档的理解,我肯定对此有误。

因此,对于多行选择,它很容易并且开箱即用:

您只需要在 gridOptions(或您称之为配置对象的任何内容)中将 rowMultiSelectWithClick 设置为 true 并将 rowSelection 设置为 'multiple'

对于单行 select/deselect 我想出了以下 (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);
  }
}

您可以使用行节点 api 取消选择节点。

基于docs-

setSelected(newValue: boolean, clearSelection: boolean)
Select (or deselect) the node. newValue=true for selection, newValue=false for deselection. If selecting, then passing true for clearSelection will select the node exclusively (i.e. NOT do multi select). If doing deselection, clearSelection has no impact.

您需要先获取要取消选择的节点的 ID,然后执行类似 -

的操作
const node = gridOptions.api.getRowNode(id);
node.setSelected(false);