multiple grids - add row

I have 2 grids in a page. I have single “Add” button to add rows.
I’ve implemented the add row in such a way that a row should be selected & then new row should be always added just below the selected row.

I want to add a row in grid 2 for example.
myGrid1.addRow(newId, “”, rowIndex);

here, addRow() function is called on the grid object. How to know in which grid the row has been selected, so that the new row can be added in the same grid?
Any help is appreciated.

You can attach event handler to the onRowSelect event of the grid and store “this” reference from that event to some var.

Later you can use it for adding new row ( it will be the last grid, in which row was selected )