Select line in datatable and get id

Asked

Viewed 1,973 times

3

  • 1

    You can put the code here, or join an example in jsFiddle for example?

  • http://jsfiddle.net/miguelpacifico/4jjkrqew/

2 answers

1

With this code you will get the contents of the column:

$('th').click(function(){
        alert($(this).html());
    });

You just have to adapt your need.

0

In your Jsfiddle code just change the on-click event from the button to this:

$('#btnGetId').click( function () {
    alert($('#example tr.selected').children(':first-child').html());
} );

What you are doing in this case is taking the existing value inside the first column, but this can vary quite a lot.

Could you put the id of the line (tr) with the value of the id field and could take as follows:

$('#btnGetId').click( function () {
    alert($('#example tr.selected').attr('id'));
} );

Getting safer, because if you change the order of the columns your id will continue searching from the same place.

Or add a specific class to the id column and you can recover it like this:

$('#btnGetId').click( function () {
    alert($('#example tr.selected').children('.id').html());
} );

Browser other questions tagged

You are not signed in. Login or sign up in order to post.