如何通过键盘方向键获取聚焦单元格时的聚焦单元格值
您可以通过使用
获取焦点单元格var focusedCell = gridOptions.api.getFocusedCell();
或使用 onCellFocused 事件。
两者都具有以下特性:
使用行索引来检索行节点:
var row = gridOptions.api.getDisplayedRowAtIndex(rowIndex);
之后,您可以使用这些属性来检索单元格的原始值:
var cellValue = gridOptions.api.getValue(colKey, row.node)
我不确定 UI 库绑定之间的 API 是否会发生变化,但这对我来说对 vue 有用:
const cellFocused = (evt) => {
const focusedCell = evt.api.getFocusedCell();
const row = evt.api.getDisplayedRowAtIndex(focusedCell.rowIndex)
const cellValue = evt.api.getValue(focusedCell.column, row)
console.log("xxx cell was value", cellValue);
};
亚历克斯的答案可能在过去有效,但现在不行。 Row.node 不存在,并且 colSelected 是列标题的字符串表示形式,而不是 Id。 获取选定单元格值的最简单方法(单击或右键单击)是:
let colSelected = params.column.colId;
let selectedCell = gridOptions.api.getFocusedCell();
let row = gridOptions.api.getDisplayedRowAtIndex(selectedCell.rowIndex);
const value = gridOptions.api.getValue(colSelected,row);