javascript - 如何将焦点设置在 onRowClicked 行中的第一个可编辑单元格上?
问题描述
我有一个需要能够通过键盘进行编辑的 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);
这个来自 docs 的例子是一个很好的起点
推荐阅读
- angular - 角度参数路由不能作为外部链接
- amazon-web-services - AWS Cloudformation 部署引入新变量
- laravel - 用户模型扩展了 Authenticatable 并扩展了模型(用于雄辩的目的)
- batch-file - 如何在查找后删除选定的行数
- javascript - 实时绘图单点上的 Flot.js 不可见
- typescript - 如何在打字稿中覆盖浏览器 API 的构造函数定义?
- javascript - CORS 策略已阻止从源“localhost”访问“localhost”处的 XMLHttpRequest:对预检的响应
- c - printf 后的分段错误
- python - 如何使用 Python 代码找到本地网络中的所有 IP 地址?
- python - 如何将 CSV 文件中的行分成两个单独的文件,其中 ID 匹配特定条件