Closed halali closed 4 years ago
Can you give me a link to a test case showing the issue please? I'm not seeing that error on this page.
This is code used for ganerating DT... but page is in Intranet so cant send you link
$.fn.dataTable.ext.buttons.reload = {
text: 'Reload',
action: function (e, dt, node, config) {
dt.ajax.reload();
}
};
var zamestnanci = $('#zamestnanci').DataTable({
dom:
"<'row'<'col-sm-auto'B><'col-sm text-left'l><'col-offset-sm-10 col-sm-3'f>>" +
"<'row'<'col-sm-12'tr>>" +
"<'row'<'col-sm-5'i><'col-sm-7'p>>",
processing: true,
autoWidth: false,
buttons: [
{extend: 'reload', text: 'Reload'},
{
extend: 'excelHtml5',
title: "Zamestnanci",
text: 'Export Excel <i class="fas fa-file-excel" style="color: green;"></i>',
}
],
"lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"language": {
"url": "{{ url_for('static',filename='plugins/datatables/slovak.json') }}"
},
'ajax': {
'url': "{{ url_for('api.get_task_sumar_zamestnanci') }}",
'method': 'POST',
'contentType': "application/json; charset=utf-8",
'data': function (d) {
return JSON.stringify({
'oblast_id': $('#oblast_id').val(),
'start_time': end_time,
'end_time': start_time
})
},
"dataSrc": 'data'
},
"columns":
[
{
"data": "meno",
"title": 'Meno',
"render": function (data, type, row, meta) {
// console.log(data, type, row)
if (type === 'display') {
data = '<a class="link" target="_blank" href="/admin/user/' + row.id + '?start=' + start_time + '&end=' + end_time + '">' + data + '</a>';
}
return data;
}
},
{"data": "ukony", "title": 'Úkony'},
{"data": "cas_cinnosti", "title": 'Čas činností'},
{"data": "strateny_cas", "title": 'Stratený / Nepriamy čas'},
{
"data": "produktivita", "title": 'Produktivita',
render: function (data, type, full, meta) {
return Produktivita(data);
}
}
],
"footerCallback":
function (row, data, start, end, display) {
var api = this.api(), data;
// Remove the formatting to get integer data for summation
var intVal = function (i) {
return typeof i === 'string' ?
i.replace(/[\$,]/g, '') * 1 :
typeof i === 'number' ?
i : 0;
};
var intFloat = function (i) {
return typeof i === 'string' ?
i.replace('%', '') * 1.0 :
typeof i === 'float' ?
i : 0;
};
average = api.column(4).data().reduce(function (a, b) {
var aver = b || 0;
return a + intFloat(aver);
}, 0);
average_page = api.column(4, {page: 'current'})
.data().reduce(function (a, b) {
var aver = b || 0;
return a + intFloat(aver);
}, 0);
totalhrs = api.column(2).data().reduce(function (a, b) {
b = b.split(":");
var hours = b[0] || 0;
var min = b[1] || 0;
return a + intVal(hours * 60) + intVal(min);
}, 0);
totalhrs = Math.floor(totalhrs / 60) + ":" + totalhrs % 60;
totalhrs_page = api.column(2, {page: 'current'})
.data().reduce(function (a, b) {
b = b.split(":");
var hours = b[0] || 0;
var min = b[1] || 0;
return a + intVal(hours * 60) + intVal(min);
}, 0);
totalhrs_page = Math.floor(totalhrs_page / 60) + ":" + totalhrs_page % 60;
totalsc = api.column(3).data().reduce(function (a, b) {
b = b.split(":");
var hours = b[0] || 0;
var min = b[1] || 0;
return a + intVal(hours * 60) + intVal(min);
}, 0);
totalsc = Math.floor(totalsc / 60) + ":" + totalsc % 60;
totalsc_page = api.column(3, {page: 'current'})
.data().reduce(function (a, b) {
b = b.split(":");
var hours = String(b[0]) || String('00');
var min = b[1] || 0;
return a + intVal(hours * 60) + intVal(min);
}, 0);
totalsc_page = Math.floor(totalsc_page / 60) + ":" + totalsc_page % 60;
// Total over all pages
total = api
.column(1)
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0);
// Total over this page
pageTotal = api
.column(1, {page: 'current'})
.data()
.reduce(function (a, b) {
return intVal(a) + intVal(b);
}, 0);
// Update footer
$(api.column(1).footer()).html(
pageTotal + ' (' + total + ' total)'
);
$(api.column(2).footer()).html(totalhrs_page + " (" + totalhrs + ' total)'
);
$(api.column(3).footer()).html(totalsc_page + " (" + totalsc + ' total)');
}
});
Can you use JSFiddle, http://live.datatables.net or similar to create a test case showing the issue? It is likely related to the data being used on your page.
I break in the following place when I have exported data from the table which is numeric: https://github.com/DataTables/Buttons/blob/master/js/buttons.html5.js#L1066
row[i] = row[i].trim();
FYI, if I add in a .toString() before the trim, I no longer fail.
row[i] = row[i].toString().trim();
I can confirm that change fixed the issue
Thank you - fixed here: 02f5816
Thanks. Will this fix roll out soon in a new Buttons release?
Yeah - that's a nasty one. I'll tag it up at the end of the week (wait for the dust to settle and see if anything else pops up).
@DataTables Any movement on incorporating this fix into a release?
Yes - hoping to do it tomorrow, or possibly Thursday. Just wrapping up a few other things.
👀
I break in the following place when I have exported data from the table which is numeric: https://github.com/DataTables/Buttons/blob/master/js/buttons.html5.js#L1066
row[i] = row[i].trim();
FYI, if I add in a .toString() before the trim, I no longer fail.
row[i] = row[i].toString().trim();
Perfect thank you
Hi,
I think new update of datatables 1.10.22 break excelHtml5 with following error