Q:

Focus loss in PrimeFaces/jquery inside table

I am using Primefaces,JSF and JQuery for my little webproject. I have a dataTable with some columns. The cells are inputText fields and editable. I get data and display them into the table.
When I edit values in the table and press enter, I want the cursor jump to the next cell. This works fine until I touched all relevant cells one time. That means I begin in the first row and go to the last row without any problems(it's like tabbing down only with enter key). If I reach the last row, the focus should go back to the first row after pressing Enter. But this doesn't work. I see for a very short time that the focus is in the first row, but after miliseconds the focus is getting loss.
Another example: I begin in row 3 and go down until the last row. Then the focus jumps to the first row until row 2. This works, but I can't focus row 3 again. I have no idea what happens and why this happens.
Here is the relevant code:    
JS part (the jquery selector works fine):
function cmid_jump(ind) {
console.log(ind);
ind++;
if($('#formPool\\:tabView\\:formTable\\:p1\\:'+ind+'\\:cmid').length >=1) { 
    console.log($('#formPool\\:tabView\\:formTable\\:p1\\:' + ind + '\\:cmid').click());
} 
else {
    console.log($('#formPool\\:tabView\\:formTable\\:p1\\:0\\:cmid').click());
}

}   
a part of Data Table (not all columns)
 <p:dataTable id = "p1" var = "pool" value = "#{controll_pool.data}" rowIndexVar="index" editable="true" editMode="cell" style="font-size: 12px">

                            <p:column id="columnMid" headerText= "Mittelkurs" style="font-size: 12px">
                                <p:cellEditor>
                                    <f:facet name="output">
                                        <h:outputText value = "#{pool.kurs_mid}" rendered="#{not empty pool.kurs_mid}"/>
                                    </f:facet>
                                    <f:facet name="input" >
                                        <p:inputText id= "cmid" onkeydown="if (event.keyCode == 13) {cmid_jump(#{index})}" styleClass="changeable" value="#{pool.mid}" />
                                    </f:facet>
                                </p:cellEditor>
                            </p:column>
</p:dataTable>

A:

try this, i did this in primefaces 5.0
function cmid_jump(ind) {
   ind++;
   var table =  $('#formPool\\:tabView\\:formTable\\:p1');
   var max_size = table.find('tbody tr').length;
   if(ind >= max_size){
       return cmid_jump(-1);  
   }
   var cell = table.find("tr[data-ri="+ind+"]").find('td:first');
   cell.click();
}

