Pdf generated from datatable

0

I'm using link to build tables, with the same use the buttons to export data, although I got to read the documentation I can not find what next and I would like you to comment if it is possible or not: My table has buttons in materialize with their corresponding symbols to edit and delete, when exporting to pdf for example I get all the fields including the buttons, it is possible to determine in the creation of the button that number of columns has to export To modify and eliminate do not leave?

$(document).ready(function(){
  $('#mytable').DataTable(
  {
   responsive: false,
  dom: 'B<"clear">lfrtip',
  fixedColumns: true,
  fixedHeader: true,
  scrollCollapse: true,
  autoWidth: true,
  scrollCollapse: true,
  lengthMenu: [[5, 10, 25, 50, -1], [5, 10, 25, 50, "All"]],
  info: true,
  buttons: [
    {
      extend: 'excelHtml5',
      title: 'Data export',
      className: 'btn',
      text: "Excel"
  },
  {
    extend: 'csvHtml5',
    title: 'Data export',
    className: 'btn',
    text: "Csv"
},
    {
      extend: 'pdfHtml5',
      title: 'Data export',
      className: 'btn',
      text: "Pdf"
  },
{
  extend: 'print',
  title: 'Data export',
  className: 'btn',
  text: "Imprimir"
},
 {
   extend: 'copy',
   title: 'Data export',
   className: 'btn',
   text: "Copiar"
 }
   ],
     language: {
            "sProcessing":     "Procesando...",
            "sLengthMenu":     "Mostrar _MENU_ registros",
            "sZeroRecords":    "No se encontraron resultados",
            "sEmptyTable":     "Ningún dato disponible en esta tabla",
            "sInfo":           "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
            "sInfoEmpty":      "Mostrando registros del 0 al 0 de un total de 0 registros",
            "sInfoFiltered":   "(filtrado de un total de _MAX_ registros)",
            "sInfoPostFix":    "",
            "sSearch":         "Buscar:",
            "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"
                        },
            "decimal": ",",
            "thousands": "."
          }
});
});
    
asked by Juan 24.04.2018 в 15:26
source

1 answer

2

You can directly exclude those columns from the export as follows:

{
    extend: 'pdfHtml5',
    title: 'Data export',
    className: 'btn',
    text: "Pdf"
    exportOptions: {
        columns: [0, 1] //exportar solo la primera y segunda columna
    }
}

EDIT

Answering your comment you can exclude the last two columns of your export table using selectors: For example to your last two th of the table you put as class class="no-exportar"

And then in your javascript you use selectors to export everything except the last two columns as follows:

{
    extend: 'pdfHtml5',
    title: 'Data export',
    className: 'btn',
    text: "Pdf"
    exportOptions: {
        columns: ":not(.no-exportar)" //exportar toda columna que no tenga la clase no-exportar
    }
}

Greetings!

    
answered by 24.04.2018 / 15:48
source