How to get the focused cell value at the time focussing on the cell by using the keyboard arrow keys
Asked
Active
Viewed 2.5k times
2 Answers
31
You can either get the focused cell by using
var focusedCell = gridOptions.api.getFocusedCell();
or use the onCellFocused event.
Both give you the following properties:
- rowIndex: number
- column: Column
Use the row-index to retrieve the row-node:
var row = gridOptions.api.getDisplayedRowAtIndex(rowIndex);
After that you can use those properties to retrieve the raw value of the cell:
var cellValue = gridOptions.api.getValue(colKey, row.node)

Alexander Zbinden
- 2,315
- 1
- 17
- 21
-
@Mallikarjuna - I know it's been almost a month since you solved this, but do you have an example of how you implemented this with keyboard navigation? Thanks! – Matt Aug 10 '18 at 16:58
-
Selected row is not always focused row, so this did the trick for me. Keep it up! – Wadi Diaz-wong Apr 06 '22 at 01:48
-
how do you get `colKey`? – Philipp Munin Nov 19 '22 at 22:51
0
I'm not sure if the API changes between UI library bindings, but this worked for me with 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);
};

Artur Carvalho
- 6,901
- 10
- 76
- 105