Render a memo field which may contain multiple lines with carriage returns within a datatable column
Render a memo field which may contain multiple lines with carriage returns within a datatable column

Hi,
My data source contains a memo field that may contain multiple lines of text separated by carriage returns.
Currently, I'm using the following in my data table init :
{ data: 'sn.notes' },
Which works, but the carriage returns are removed, so all the text appears connected.
So, for example the original text might look like this (ignore the stars) :
************* Start
This is a test note
By Chris J.
************ End
But on my data table it is displaying like this (ignore the stars) :
************* Start
This is a test note By Chris J.
************ End
I've read I need to use the render function to replace my carriage returns with <br> but I'm not sure how to do this.
Could someone help\advise, please?
Regards,
Chris
This question has an accepted answers - jump to answer
Answers
You would use
columns.render
to convert those to HTML line breaks. This thread explains it in more detail,Colin
Thanks Colin :-)
For future reference, I replaced the line :
{ data: 'sn.notes' },
With :
{ data: 'sn.notes', render: function(data) { return data.replace(/(?:\r\n|\r|\n)/g, '<br>') } },