如何检索 ag-grid 中所选列的 ID?

How can I retrieve the Id of the selected column in ag-grid?

我使用 ag-grid 构建了这个网格:

我想知道用户何时单击以下特定单元格:
- 行号
- ColumnId(列定义中的字段属性)

到目前为止,我只能通过这种方式收集 rowId:

Relevant html code:

  (rowClicked)="getRowId($event)"

Relevant TypeScript code:

  getRowId(chosenRow) {
    console.log('chosenRow.node: ', chosenRow.node); 
}

我想知道是否可以使用类似的方法来检测用户刚刚选择了哪一列?
谢谢!

  (cellClicked)="updateDepartementsDropDownList($event);"

打字稿:

 updateDepartementsDropDownList(params) {
    const colId = params.column.getId();
    console.log('colId: ', colId);

  }

您可以通过简单地监听下面的网格单元格点击事件来实现这一点。

 this.gridOptions.onCellClicked = ((event: CellClickedEvent) => {
     const rowId = event.rowIndex;
     const colId = event.column.colId;
 });