javascript - 如何将焦点设置在 onRowClicked 行中的第一个可编辑单元格上?

标签 javascript ag-grid

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

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

谁有我可以看的示例?

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

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

这为我提供了一个事件,我可以在其中获取 rowIndex 和 columnApi。我希望这里的某个地方有一个集合来执行 for 循环,但我没有看到它。

最佳答案

您可以在 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);  

example来自文档是一个很好的起点

关于javascript - 如何将焦点设置在 onRowClicked 行中的第一个可编辑单元格上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54539217/

相关文章:

javascript - 文件不被缓存

Javascript警报框设计

javascript - 将 jQuery 转换为纯 JavaScript

angular - ag-Grid:找不到 agRichSelectCellEditor

reactjs - 使用react-select作为弹出自定义单元格编辑器时,ag-grid中的键盘事件出现问题

javascript - 使用 ag-grid 中的分组功能构建我们自己的 cellRenderer

javascript - html - 为什么单选按钮被多次选择而不是一个单选框?

javascript - React Native 应用程序显示错误,指出即使提供 key 后 key 也将未定义

ag-grid - 将 ag-grid 列绑定(bind)到数组

ag-grid - ag-grid 在可编辑和不可编辑模式之间切换