Customize export to PDF, CSV, Excel...

Customize export to PDF, CSV, Excel...

maruthikumar80maruthikumar80 Posts: 5Questions: 2Answers: 0

Hello All,

Currently I am working on Export Datatable to PDF, CSV, EXcel functionalities.
As far as I know while initializing the Datatable, if we include
"buttons": [
'copy', 'csv', 'excel', 'pdf'
]
will perform the stuff. But I want to call these APIs by creating my own buttons.
Can you guide me how can I achieve this?

Thank you,
Maruthi Kumar

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,237Questions: 1Answers: 2,598

    Hi @maruthikumar80 ,

    Yep, you can customise buttons, or create your own. It's best to look at the examples in the Buttons section here, this will give you a good understanding. The third example shows how to make a custom button.

    Cheers,

    Colin

  • allanallan Posts: 63,099Questions: 1Answers: 10,391 Site admin
    Answer ✓

    You can use the button().trigger() method to trigger the buttons externally.

    That does however mean you need to have the buttons created somewhere (possibly they don't need to actually be in the DOM, I'm not sure - haven't tried it!) so that you can trigger them. If you want to do it without creating DataTables' own buttons you'd need to modify the source code to be able to build the output files from your own buttons.

    Allan

  • maruthikumar80maruthikumar80 Posts: 5Questions: 2Answers: 0

    Hello Colin and Allan,

    I am extremely sorry for my delayed reply. Finally I fixed based on your comments. Thank you for your help.
    Here are the steps which I followed.
    Changed "dom" property to 'frtip' while initializing the datatable.
    Added the button.
    buttons: [

                    {
                        extend: 'pdfHtml5',
                        exportOptions: {
                            columns: ':visible'
                        },
                        orientation: 'landscape',
                        pageSize: "LEGAL"
                    }
          ]
    

    Finally invoking using trigger() method.

    $("#btnExport").click(function () {
    data_table.DataTable().button('0').trigger();
    });

    Where btnExport is my bootstrap custom button.
    Regards,
    Maruthi Kumar

This discussion has been closed.