New line character not working in datatable export custom function

Viewed 42

I am trying to customize data in export excel function of datatable jquery plugin. Below are some lines of code.

   $('#studentTbl').DataTable({
     ajax:{
        url: 'index.php?secController=TestInterview&action=fetchAllApplicants',
        type: 'POST',
        data: {
        },
        ........,
        buttons: [
          .....
           {
            extend: 'excelHtml5',
            title: ' New Applications ',
            pageSize: 'A4',
            exportOptions: {
                columns: [0, 1, 2],
                format: {
                    body: function (data, row, column, node) {
                        if (column == 0) {
                            data.replace(/<br\s*\/?>/gi, '"' + "\r\n" + '"');
                        }
                        return column == 0 ? node.textContent.replace('Status', '').replace(/ +/g, ' ') : data;
                    }
                }
            },
        },
        ....
     });

I have the first column with Html elements that are used for displaying data as per client requirements. They have 'p', 'br' tags, etc. Now I am trying to customize the data in the first cell of the excel sheet for exporting them in a well-formated way. I am first trying to replace the 'br' to excel's new line character '\n', then I am trying to replace Status with '' (which does not need to be displayed in the excel cell). Now the issue is that when the excel sheet is generated the cell values of the first column still appear in one line. Please help!!!

0 Answers
Related