Getting row id, not by clicking but from Keyup event
Getting row id, not by clicking but from Keyup event
Tronik
Posts: 122Questions: 28Answers: 1
Hi!
Trying to get the row id, when user clicks enter in an input field on that row.
Changing the selectors do not help... Any suggestions on how to achieve this?
Current code just alerts undefined
$('#datatable tbody input').on( 'keyup change', function (ev) {
if (ev.keyCode == 13) {
alert( 'Row index: '+table.row( this ).id() );
return false;
}
} );
Thankful
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
There really isn't enough code here to go on. I think you have two issues with
table.row( this ).id()
this
is theinput
and not a row selector. You need to get the row that the input is on. Something like this maybe:row().id()
to work you need to have a row ID defined. As mentioned in the docs you may need to userowId
to define your row ID. Just a guess since you haven't provided this info.Kevin
Thank you!
Obvious really... the examples in docs are targeted to TR element.
As you pointed out id dont work but index did:
table.row( $(this).closest('tr') ).index();
And that gives me ID of row which is what I need