I got the following .js file which is called on each page of my website and automatically transforms tables to DataTables:
$.extend( $.fn.dataTable.defaults, {
"buttons": [
$.extend( true, {}, buttonCommon, {
extend: 'excelHtml5',
exportOptions: {
columns: ':visible'
}
} ),
$.extend( true, {}, buttonCommon, {
extend: 'pdfHtml5',
orientation: 'landscape',
exportOptions: {
columns: ':visible'
}
} ),
$.extend( true, {}, buttonCommon, {
extend: 'print',
exportOptions: {
columns: ':visible'
},
orientation: 'landscape'
} )
]
} );
//Render datatables
$(document).ready(function() {
if ($('.data-table').length !== 0)
{
$('.data-table').DataTable();
}
});
When I export a table (i.e. excelHtml5, pdfHtml5 or print), I want the exported document's title to display the table's data-exporttitle attribute if the table has such attribute, or else display a default value. Currently and by default, the title displays the page header title.
How can the above script be modified in order to achieve this?
If this info is of any help, some pages on my website contain more than one table.
My first reflex was to add the following "title" line of code in each extend function, but it doesn't work:
$.extend( true, {}, buttonCommon, {
extend: 'pdfHtml5',
orientation: 'landscape',
title: $(this).data("export-title")
} ),