|
@@ -458,53 +458,119 @@
|
|
|
|
|
|
|
|
<script>
|
|
<script>
|
|
|
function newexportaction(e, dt, button, config, cb) {
|
|
function newexportaction(e, dt, button, config, cb) {
|
|
|
- var self = this;
|
|
|
|
|
- var oldStart = dt.settings()[0]._iDisplayStart;
|
|
|
|
|
-
|
|
|
|
|
- dt.one('preXhr', function (e, s, data) {
|
|
|
|
|
- data.start = 0;
|
|
|
|
|
- data.length = 10000;
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- dt.one('preDraw', function (e, settings) {
|
|
|
|
|
- if (button[0].className.includes('buttons-copy')) {
|
|
|
|
|
|
|
+ const self = this;
|
|
|
|
|
+ const settings = dt.settings()[0];
|
|
|
|
|
+ const isServerSide = settings.oFeatures && settings.oFeatures.bServerSide;
|
|
|
|
|
+ const hasAjax = !!settings.ajax;
|
|
|
|
|
+
|
|
|
|
|
+ // --- CLIENT-SIDE ---
|
|
|
|
|
+ if (!isServerSide || !hasAjax) {
|
|
|
|
|
+ // Esporta tutte le righe lato client
|
|
|
|
|
+ const origExportOptions = config.exportOptions ? {...config.exportOptions} : {};
|
|
|
|
|
+ config.exportOptions = config.exportOptions || {};
|
|
|
|
|
+ config.exportOptions.modifier = {...(config.exportOptions.modifier || {}), page: 'all'};
|
|
|
|
|
+
|
|
|
|
|
+ // PDF: tabella full-width
|
|
|
|
|
+ // const isPdf = button[0].className.indexOf('buttons-pdf') >= 0;
|
|
|
|
|
+ // const origCustomize = config.customize;
|
|
|
|
|
+ // if (isPdf) {
|
|
|
|
|
+ // config.customize = function(doc) {
|
|
|
|
|
+ // const table = doc.content[1] && doc.content[1].table ? doc.content[1].table : null;
|
|
|
|
|
+ // if (table && table.body && table.body[0]) {
|
|
|
|
|
+ // table.widths = Array(table.body[0].length).fill('*');
|
|
|
|
|
+ // }
|
|
|
|
|
+ // if (typeof origCustomize === 'function') origCustomize(doc);
|
|
|
|
|
+ // };
|
|
|
|
|
+ // }
|
|
|
|
|
+
|
|
|
|
|
+ const cls = button[0].className;
|
|
|
|
|
+ if (cls.includes('buttons-copy')) {
|
|
|
$.fn.dataTable.ext.buttons.copyHtml5.action.call(self, e, dt, button, config, cb);
|
|
$.fn.dataTable.ext.buttons.copyHtml5.action.call(self, e, dt, button, config, cb);
|
|
|
- } else if (button[0].className.includes('buttons-excel')) {
|
|
|
|
|
- ($.fn.dataTable.ext.buttons.excelHtml5.available(dt, config)
|
|
|
|
|
|
|
+ } else if (cls.includes('buttons-excel')) {
|
|
|
|
|
+ ($.fn.dataTable.ext.buttons.excelHtml5.available(dt, config)
|
|
|
? $.fn.dataTable.ext.buttons.excelHtml5
|
|
? $.fn.dataTable.ext.buttons.excelHtml5
|
|
|
: $.fn.dataTable.ext.buttons.excelFlash
|
|
: $.fn.dataTable.ext.buttons.excelFlash
|
|
|
).action.call(self, e, dt, button, config, cb);
|
|
).action.call(self, e, dt, button, config, cb);
|
|
|
- } else if (button[0].className.includes('buttons-csv')) {
|
|
|
|
|
|
|
+ } else if (cls.includes('buttons-csv')) {
|
|
|
($.fn.dataTable.ext.buttons.csvHtml5.available(dt, config)
|
|
($.fn.dataTable.ext.buttons.csvHtml5.available(dt, config)
|
|
|
? $.fn.dataTable.ext.buttons.csvHtml5
|
|
? $.fn.dataTable.ext.buttons.csvHtml5
|
|
|
: $.fn.dataTable.ext.buttons.csvFlash
|
|
: $.fn.dataTable.ext.buttons.csvFlash
|
|
|
).action.call(self, e, dt, button, config, cb);
|
|
).action.call(self, e, dt, button, config, cb);
|
|
|
- } else if (button[0].className.includes('buttons-pdf')) {
|
|
|
|
|
|
|
+ } else if (cls.includes('buttons-pdf')) {
|
|
|
($.fn.dataTable.ext.buttons.pdfHtml5.available(dt, config)
|
|
($.fn.dataTable.ext.buttons.pdfHtml5.available(dt, config)
|
|
|
? $.fn.dataTable.ext.buttons.pdfHtml5
|
|
? $.fn.dataTable.ext.buttons.pdfHtml5
|
|
|
: $.fn.dataTable.ext.buttons.pdfFlash
|
|
: $.fn.dataTable.ext.buttons.pdfFlash
|
|
|
).action.call(self, e, dt, button, config, cb);
|
|
).action.call(self, e, dt, button, config, cb);
|
|
|
- } else if (button[0].className.includes('buttons-print')) {
|
|
|
|
|
|
|
+ } else if (cls.includes('buttons-print')) {
|
|
|
$.fn.dataTable.ext.buttons.print.action.call(self, e, dt, button, config, cb);
|
|
$.fn.dataTable.ext.buttons.print.action.call(self, e, dt, button, config, cb);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Ripristina la paginazione
|
|
|
|
|
- dt.one('preXhr', function (e, s, data) {
|
|
|
|
|
- settings._iDisplayStart = oldStart;
|
|
|
|
|
- data.start = oldStart;
|
|
|
|
|
- data.length = s._iDisplayLength;
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // Ripristina config
|
|
|
|
|
+ config.exportOptions = origExportOptions;
|
|
|
|
|
+ // if (isPdf) config.customize = origCustomize;
|
|
|
|
|
|
|
|
- // Reload con callback (DataTables 2.x)
|
|
|
|
|
- dt.ajax.reload(() => {
|
|
|
|
|
- if (typeof cb === 'function') cb();
|
|
|
|
|
- }, false);
|
|
|
|
|
|
|
+ if (typeof cb === 'function') cb();
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- return false;
|
|
|
|
|
|
|
+ // --- SERVER-SIDE + AJAX: fetch completo poi export ---
|
|
|
|
|
+ const info = dt.page.info();
|
|
|
|
|
+ const oldStart = info.start;
|
|
|
|
|
+ const oldLength = info.length;
|
|
|
|
|
+ const targetLength = info.recordsTotal > 0 ? info.recordsTotal : 2147483647;
|
|
|
|
|
+
|
|
|
|
|
+ dt.one('preXhr', function (e2, s, data) {
|
|
|
|
|
+ data.start = 0;
|
|
|
|
|
+ data.length = targetLength;
|
|
|
|
|
+
|
|
|
|
|
+ dt.one('preDraw', function (e3, stg) {
|
|
|
|
|
+ const cls = button[0].className;
|
|
|
|
|
+
|
|
|
|
|
+ if (cls.includes('buttons-copy')) {
|
|
|
|
|
+ $.fn.dataTable.ext.buttons.copyHtml5.action.call(self, e, dt, button, config, cb);
|
|
|
|
|
+ } else if (cls.includes('buttons-excel')) {
|
|
|
|
|
+ ($.fn.dataTable.ext.buttons.excelHtml5.available(dt, config)
|
|
|
|
|
+ ? $.fn.dataTable.ext.buttons.excelHtml5
|
|
|
|
|
+ : $.fn.dataTable.ext.buttons.excelFlash
|
|
|
|
|
+ ).action.call(self, e, dt, button, config, cb);
|
|
|
|
|
+ } else if (cls.includes('buttons-csv')) {
|
|
|
|
|
+ ($.fn.dataTable.ext.buttons.csvHtml5.available(dt, config)
|
|
|
|
|
+ ? $.fn.dataTable.ext.buttons.csvHtml5
|
|
|
|
|
+ : $.fn.dataTable.ext.buttons.csvFlash
|
|
|
|
|
+ ).action.call(self, e, dt, button, config, cb);
|
|
|
|
|
+ } else if (cls.includes('buttons-pdf')) {
|
|
|
|
|
+ // Full-width PDF
|
|
|
|
|
+ // const origCustomize = config.customize;
|
|
|
|
|
+ // config.customize = function(doc) {
|
|
|
|
|
+ // const t = doc.content[1] && doc.content[1].table ? doc.content[1].table : null;
|
|
|
|
|
+ // if (t && t.body && t.body[0]) t.widths = Array(t.body[0].length).fill('*');
|
|
|
|
|
+ // if (typeof origCustomize === 'function') origCustomize(doc);
|
|
|
|
|
+ // };
|
|
|
|
|
+ ($.fn.dataTable.ext.buttons.pdfHtml5.available(dt, config)
|
|
|
|
|
+ ? $.fn.dataTable.ext.buttons.pdfHtml5
|
|
|
|
|
+ : $.fn.dataTable.ext.buttons.pdfFlash
|
|
|
|
|
+ ).action.call(self, e, dt, button, config, cb);
|
|
|
|
|
+ // config.customize = origCustomize;
|
|
|
|
|
+ } else if (cls.includes('buttons-print')) {
|
|
|
|
|
+ $.fn.dataTable.ext.buttons.print.action.call(self, e, dt, button, config, cb);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ dt.one('preXhr', function (e4, s2, data2) {
|
|
|
|
|
+ data2.start = oldStart;
|
|
|
|
|
+ data2.length = oldLength;
|
|
|
|
|
+ stg._iDisplayStart = oldStart;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ setTimeout(() => {
|
|
|
|
|
+ dt.ajax.reload(() => { if (typeof cb === 'function') cb(); }, false);
|
|
|
|
|
+ }, 0);
|
|
|
|
|
+
|
|
|
|
|
+ return false;
|
|
|
|
|
+ });
|
|
|
});
|
|
});
|
|
|
- // Requery the server with the new one-time export settings
|
|
|
|
|
|
|
+
|
|
|
dt.ajax.reload();
|
|
dt.ajax.reload();
|
|
|
- };
|
|
|
|
|
|
|
+ }
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
@stack('scripts')
|
|
@stack('scripts')
|