【问题标题】:How to focus on `ag-Grid` so the next key press is an key event come from `ag-Grid` itself如何专注于`ag-Grid`所以下一次按键是来自`ag-Grid`本身的关键事件
【发布时间】:2020-08-30 19:32:09
【问题描述】:

我为ag-Grid 制作了一些自定义导航组件。

一旦用户采取行动,我想关注ag-Grid 的行或单元格之一,就好像用户自己只是单击了ag-Grid 的单元格之一一样。

所以在这个聚焦之后,下次我按下像Up/Down/Left/Right这样的键时,它被注册为ag-Grid的键盘交互事件(Keyboard Interaction: Core Feature of our Datagrid) .

更具体地说,一旦按下箭头键,navigateToNextCell() 挂钩就会被调用。

我该怎么做?

我在以下方面进行了实验:

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

这些都不起作用。

【问题讨论】:

    标签: ag-grid ag-grid-react


    【解决方案1】:

    考虑到行索引index,关注行节点有效:

    const rowNode = document.querySelector(`.ag-row[row-index="${index}"] > .ag-cell`)
    if (rowNode) {
      rowNode.focus()
    }
    

    【讨论】:

      猜你喜欢
      • 2022-11-29
      • 2021-01-14
      • 2017-04-08
      • 2017-12-12
      • 2018-11-18
      • 2016-05-11
      • 2021-11-12
      • 2023-02-06
      • 1970-01-01
      相关资源
      最近更新 更多