Editor - Serverside. How can I show multiple lines in cell?

Editor - Serverside. How can I show multiple lines in cell?

mpdatampdata Posts: 10Questions: 2Answers: 1

Datatables Editor.
How can I show multiple lines in cell?
The solution as the client entering new records to add <br> doesn't seem ok.

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 63,678Questions: 1Answers: 10,497 Site admin
    Answer ✓

    I presume that the user input has new line characters (\n) for the line breaks, and you want to show them as multiple lines? If so, a rendering function would be the way to do it - e.g.:

    {
      data: 'myText',
      render: function (data, type, row) {
        if (type === 'display') {
          return data.replace(/\n/g, '<br>');
        }
        return data;
      }
    }
    

    Allan

  • mpdatampdata Posts: 10Questions: 2Answers: 1

    Thanks, it works. Display in cell on multiple lines.
    But it is a problem. If I export to pdf or excel or want to print, the display in the cell is on one line.
    Please help me.

  • mpdatampdata Posts: 10Questions: 2Answers: 1

    I found the solution here: https://datatables.net/forums/discussion/34951/how-to-include-line-breaks-when-printing
    For PRINT it works (stripHtml: false).
    It does not work for PDF or Excel export (stripNewlines: false).

  • kthorngrenkthorngren Posts: 21,443Questions: 26Answers: 4,974
    Answer ✓

    When exporting the export function uses the display orthogonal data by default. You can use a different orthogonal data as shown in this example.

    PDF uses \n for newlines. You will need to use orthogonal data to return the original data with \n.

    Excel is more complicated. You will need to set the cell to use word wrap as discussed in this thread. Plus you will need to use the Excel CHAR function to replace the newline character with CHAR(10). See this thread for some details.

    Here is an example with Print, Excel and PDF:
    https://live.datatables.net/socehike/1/edit

    Kevin

  • mpdatampdata Posts: 10Questions: 2Answers: 1

    Thanks.

Sign In or Register to comment.