I am using the Javascript datatables plugin: https://datatables.net Is it possible to specify the column type when exporting data to excel? I want to specify a certain column to be a time format in the final excel document. I have looked at the documentation: https://datatables.net/manual/index but I can't find any solution.
1 Answer
Yes, There is a function called columns.render which does exactly this.
Buttons has two different methods that can be used to format the data exported differently from the data that is shown in the table: orthogonal options as shown in this example and formatting functions. They both achieve basically the same thing in different ways: namely modification of the output data.
$(document).ready(function() {
$('#example').DataTable( {
ajax: '../../../../examples/ajax/data/objects.txt',
columns: [
{ data: 'name' },
{ data: 'position' },
{ data: 'office' },
{ data: 'extn' },
{ data: 'start_date' },
{ data: 'salary', render: function (data, type, row) {
return type === 'export' ?
data.replace( /[$,]/g, '' ) :
data;
} }
],
dom: 'Bfrtip',
buttons: [
{
extend: 'copyHtml5',
exportOptions: { orthogonal: 'export' }
},
{
extend: 'excelHtml5',
exportOptions: { orthogonal: 'export' }
},
{
extend: 'pdfHtml5',
exportOptions: { orthogonal: 'export' }
}
]
} );
} );
Referred from https://datatables.net/extensions/buttons/examples/html5/outputFormat-orthogonal.html