Ag-grid opposite method to cellFocused

老子叫甜甜 提交于 2020-06-13 11:46:59

问题


folks! Does anyone know the opposite method to cellFocused in ag-grid? I need to detect when the focused cell loses its focus and run some actions.

Thanks for your responses.


回答1:


I've found a way to support onBlur event. Since ag-grid doesn't have a built-in method, I created wy own event listener to the focus cell node and remove it after losing the focus state.

So, my code looks like this. Inside the react class I have 3 additional methods:

removeCellBlurListener = () => {
    const target = document.activeElement;
    if (target) {
        target.removeEventListener('blur', this.onCellBlur);
    }
};

addCellBlurListener = () => {
    const target = document.activeElement;
    if (target) {
        target.addEventListener('blur', this.onCellBlur);
    }
};

onCellBlur = () => {
    ...do something on blur
};

render () {
    return (
        <AgGridReact
              {...restProps}
              onCellFocused={(e) => this.addCellBlurListener()}
              onGridReady={this.onGridReady}
         />
    );
}


来源:https://stackoverflow.com/questions/61950465/ag-grid-opposite-method-to-cellfocused

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!