Datatablet JS Export with Multiline

Asked

Viewed 192 times

2

Opa,

In the same cell of the datatable there can be several lines, and the function buttonsto export from datatable does not recognize tag <Br>, I’m trying to use the columns and the render this way, only for testing, where it should exchange the , for <br>. Datatable appears, but not buttons.

$(document).ready(function() {

var table = $('#example').DataTable( {


   ///Se adicionar botões exportar não aparecem
        columns: [
            null,
            null,
            null,
            null,
            null,
            {
                render: function(data, type, row){
                    return data.split(", ").join("<br/>");
                }
            }
        ],
   ///Se adicionar botões exportar não aparecem


    lengthChange: false,
    buttons: [


        {
            extend: 'copy',
            text: 'Copiar'
        },
        {
            extend: 'print',
            text: 'Imprimir',
            message: '<?php echo $TextoArquivoExport;?>',
        },
        {
            extend: 'excelHtml5',
             title: '<?php echo $NomeArquivoExport;?>'
        },
        {
            extend: 'pdfHtml5',
            orientation: 'landscape',
            pageSize: 'LEGAL',
             fieldSeparator: '\t',
             message: '<?php echo $TextoArquivoExport;?>',
            title: '<?php echo $NomeArquivoExport;?>',
                exportOptions: {
                    stripNewlines: false
                }
        },
        {
            extend: 'colvis',
            text: 'Exibir/Ocultar Coluna'
        }

    ],

    language: {
        buttons: {
            copyTitle: 'Informações do relatório copiadas',
            copyKeys: 'Foram copiados <i>ctrl</i> ou <i>\u2318</i> + <i>C</i> registros. <br><br>Por favor, pressione o botão ESC para sair.',
            copySuccess: {
                _: '%d registros copiados',
                1: '1 linha copiada'
            }
        }
    }

} );

The objective in question is to replace the , for <br>and there’s a line break. Based on columnsand in the render: https://datatables.net/reference/option/columns.render

Possible solution taken from: https://stackoverflow.com/questions/32791577/how-can-i-implement-new-line-in-a-column-datatables

1 answer

0

Subtle line:

{
  render: function(data, type, row){
  return data.split(", ").join("<br/>");
}

For,

{ null,
  render: function(data, type, row){
  return data.split(", ").join("<br/>");
}

The datatables it requires you to make an identification in the column if you do not want as is the case you need to put null and then run the render. I think that was it :D

  • Without success buddy, the same occurs, when editing what you reported, the export buttons do not appear. I need exactly that they appear and in the export the line breaks also work. Hug

Browser other questions tagged

You are not signed in. Login or sign up in order to post.