for jQuery data table select, you should follow
this instruction.
If You want to add function handler inside of jQuery data table action button, you can make the handler function outside of datatable component.
first, this is the default of grid code with select data action button.
$(document).ready(function() {
var events = $('#events');
var table = $('#example').DataTable( {
dom: 'Bfrtip',
select: true,
buttons: [
{
text: 'Get selected data',
action: function () {
var dataselected= table.rows( { selected: true } );
console.log("dataselected:", dataselected);
}
}
]
} );
} );
Check at console browser and paste here what is console.log printed, at comments of this thread.
then replace this block:
console.log("dataselected:", dataselected);
with your custom function. i.e. PostSelectedData(dataselected);
var PostSelectedData = function(dataselected) {
$.ajax({
type: "POST",
url: '/Home/SelectedData',
data: '{obj: ' + JSON.stringify(row) + '}',
dataType: "json",
success: function(data) {
alert("success");
console.log("Success: ", data)
},
error: function(xhr, ajaxOptions, thrownError) {
alert('Failed to retrieve data.');
console.log("Failed:", xhr, ajaxOptions, thrownError)
}
});
}