data.replace is not a function
data.replace is not a function
Rappi
Posts: 82Questions: 18Answers: 1
Hello.
I have a problem with export.
extend: 'print',
title: '',
messageTop: '<center><strong>Bestandsbuch<br /><?php echo $verein;?></strong><br /><?php echo $von;?> bis <?php echo $bis;?></center>',
text: 'Drucken',
stripHtml: true,
stripNewlines:true,
exportOptions: {
columns: ':visible',
format: {
body: function (data, row, column, node) {
//return data.replace(/\n/ig, "<br/>");
//return column === 2 ? data.replace(/\n/ig, "<br/>") : data;
}
}
},
customize: function (win) {
$(win.document.body).find('table').addClass('display').css('font-size', '8px');
$(win.document.body).find('tr:nth-child(odd) td').each(function(index){
$(this).css('background-color','#D0D0D0');
});
$(win.document.body).find('h1').css('text-align','center');
}
},
if i use return data.replace(/\n/ig, "<br/>"); then above error appears.
If I use return column === 5 ? data.replace(/\n/ig, "<br/>") : data; no error appears but I want to render not only column 5 but all columns.
What can I do to render all columns?
Rappi
This discussion has been closed.
Answers
Your code snippet seems to work here:
http://live.datatables.net/xovarumu/1/edit
There must be something specific with your data causing the issue. Please provide a link to your page or update this test case to show the issue.
Kevin
Thanks for the quick reply. The system is a closed system. So unfortunately I can not provide a link. Since it is data composed of several table columns, I don't know how to get the sample data into the test case....
Here is an excerpt of how the data is put together.
And this is my table:
If your error is occurring with this code:
Then you will need to debug the value of
data
to determine why this error occurs. Use console.log or the browser's debugger to monitordata
and maybe the column number. It could be something with one of the rendered columns or maybe the value is a number. It will be difficult to debug with only looking at the code. Maybe look at some Stack Overflow Threads to get an idea of why you might get this error.Or you can add an if statement to check that
data
is a string and if so use the replace statement.Kevin
ok, I found the column that is responsible for the error and by an if query excluded this column from data.replace.
Now it works.
Thanks.