简体   繁体   中英

ag-grid: JavaScript Grid get row id

I am testing ag-grid and trying to get a row id when clicking on a row. I can see the value, but not retrieve it.

来自 ag-grid 的行 ID

There is no clue in the documentation. Any tip how to retrieve the data?

From the ag-grid website can you use the selectionChanged event, find the selected rows and from there you can access the associated data?

<ag-grid-angular>
  (selectionChanged)="onSelectionChanged($event)"
</ag-grid-angular>
onSelectionChanged() {
  const selectedRows = this.gridApi.getSelectedRows();
  const selectedId = selectedRows[0].id;
}

See this example: https://plnkr.co/edit/lfjvlLlbyixDOo6m

I've just reread your question and I didn't see you want to use rowClicked. Try this example: https://plnkr.co/edit/lfjvlLlbyixDOo6m

onRowClicked(params)
{
  console.log(params)
  const clickedItem = <dataItem>params.data;
  console.log(clickedItem.athlete)
}

ie cast the item appropriately before using it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM