no se ejcuta el boton pdf para exportar los datos

no se ejcuta el boton pdf para exportar los datos

jmhuertafejmhuertafe Posts: 5Questions: 4Answers: 0
edited November 2023 in Free community support

haciendo pruebas para conocer mas de datatables, quise agregar una paginacion a mi reporte que se exporta a pdf, y ya no se ejecuta el boton, si quito el codigo si funciona.

agradezco todos sus consejos.

aqui la parte del codigo que puse para paginar.

var pageCount = doc.internal.getNumberOfPages();
                    doc.footer = function(currentPage) {
                        return { text: 'Página ' + currentPage.toString() + ' de ' + pageCount.toString(), alignment: 'center', margin: [0, 0, 0, 20] };
                    };

aqui el codigo completo que utilizo para el pdf

{
                "extend": "pdfHtml5",
                "text": "<i class='fas fa-file-pdf'></i> PDF",
                "titleAttr":"Exportar a PDF",
                "className": "btn btn-danger",
                "orientation": "landscape",  //--- HORIZONTAL ---
                "pageSize": "letter",

                "title": "TITULO REPORTE",

                customize: function(doc) {
                    doc.pageMargins = { top: 20, bottom: 20, left: 20, right: 20 };          
                    doc.styles.title = { color: 'black', fontSize: '11', background: 'silver', alignment: 'center', bold: true }; 
                    doc.content.splice( doc.content.length - 2, 0, { canvas: [{ type: 'line', x1: 0, y1: 10, x2: 600, y2: 10, lineWidth: 1 }] });
                   
                    doc.content.push({ canvas: [{ type: 'line', x1: 0, y1: 10, x2: 700, y2: 10, lineWidth: 1 }] });
                    var pageCount = doc.internal.getNumberOfPages();
                    doc.footer = function(currentPage) {
                        return { text: 'Página ' + currentPage.toString() + ' de ' + pageCount.toString(), alignment: 'center', margin: [0, 0, 0, 20] };
                    };
                    
                },

                "messageTop": "» SUBTITULO REPORTE",
                "messageBottom": "Fin del reporte",
                "exportOptions": { "columns": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], modifier: { selected: true } }  
            }

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

Answers

  • kthorngrenkthorngren Posts: 21,167Questions: 26Answers: 4,921
    edited November 2023

    testing to learn more about datatables, I wanted to add a page to my report that is exported to pdf, and the button no longer runs, if I remove the code if it works.

    Do you get errors in the browser's console?

    doc.footer = function(currentPage) {

    What is currentPage? I suspect you are getting an error similar to this:

    Uncaught ReferenceError: currentPage is not defined

    But the problem might be something different. Please provide a link to a test case showing the issue so we can help debug.
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

    The PDF export uses PDFMake. You might need to refer the the PDFMake docs to learn how to add a new page to the export.

    Kevin

Sign In or Register to comment.