In jquery datatable how do I select a single row and get the value of a particular column, such as id?
In jquery datatable how do I select a single row and get the value of a particular column, such as id?
With this code you will get the contents of the column:
$('th').click(function(){
alert($(this).html());
});
You just need to adapt your need.
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());
} );