o cabeçalho não aparece ao exportar e imprimir

o cabeçalho não aparece ao exportar e imprimir

herlanderherlander Posts: 1Questions: 0Answers: 0
edited April 2023 in Free community support

o cabeçalho não aparece depois de destruir e criar a nova tabela, gostaria que aparecesse o cabeçalho

 success: function (dadosTabela) {
            //   alert(dadosTabela);
            $('#dataTablePDR tfoot th').each(function () {
                var title = $(this).text();
                $(this).html('<input type="text" placeholder= "' + title + '" />');
            });
            //receber dados da servlet
            var dados = dadosTabela;
            //  alert(dados.listActividades);
            //alert(dados.listActividades.grupo);
            var tableTitle = $('#table-title').text();
            
            if ($.fn.DataTable.isDataTable('#dataTablePDR')) {              
                $('#dataTablePDR').DataTable().destroy();
            }
     

            // Cria uma nova tabela e preenche com os dados recebidos
            var table1 = $('#dataTablePDR').DataTable({
                data: dados.listActividades,
           
                columns: [
                    {data: 'grupo'},
                    {data: 'idactividade'},
                    {data: 'cliente'},
                    {data: 'descricao'},
                    {data: 'seccao.departamento.direccao.nomeDireccao'},
                    {data: 'seccao.departamento.nomeDepartamento'},
                    {data: 'seccao.nomeSeccao'},
                    {data: 'responavel'},
                    {data: 'pdr'},
                    {data: 'coment'},
                    {data: 'downtime'},
                    {data: 'aprovador'/*},
                     {
                     data: null,
                     render: function (data, type, row, meta) {
                     var editLink = '<a href="' + context + '/ActividadesServlet?comando=Actualizar&txtCodigoActividades=' + row.idactividade + '" class="text-primary mr-1" title="Editar Dados"><i class="far fa-edit"></i></a>';
                     var deleteLink = '<a href="' + context + '/ActividadesServlet?comando=Apagar&txtCodigoActividades=' + row.idactividade + '" class="text-danger mr-1" title="Excluir Registro"><i class="far fa-trash-alt"></i></a>';
                     return editLink + deleteLink;
                     }
                     */}
                                     
                ],
                dom: 'lBfrtip',
                language: {
                    url: '//cdn.datatables.net/plug-ins/1.11.3/i18n/pt_br.json'
                }, columnDefs: [
                    {
                        "targets": "_all",
                        "defaultContent": " "
                    }
                ],
                buttons: [
                    {
                        extend: 'copy',
                        title: tableTitle,
                         header: true,
                        className: 'btn btn-dark rounded-0',
                        text: '<i class="far fa-copy"></i> Copiar'/*,
                         exportOptions: {
                         columns: function (idx, data, node) {
                         if (idx < (table1.columns().count() - 1)) {
                         return true;
                         }
                         return false;
                         }
                         }*/
                    },
                    {
                        extend: 'excel',
                        title: tableTitle,
                         header: true,
                        className: 'btn rounded-0',
                        text: '<i class="far fa-file-excel"></i> Excel',
                        filename: tableTitle/*,
                         exportOptions: {
                         columns: function (idx, data, node) {
                         if (idx < (table1.columns().count() - 1)) {
                         return true;
                         }
                         return false;
                         }
                         }*/
                    },
                    {
                        extend: 'pdf',
                        title: tableTitle,
                         header: true,
                        className: 'btn  rounded-0',
                        text: '<i class="far fa-file-pdf"></i> Pdf',
                        filename: tableTitle/*,
                         exportOptions: {
                         columns: function (idx, data, node) {
                         if (idx < (table1.columns().count() - 1)) {
                         return true;
                         }
                         return false;
                         }
                         }*/
                    },
                    {
                        extend: 'csv',
                        title: tableTitle,
                         header: true,
                        className: 'btn rounded-0',
                        text: '<i class="fas fa-file-csv"></i> CSV',
                        charset: 'UTF-8',
                        fieldSeparator: ';',
                        bom: true,
                        filename: tableTitle/*,
                         exportOptions: {
                         columns: function (idx, data, node) {
                         if (idx < (table1.columns().count() - 1)) {
                         return true;
                         }
                         return false;
                         }
                         }*/

                    },
                    {
                        extend: 'print',
                        title: tableTitle,
                        className: 'btn rounded-0',
                        text: '<i class="fas fa-print"></i> Print',
                         header: true,
                        messageTop: 'Documento do supergest.'/*,
                         exportOptions: {
                         columns: function (idx, data, node) {
                         if (idx < (table1.columns().count() - 1)) {
                         return true;
                         }
                         return false;
                         }
                         }*/
                    }


                ],
                initComplete: function () {
                    // Apply the search
                    this.api()
                            .columns()
                            .every(function () {
                                var that = this;
                                $('input', this.footer()).on('keyup change clear', function () {
                                    if (that.search() !== this.value) {
                                        that.search(this.value).draw();
                                    }
                                });
                            });
                }


            });
            // Move footer row to thead
            var vall = table1.cell(1, 1).data();
            //  alert(vall);
            $('#dataTablePDR tfoot tr').appendTo('#dataTablePDR thead');
        }

    });

Edited by Colin - Syntax highlighting. Details on how to highlight code using markdown can be found in this guide.

Replies

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

Sign In or Register to comment.