Datatable change column names on excel export
Datatable change column names on excel export
ricardomartos
Posts: 1Questions: 1Answers: 0
Hello!
I'm new and I'm having trouble trying to change the names of columns when I export the table to Excel.
I have this:
$('#TableTest').DataTable({
autoWidth: false,
processing: true,
serverSide: true,
ajax: {
url: "/web/a/info",
type: 'GET',
data: function( d ) {
d.value = $('#some_option option:selected').val();
}
},
scrollCollapse: true,
paging: true,
jQueryUI: false,
order: [ 1, 'asc' ],
language: DTLang.language,
bDestroy: true,
columnDefs: [
{
"className": "text-center", "targets": "_all",
"targets": [7] ,"render": function ( data) {return "<a href='/web/someurl/id/"+data+"/other/"+$('#other_option option:selected').val()+"'>Edit</a>";}
}
],
selector:true,
dom: 'Bflrtip',
lengthMenu: [[10, 25, 50, 100, -1], [10,25, 50, 100, "All"]],
buttons: [
{
extend: 'excelHtml5',
text: '<span class="fa fa-file-excel-o"></span>Excel',
title: null,
exportOptions: {
modifier: {
page: 'all'
},
columns: [0, 2, 3, 4, 5, 6]
}
}
]
});
Could some one please help me? I'm getting seriously crazy.
Thanks.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Hi take a look at this please: https://datatables.net/reference/button/excelHtml5
Search for this text on that page please:
"As an example, let's modify the text shown in cell A1:"
That's what you would need to do!
Here is an example from my own coding as part of the "customize" function: