Hello, I'm trying to pass the 'onKeyDown' function to my React component. Followed the docs and looked for any example on the net but I'm not able to do it. Can you please share an example on how to do it?:
My column definition
{
headerName: 'Email', field: 'email', editable:true,
suppressFilter: true, suppressSorting: true, suppressToolPanel: true,
cellEditorFramework: PATableCellEditor, <== How can I pass 'my' onKeyDown here?
},
Cell editor
export default class PATableCellEditor extends Component {
constructor(props) {
super(props);
// What I understood from the docs is that props.onKeyDown should be already in place
}
:
Thanks in advance,
Answering myself, found a workaround (or maybe this is the way to do it):
Cell editor
export default class PATableCellEditor extends Component {
constructor(props) {
super(props);
:
}
:
afterGuiAttached() {
// get ref from React component
let eInput = this.refs.textField;
:
// Add a listener to 'keydown'
let self = this;
eInput.addEventListener('keydown', function (event) {
self.myOnKeyDown(event)
});
:
}
:
// Stop propagating 'left'/'right' keys
myOnKeyDown(event) {
let key = event.which || event.keyCode;
if (key === 37 || // left
key === 39) { // right
event.stopPropagation();
}
}
:
thank you for feeding back and closing 馃憤
@ceolter I found a way to add my onKeyDown like this:
rowItem.cellEditorParams={
onKeyDown: myOnKeyDown,
}
but It works only when cellEditor is popup type.
As @LuisPalacios 's feedback
let eInput = this.refs.textField;
this is not a universal way for me because I get the render object dynamically and can't handle editor's refs. what should I do?
Thank you very much.
Most helpful comment
Answering myself, found a workaround (or maybe this is the way to do it):
Cell editor