let buttons = [
{
className: 'btn btn-default',
extend: 'collection',
text: '匯出',
buttons: [
{
filename: function () {
return `VaccineList_${moment().format("YYYY-MM-DD HH:mm")}`;
},
extend: "excel",
action: exportAllRow,
extend: 'excelHtml5',
exportOptions: {
columns: [1, 2,3, 4, 5, 6, 7, 8, 9,10,11]
}
},
{
extend: 'print',
action: exportAllRow,
exportOptions: {
columns: [1,2, 3, 4, 5, 6, 7, 8, 9,10,11]
}
}
]
},
{
extend: 'colvis',
className: 'btn btn-default mr-2'
}
];
function exportAllRow(e, dt, button, config) {
let rowsAmt = dt.page.info().recordsDisplay;
if (rowsAmt > 10000) {
if (!confirm(`匯出或列印的記錄數量較多( ${rowsAmt} 條記錄)
您確定繼續嗎?`)) {
return;
}
}
var self = this;
var oldStart = dt.settings()[0]._iDisplayStart;
dt.one('preXhr', function (e, s, data) {
data.start = 0;
data.length = 5000000;
dt.one('preDraw', function (e, settings) {
if (button[0].className.indexOf('buttons-copy') >= 0) {
$.fn.dataTable.ext.buttons.copyHtml5.action.call(self, e, dt, button, config);
} else if (button[0].className.indexOf('buttons-excel') >= 0) {
$.fn.dataTable.ext.buttons.excelHtml5.available(dt, config) ?
$.fn.dataTable.ext.buttons.excelHtml5.action.call(self, e, dt, button, config) :
$.fn.dataTable.ext.buttons.excelFlash.action.call(self, e, dt, button, config);
} else if (button[0].className.indexOf('buttons-csv') >= 0) {
$.fn.dataTable.ext.buttons.csvHtml5.available(dt, config) ?
$.fn.dataTable.ext.buttons.csvHtml5.action.call(self, e, dt, button, config) :
$.fn.dataTable.ext.buttons.csvFlash.action.call(self, e, dt, button, config);
} else if (button[0].className.indexOf('buttons-pdf') >= 0) {
$.fn.dataTable.ext.buttons.pdfHtml5.available(dt, config) ?
$.fn.dataTable.ext.buttons.pdfHtml5.action.call(self, e, dt, button, config) :
$.fn.dataTable.ext.buttons.pdfFlash.action.call(self, e, dt, button, config);
} else if (button[0].className.indexOf('buttons-print') >= 0) {
setTimeout(function () { $.fn.dataTable.ext.buttons.print.action(e, dt, button, config); }, 0);
}
dt.one('preXhr', function (e, s, data) {
settings._iDisplayStart = oldStart;
data.start = oldStart;
});
setTimeout(dt.ajax.reload, 0);
return false;
});
});
dt.ajax.reload();
};