My question is primarily related to this statement in the wrt docs react component:
CellEditor parameter
onKeyDown The callback for passing the grid pressed a key - useful for transmitting to control key events (tab, arrows, etc.) back to the grid - however you do not need to call this because the grid is already listening to events as they propagate. This is only necessary if you are preventing the Propagation event.
I understand that the cellEditor parameters exist, since the props are passed to the reaction version of the component, but I can not find how to connect to onKeyDown , as indicated in the docs. In my constructor for my cellEditor there is an onKeyDown function and corresponds to onKeyDown specified in cellEditorParams inside the definition of my column (if it exists).
constructor(props) { super(props); // console.log(typeof props.onKeyDown == 'function') => 'true' }
But it was never reached if it just exists in the component
onKeyDown(event) { console.log('not reached'); }
It onKeyDown={this.props.onKeyDown} called if I put onKeyDown={this.props.onKeyDown} inside the top-level wrapper div around my input, but it still does not catch "Enter".
I tried listening to a cell containing my custom cell editor
this.props.eGridCell.addEventListener('keyup', (event) => { console.log(event.keyCode === 13) })
Which one captures input, click , but it seems to turn off when input is pressed, before I can capture the final click inside the field? I have seen behavior when this does not work, so I am very confused.
Currently, I have a simple MyCellEditor cell editor, which I try to focus and select the next cell when clicking is entered in addition to just a tab. I already have the ability to retrieve the rowIndex and column properties that I need from rowRenderer in this.props.api.rowRenderer , which I then use as:
this.props.api.rowRenderer.moveFocusToNextCell(rowIndex, column, false, false, true);
My problem is to prevent the distribution of the default event from "Enter".
Below is my cell editor and usage.
import React from 'react'; import _ from 'lodash'; class MyCellEditor extends React.Component { constructor(props) { super(props); this.state = { value: props.value, }; } getValue() { return this.state.value; } isPopup() { return false; } isCancelBeforeStart() { return false; } afterGuiAttached() { const eInput = this.input; eInput.focus(); eInput.select(); } onKeyDown(event) {
Column Definition:
columnDefs = [{ headerName: 'CustomColumn', field: 'customField', editable: true, cellClass: 'grid-align ag-grid-shop-order-text', sortable: false, cellEditorFramework: MyCellEditor, // Do I need cellEditorParams? cellEditorParams: { // onKeyDown: (event) => console.log('does not output') } }, ... }
React:
<AgGridReact columnDefs={columnDefs} rowData={this.props.rows} enableColResize="false" rowSelection="single" enableSorting="false" singleClickEdit="true" suppressMovableColumns="true" rowHeight="30" // onKeyDown also does nothing here onGridReady={this.onGridReady} onGridResize={() => console.log('grid resized')} onColumnResize={() => console.log('column resized')} />