Getting next or prev row id


I am using a normal grid that has a lot of remove and add row operations.
Is there any method that will give me the next and previous row ids(with respect to how they are shown on screen) of a selected row?
Thanks in advance

Id of the next row:

var selected_id=grid.getSelectedRowId() var next_id=grid.getRowId(grid.getRowIndex(selected_id)+1)

Id of the previous row:

var previours_id=grid.getRowId(grid.getRowIndex(selected_id)-1)