Datatables 2 with Excel button - incorrect headers being exported
Datatables 2 with Excel button - incorrect headers being exported

Link to test case:
Debugger code (debug.datatables.net): ijisuh
Error messages shown: None
Description of problem: When exporting to Excel, the data cells contain the correct information as specified in the buttons.exportOptions object, however the headers appear to just be listing them in the order visible.
$('#ordersTable').DataTable({
ajax: {
url: '/api/v1/orders',
dataSrc: '',
},
columns: [
{ data: 'id' }, // 0
{ data: '', width: '54px' }, // 1
{ data: 'OrderNumber' }, // 2
{ data: 'NextStep' }, // 3
{ data: 'RiderFirstName' }, // 4
{ data: 'RiderLastName' }, // 5
{ data: 'RiderEmail' }, // 6
{ data: 'RiderFlagNumber' }, // 7
{ data: 'RiderShirt' }, // 8
{ data: 'PassengerName' }, // 9
{ data: 'PassFlagNumber' }, // 10
{ data: 'PassengerShirt' }, // 11
{ data: 'CharityName' }, // 12
{ data: 'updatedAt', type: 'date' }, // 13
{ data: 'isNew' }, // 14
{ data: 'applyFlagSurcharge' }, // 15
{ data: 'FlagSurchargeOrderNumber' }, // 16
{ data: 'CellNumber' }, // 17
{ data: 'RiderID' }, // 18
{ data: 'PassUserID' }, // 19
{ data: 'Address' }, // 20
{ data: 'City' }, // 21
{ data: 'State' }, // 22
{ data: 'ZipCode' }, // 23
],
columnDefs: [
{ targets: [0, 6, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23], visible: false },
],
language: {
entries: {
_: 'orders',
1: 'order',
},
},
layout: {
topStart: {
buttons: [
{
extend: 'excel',
text: 'Download Paid Orders',
title: 'TOH Paid Orders',
exportOptions: {
columns: [7, 4, 5, 6, 10, 9, 20, 21, 22, 23, 8, 11, 12, 2, 13],
modifier: {
search: 'none',
page: 'all',
},
},
sheetName: 'Paid Orders',
},
],
},
topEnd: 'search',
bottomStart: 'info',
bottomEnd: 'paging',
},
order: [[13, 'desc']],
pageLength: 100,
});
With the code snippet above I get the data from columns 7, 4, 5, 6, 10, 9, 20, 21, 22, 23, 8, 11, 12, 2, 13 (in that order); but I am getting the headers from columns 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 20, 21, 22, 23 (in that order).
Answers
What versions are you using of Buttons and DataTables? I was aware of that issue, but it should have been resolved in the latest releases.
Allan
@allan According to the debug tool, Buttons 3.2.2 and DataTables 2.2.2, both of which it states are the latest available.
I recently upgraded from Datatables 1.12.1, Buttons 2.2.3 and most of this code wasn't changed aside from converting to the new layout and language options.
I've managed to reproduce the error here: https://live.datatables.net/pepopivu/1/edit . Looking into it...
I've worked out why I found it familiar, it is something I fixed relatively recently! The fix is in the nightly build of DataTables and you can see it in operation here.
I'm aiming to release DataTables 2.3 (which includes this fix) before the end of the month. I think it is actually ready to go, but I'd like to let some of the nightly users try it out (beta testing) first.
Allan
I got home too late to try the nightly tonight, but will do so tomorrow evening for sure.