Buttons breaks on numeric columns
Buttons breaks on numeric columns
Using DataTables 1.10.8 via the Download builder: When I try to activate Buttons on a table containing columns with numeric data, I get an 'Uncaught TypeError: a.replace is not a function', pointing to the code:
c.stripHtml&&(a=a.replace(/<.*?>/g, ...
The code I'm using to create the Buttons:
var dtAddButtons = function (dataTable, location, exportTitle, printTitle) {
new $.fn.dataTable.Buttons( dataTable, {
buttons: [
{
extend: 'collection',
text: 'Save <span class="caret"></span>',
buttons: [
{
extend: 'excel',
title: exportTitle
},
{
extend: 'csv',
title: exportTitle
},
{
extend: 'csv',
text: 'TSV',
fieldSeparator: '\t',
extension: '.tsv',
title: exportTitle
}
]
},
{
extend: 'print',
title: printTitle
}
]
} );
dataTable.buttons().container()
.appendTo(location);
};
My DataTable defaults:
$.extend($.fn.dataTable.defaults, {
"language": {
"info": "_START_–_END_ of _TOTAL_",
"infoEmpty": "0 items",
"infoFiltered": " (filtered from _MAX_)",
"lengthMenu": "Show _MENU_ per page",
"paginate": {
"previous": '<span aria-hidden="true" title="Previous">❮</span> <span class="sr-only">Previous</span>',
"next": '<span class="sr-only">Next</span> <span aria-hidden="true" title="Next">❯</span>'
},
"search": "Filter:",
"zeroRecords": "No matching items."
},
"lengthChange": false,
"orderClasses": false,
"pagingType": "simple_numbers",
"processing": true,
"stateSave": true
});
The normal column spec is:
{
"data": "score"
}
When I replace it with the following to convert the data to a string, the error goes away:
{
"data": "score",
"render": function (data, type, row, meta) {
return '' + data;
}
}
See also: http://debug.datatables.net/ibavib
This question has an accepted answers - jump to answer
Answers
I had the same issue. Using DataTables 1.10.8. I have applied a similar fix.
Hi,
Yes, unfortunately there is a bug in the Buttons release where it throws an error with non-string based data. This commit fixes the issue and I will be releasing Buttons 1.0.1 with this and other fixes at the end of the week.
Regards,
Allan