I want to send email with attached Excel created from Datatables buttons.
I created controller to send email.
and created datatables to export excel
I do not know how to get the excel in ajax to send to controller.
this is my code but it is not working
$('#example-table').DataTable({
dom: 'Blfrtip',
buttons: [
{
extend: 'excelHtml5',
title: 'Data',
text: 'Export To Excel',
exportOptions: {
format: {
body: function (inner, rowidx, colidx, node) {
if ($(node).children("input").length > 0) {
return $(node).children("input").first().val();
} else {
return inner;
}
}
}
},
action: function (e, dt, node, config) {
//var files = $.fn.dataTable.ext.buttons.excelHtml5.action.call(this, e, dt, node, config);
var table = $('#example-table').DataTable();
var data = table.buttons.exportData();
var files = $("#fileUploader").get(0).files[0];
var url = "/test/SendEmail";
formData = new FormData();
formData.append("fileUploader", files);
jQuery.ajax({
type: 'POST',
url: url,
data: formData,
dataType: 'xlsx',
cache: false,
contentType: false,
processData: false,
});
}
},
]