jQuery dataTables : Export with newline / break in

2019-08-13 19:54发布

问题:

I´m trying to generate an exportable datatable with the plugin "jquery.dataTable".

But for design reasons I need linebreaks inside the cells. For the HTML view I simply use <br>, but if I try to export this f.e into a PDF, it will cause to break the output from the first occurring br, so I googled around and tried to pre-process the data and replace breaks with newline characters but this will cause the PDF export to break at the first br for even a lot of rows. I have no idea.

Here's the relevant part of my attempt:

{
    "aButtons": [{
        "sExtends": "pdf",
        "fnCellRender": function ( sValue, iColumn, nTr, iDataIndex ) {
            return sValue.replace(/<br\s*\/?>/ig, "\r\n") ;
        },
        "sNewLine":"\r\n"
    }]
},