40
Event For Cell In Focus During Editing igGrid
posted

I need to raise an event that I can handle when a particular cell's input field during editing mode comes into focus in the igGrid. I have two text fields in my grid, when I add a new row in the grid after the first field is set and the focus is set on the second field I want to capture the value currently in the first input field, perform some checks on it and set the value of the second input field(I want to do this while the editing mode is still active i.e the row is not inserted). 

I am aware of the cellediting events infragistics provide, but as it appears they all are fired for every cell at the same time when either I add a new row or when I press the Done button after filling in the fields. I cannot find an event when a particular cell's input field is in focus during editing. And as I mentioned, not only do I need the event, but I also need the values of the previous cell. I would appreciate you're assistance in this.

  • 17884
    Suggested Answer
    Offline posted

    Hello Omer Tariq,

     

    Thank you for posting in our forums!

    You could achieve this by hooking up a focus event on the input elements of the cells during the editCellStarting event.  If you do this, you would need to remove the handler during editCellEnded event or somehow keep track if you've added the handler already.

    Instead, I would recommend hooking up a delegated event.  You can do this with the following code for example:

    $($("#grid1").igGrid("headersTable")).on("focus", "td:nth-child(5) input", cellFocusEvent);

    This only needs to be called once, after the igGrid is initialized.  Using the above code will also only run on the add new row and the editCellStarting/editCellEnded method will work for all rows and both methods can me slightly modified to work both ways.

    I have attached a simple sample that demonstrates both of these methods.  In the add new row, insert values for the Quantity and Cost columns.  Then, focusing on the Total will automatically calculate the product of the other columns.  In my sample, the editCellStarting/editCellEnded are commented out to show how the delegated event will work.

    If you need and further assistance with this, please let me know and I will be glad to help.