PDF DataTables orientation?

1

I have a problem in a JQuery script referring to a table built with the DataTables libraries.

The fact is that I have too many columns, and the PDF comes out in a vertical match, so you do not see the last columns.

The script that I currently have is this:

$(document).ready(function() {
  var table = $('#example').DataTable({
    lengthChange: false,
    buttons: ['copy', 'excel', 'pdf', 'colvis']
  });

  table.buttons().container()
    .appendTo('#example_wrapper .col-md-6:eq(0)');

  table({
    dom: 'Bfrtip',
    buttons: [{
      extend: 'pdfFlash',
      orientation: 'landscape',
      pageSize: 'LEGAL'
    }]
  });
});

But it does not work. I need help to visualize all the columns in the PDF (When the download is done, do it horizontally)

The table is as follows:

<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
  <thead>
    <tr>
      <th>FECHA</th>
      <th>INICIO</th>
      <th>FIN</th>
      <th>DESCRIPCION TRABAJO</th>
      <th>TAREA</th>
      <th>DESCRIPCION TAREA</th>
      <th>EXTRANJERO</th>
      <th>INCIDENCIA</th>
      <th>ALBARAN</th>
      <th>CONDUCTOR</th>
      <th>VEHICULO</th>
      <th>KILOMETROS</th>
      <th>FINALIZADO</th>

      <th>EDITAR</th>
    </tr>
  </thead>
  <tfoot>
    <tr>
      <th>FECHA</th>
      <th>INICIO</th>
      <th>FIN</th>
      <th>DESCRIPCION TRABAJO</th>
      <th>TAREA</th>
      <th>DESCRIPCION TAREA</th>
      <th>EXTRANJERO</th>
      <th>INCIDENCIA</th>
      <th>ALBARAN</th>
      <th>CONDUCTOR</th>
      <th>VEHICULO</th>
      <th>KILOMETROS</th>
      <th>FINALIZADO</th>

      <th>EDITAR</th>
    </tr>
  </tfoot>
  <tbody>
    <?php do {

      echo "<tr>";
      //echo "<td>".$row_partes['id']."</td>";
      //echo "<td>".date('d-m-Y',strtotime($row_partes['fecha']))."</td>";
      echo "<td>".$row_partes['fecha']."</td>";
      echo "<td>".$row_partes['horainicio']."</td>";
      echo "<td>".$row_partes['horafin']."</td>";
      echo "<td>".$row_partes['descripcion']."</td>";
      echo "<td>".$row_partes['TAREA']."</td>";
      echo "<td>".$row_partes['DESCRIPCION']."</td>";
      if($row_partes['EXTRANJERO'] == 0 || $row_partes['EXTRANJERO']=="N"){
        echo "<td>" . $row_partes['EXTRANJERO'] = "NO" . "</td>";
      }
      else{

        echo "<td>" . $row_partes['EXTRANJERO'] = "SI" . "</td>";
      }
      if($row_partes['INCIDES']==""){
        echo "<td>" . $row_partes['INCIDES'] = "NO" . "</td>";
      }
      else{
        echo "<td>" . $row_partes['INCIDES'] . "</td>";
      }

      if($row_partes['ALBANUM']==""){
        echo "<td>" . $row_partes['ALBANUM'] = "NO" . "</td>";
      }
      else{
        echo "<td>" . $row_partes['ALBANUM'] . "</td>";
      }
      if($row_partes['CONDUCTOR'] == "N"){
        echo "<td>" . $row_partes['CONDUCTOR'] = "NO" . "</td>";
      }
      else{
        echo "<td>" . $row_partes['CONDUCTOR'] = "SI" . "</td>";
      }
      if($row_partes['MATRICULA'] =="0000000"){
        echo "<td>" . $row_partes['MATRICULA'] = "Sin Vehiculo" . "</td>";
      }
      else{
        echo "<td>" . $row_partes['MATRICULA'] . "</td>";
      }
      if($row_partes['KMETROS'] ==""){
        echo "<td>" . $row_partes['KMETROS'] = "Ninguno" . "</td>";
      }
      else{
        echo "<td>" . $row_partes['KMETROS'] . "</td>";
      }
      if($row_partes['FINALIZADO'] == "N"){
        echo "<td>" . $row_partes['FINALIZADO'] = "NO" . "</td>";
      }
      else{
        echo "<td>" . $row_partes['FINALIZADO'] = "SI" . "</td>";
      }

    echo "<td><form method='POST' role='form' name='form'><input type='hidden' name='idparte' value='".$row_partes['id']."'<p><input class='form-control' name='obra' id='obra' placeholder='Nueva Obra...'></p><p><div align='right'><button name='cambiaobra' type='submit' class='btn btn-info btn-circle'><i class='glyphicon glyphicon-ok'></i></button></p></div></form></td>";

      echo "</tr>";
      }

      while ($row_partes = $result257->fetch_array(MYSQLI_ASSOC)); ?>
  </tbody>
</table>
    
asked by Adri404 18.01.2018 в 10:28
source

1 answer

0

Replace your js with this.

var idioma = {
    "sProcessing": "Procesando...",
    "sLengthMenu": "Mostrar _MENU_ registros",
    "sZeroRecords": "No se encontraron resultados",
    "sEmptyTable": "Ningún dato disponible en esta tabla",
    "sInfo": "Mostrando _START_ al _END_ de _TOTAL_ registros",
    "sInfoEmpty": "Mostrando _START_ al _END_ de _TOTAL_ registros",
    "sInfoFiltered": "(filtrado de un total de _MAX_ registros)",
    "sInfoPostFix": "",
    "sSearch": "Filtrar por:",
    "sUrl": "",
    "sInfoThousands": ",",
    "sLoadingRecords": "Cargando...",
    "oPaginate": {
        "sFirst": "Primero",
        "sLast": "Último",
        "sNext": "Siguiente",
        "sPrevious": "Anterior"
    },
    "oAria": {
        "sSortAscending": ": Activar para ordenar la columna de manera ascendente",
        "sSortDescending": ": Activar para ordenar la columna de manera descendente"
    },
    buttons: {
        copyTitle: 'Los datos fueron copiados',
        copyInfo: {
            _: 'Copiados %d filas al portapapeles',
            1: 'Copiado 1 fila al portapapeles',
        }
    }
}
var listarReporte = function () {
    var tblReportes = $('#example').DataTable({
        "destroy": true,
        "processing": true,
        "ordering": false,
        "scrollX": false,
        paging: false,
        "language": idioma,
        dom: 'Bfrtip',
        info: false,
        buttons: [
            'copy', {
                extend: 'excel',
                text: 'Excel',
                title: 'tu título',
                filename: 'tu título',
            }, {
                extend: 'pdf',
                text: 'PDF',
                orientation: 'landscape',
                title: 'tu título',
                filename: 'tu título',
            }, {
                extend: 'print',
                text: 'Imprimir',
                title: 'tu título',
                exportOptions: {
                    modifier: {
                        page: 'current'
                    }
                },
            }
        ]
    });
}
listarReporte();
    
answered by 18.01.2018 / 18:09
source