PDF Export function.

PDF Export function.

usaman45usaman45 Posts: 6Questions: 4Answers: 0
edited June 2019 in Free community support

I have code but not sure how to add PDF export function and with different name, please help.
Here is my code:

<script>
    var today = new Date();
    var date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
    var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds();
    var dateTime = date + '_' + time;

    $(document).ready(function () {
        gridDataTableView("UsersList.xls");
    });

    gridDataTableView = function (fname) {
        $('#tblGrid').dataTable({
            "bFilter": true,
            "bLengthChange": false, "bPaginate": true, "bInfo": true,
            dom: 'Bfrtip',
            "order": [[0, 'desc'], [1, 'desc']],
            buttons: [{ extend: 'copy', text: 'Copy to clipboard', className: 'copyButton' },
            { extend: 'excelHtml5', text: 'Export to Excel file', className: 'link_button', title: fname }]
        });
    }
</script>

EDIT: Updated post to format code using Markdown formatting.

Answers

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954

    Does this doc answer your questions?
    https://datatables.net/reference/button/pdfHtml5

    Kevin

  • usaman45usaman45 Posts: 6Questions: 4Answers: 0
    edited June 2019

    I added pdf part to code but the PDF button is not showing.

    $('#tblGrid').dataTable({
    "bFilter": true,
    "bLengthChange": false, "bPaginate": true, "bInfo": true,
    dom: 'Bfrtip',
    "order": [[0, 'desc'], [1, 'desc']],
    buttons: [{ extend: 'copy', text: 'Copy to clipboard', className: 'copyButton' },
    {
    extend: 'pdfHtml5',
    text: 'Save current page',
    exportOptions: {
    modifier: {
    page: 'current'
    }
    }
    },
    { extend: 'excelHtml5', text: 'Export to Excel file', className: 'link_button', title: fname }]
    });

  • kthorngrenkthorngren Posts: 21,344Questions: 26Answers: 4,954

    Did you include the PDFMake library as mentioned in the do clink?

    You can use the Download Builder to generate all the required files for your solution.

    Kevin

This discussion has been closed.