Delete n columns with pdfHtml5 - excelHtml5 - DataTables - JS - jQuery

0

Hello everyone, I have the following view

As you can see I have a table and the buttons EXCEL and PDF

But when I download it I get it this way:

What I want to know is how to eliminate the last column called ACTION

This is my jQuery:

/* Desarrollado por Ivan More Flores - ETI UGEL04 */
/* global baseurl, ciCsrfToken, swal */
var tabla_roles;
$(document).ready(function () {

    $(function () {
        tabla_roles = $('#tabla_roles').DataTable({
            dom: 'Bfrtip',
            buttons: [
                {
                    extend: 'pdfHtml5',
                    orientation: 'portrait',
                    pageSize: 'A4'
                },
                {
                    extend: 'excelHtml5',
                    customize: function (xlsx) {
                        var sheet = xlsx.xl.worksheets['sheet1.xml'];
                        $('row c[r*="1"]', sheet).attr('s', '47');
                        $('row c[r*="2"]', sheet).attr('s', '42');
                    }
                }
            ],
            "processing": true,
            "serverSide": true,
            "order": [],
            "ajax": {
                "url": baseurl + 'Rol/listar_roles',
                "type": "POST",
                "data": {"ci_csrf_token": ciCsrfToken}
            },
            "columnDefs": [
                {
                    "targets": [-1, 0, 1, 2, 3],
                    "orderable": false
                }
            ],
            "language": {
                "processing": "Procesando...",
                "lengthMenu": "Mostrar _MENU_ registros",
                "zeroRecords": "No se encontraron resultados",
                "emptyTable": "Ningún dato disponible en esta tabla",
                "info": "Mostrando registros del _START_ al _END_ de un total de _TOTAL_ registros",
                "infoEmpty": "Mostrando registros del 0 al 0 de un total de 0 registros",
                "infoFiltered": "(filtrado de un total de _MAX_ registros)",
                "infoPostFix": "",
                "search": "Buscar:",
                "url": "",
                "infoThousands": ",",
                "loadingRecords": "Cargando...",
                "paginate": {
                    "first": "Primero",
                    "last": "Último",
                    "next": "Siguiente",
                    "previous": "Anterior"
                },
                "aria": {
                    "sortAscending": ": Activar para ordenar la columna de manera ascendente",
                    "sortDescending": ": Activar para ordenar la columna de manera descendente"
                }
            },
            "lengthMenu": [[10, 15, 20, 25], [10, 15, 20, 25]],
            "iDisplayLength": 10,
        });

        //Button PDF
        $('.buttons-pdf').hide();
        $('#btn_pdf').click(function () {
            $('.buttons-pdf').click();
        });

        //Button EXCEL
        $('.buttons-excel').hide();
        $('#btn_excel').click(function () {
            $('.buttons-excel').click();
        });

        $('.search-input-text').on('keyup click', function () {
            var i = $(this).attr('data-column');
            var v = $(this).val();
            tabla_roles.columns(i).search(v).draw();
        });
        $('.search-input-select').on('change', function () {
            var i = $(this).attr('data-column');
            var v = $(this).val();
            tabla_roles.columns(i).search(v).draw();
        });
        $('#tabla_roles_filter').css('display', 'none');
    });
});
    
asked by Ivan More Flores 19.11.2018 в 18:18
source

1 answer

1

you can do it with:

<th class='notexport'>yourColumn</th>
 { extend: 'excelHtml5',
        exportOptions: {
            columns: ':not(.notexport)'
        }

or using a css last child selector:

  exportOptions: {
            // columns: ':visible' or
            columns: 'th:not(:last-child)'
        }

or doing the columns you want:

extend: 'excelHtml5',
exportOptions: { 
columns: [ 0, 1, 2, 3,4,5,6 ] }
    
answered by 19.11.2018 / 18:37
source