Can not format the table header (strip br tags) during excel export
Can not format the table header (strip br tags) during excel export
veronduijna
Posts: 5Questions: 1Answers: 0
I have a datatable. There are <br> tags in table header. I want to strip during excel export. It is 2 days already can not find solution. Please help.
This example works for the body, but not for the header: https://datatables.net/extensions/buttons/examples/html5/outputFormat-function.html
=============== this is my code ==================
var exportFormatter = {
format: {
header: function (data, row, column, node) {
return data.replace(/[<]br[^>]*[>]/gi," ");
}
}
};
table = $('#mydatatable').DataTable({
order: [],
buttons: [{
extend: 'excelHtml5',
filename: 'excelfilename',
footer: false,
title: '',
text: '<i class="fa-solid fa-file-arrow-down"></i> <span>Excel</span>'
}],
initComplete: function () {
/* some code for column filtering */
}
});
This question has an accepted answers - jump to answer
Answers
There seems to be a problem with the exportFormatter example also. It seems Buttons 3.0.0. only processes the first row of data:
It may be the same issue you are having. @allan will need to take a look.
Kevin
Yes, It seems older versions works fine when it comes to exporting. But I have other features in my table which not included in older versions. So, I can not use them.
This is my final code:
when I try to log the data I get error about header[col].length in buttons.html5.min.js file. But it works fine when there is "body" instead of "header".
anything?
Have you tried updating to Buttons 3.0.1? It addresses a few issues with the export of the header and footer.
If that doesn't address the issue, can you link to a test case showing the problem please.
Allan
Yes, it worked. Thanks.