【问题标题】:How do I set the focus on the first editable cell in a row onRowClicked?如何将焦点设置在 onRowClicked 行中的第一个可编辑单元格上?
【发布时间】:2019-06-29 13:20:15
【问题描述】:

我有一个需要能够通过键盘进行编辑的 ag-grid。我将 editType 设置为 fullRow,我希望能够添加 javascript,这样当我触发 onRowEditingStarted 事件时,它会转到第一个可编辑单元格,因为有时我的网格比屏幕大。

我可以获取 rowIndex,但我无法获取列集合来查看属性。我想保留 rowIndex,但获取第一个可编辑列并在那里设置焦点。 (现在,它是偶然选择触发事件的任何东西。)

谁有我可以看的例子?

我尝试过查看这里生成的对象:

onRowEditingStarted: function(params) {
   console.log("started row editing");
   console.log(params);
}

这给了我一个可以获取 rowIndex 和 columnApi 的事件。我希望这里的某个地方有一个用于执行 for 循环的集合,但我没有看到它。

【问题讨论】:

    标签: javascript ag-grid


    【解决方案1】:

    你可以在onRowEditingStarted中做类似的事情

    // scrolls to the first column, or first editable column. you can pass in the correct index
    var firstEditCol = params.columnApi.getAllDisplayedColumns()[0];
    /////
    params.api.ensureColumnVisible(firstEditCol );
    
    // sets focus into the first grid cell
    params.api.setFocusedCell(params.rowIndex, firstEditCol);  
    

    来自 docs 的 example 是一个很好的起点

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-04
      • 2019-01-08
      • 2012-08-26
      • 1970-01-01
      • 2011-08-28
      • 2023-02-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多