Select row in datatable and get id

3

In jquery datatable how do I select a single row and get the value of a particular column, such as id?

link

    
asked by anonymous 23.09.2014 / 23:36

2 answers

1

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

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

You just need to adapt your need.

    
24.09.2014 / 18:06
0

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

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

What you are doing in this case is getting the value within the first column, but this can vary greatly.

You could put the id of the line ( tr ) with the value of the id field and could pick up as follows:

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

Being more secure, because if you change the order of the columns your id will continue to search from the same place.

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

$('#btnGetId').click( function () {
    alert($('#example tr.selected').children('.id').html());
} );
    
25.09.2014 / 01:51