如何将注意力集中在 "ag-Grid "上,使下一次按键是来自 "ag-Grid "本身的按键事件。

问题描述 投票:0回答:1

我做了一些自定义导航组件,用于 ag-Grid.

一旦用户的操作发生,我想关注其中的一个。ag-Grid的行或单元格,就像用户简单地点击其中一个 ag-Grid的细胞自己。

所以在这次聚焦之后,下一次我按下一个键,如 UpDownLeftRight它被注册为 ag-Grid的键盘交互事件 (键盘交互。我们数据表格的核心功能).

用更具体的话来说,就是 navigateToNextCell() 钩子应该在按下方向键后被调用。

怎样才能做到这一点呢?

我试验了一些东西,比如。

  • gridApi.setFocusedCell(0, 0)
  • gridApi.dispatchEvent({ type: 'cellFocused', rowIndex, column })
  • document.querySelector('.ag-root-wrapper').focus()

这些东西都没有用。

ag-grid ag-grid-react
1个回答
0
投票

聚焦在行节点上是可行的,给定的行索引是 index:

const rowNode = document.querySelector(`.ag-row[row-index="${index}"] > .ag-cell`)
if (rowNode) {
  rowNode.focus()
}
© www.soinside.com 2019 - 2024. All rights reserved.