Goal: Make ag-Grid cell editable as a currency control.
Approach:
- Created a custom directive for currency.
- Created a custom cell editor, which uses that currency directive.
Issue:
In a normal scenario, on page load, control with directive (implements ControlValueAccesor) loads and writeValue() is called to initialize the value in the control. So, I'm displaying the value with the currency($) symbol using writeValue(). And when, user clicks on the control, I'm displaying the value without currency symbol by writing the logic in focus event.
Now, with ag-Grid, directive would not load on page load. It would load when control is clicked, since it is enclosed within a cell editor. So, on click/focus, the following gets called in the following order -
- focus event - It would set the control value to null, since no value has been set yet using writeValue. But soon after that, writeValue() is called.
- writeValue() - It would set the control value to the value with $ symbol, which I don't want. I want value without the $ symbol, on focus.
So, how can I call writeValue() before the focus event of the directive?
Note: Btw, 2-click functionality of cell-editor is working fine but I want 1-click solution, as I have set the focus on the control in afterGuiAttached().