How can you place export buttons in another location on your page?

How can you place export buttons in another location on your page?

mmalmeidammalmeida Posts: 15Questions: 2Answers: 0

The example at https://datatables.net/extensions/buttons/examples/initialisation/new.html showcases how to create some buttons and prepend them to the existing dataTables.

Is it possible to create the buttons but put them in other locations on the page?
Example, consider the examples at http://www.keenthemes.com/preview/metronic/theme/admin_1/table_datatables_managed.html - the first table has the print/pdf/excel under the "tools" button on the top right corner of the table.

Is it be possible to have the export buttons there?

This question has an accepted answers - jump to answer

Answers

  • jr42.gordonjr42.gordon Posts: 305Questions: 2Answers: 49
    Answer ✓
  • mmalmeidammalmeida Posts: 15Questions: 2Answers: 0

    Thanks for the tip @jr42.gordon

    Here is how I ended up doing, usinfg:
    - the buttons property
    - container().appendTo('#someDivOnThePage')

    //begin export buttons
            codeListTable = $("#codeListTable").DataTable();
            new $.fn.dataTable.Buttons( codeListTable, {
                buttons: [
                    {
                    extend:    'copy',
                    text:      '<i class="fa fa-files-o"></i> Copy',
                    titleAttr: 'Copy',
                    className: 'btn btn-default btn-sm'
                    },
                    {
                    extend:    'csv',
                    text:      '<i class="fa fa-files-o"></i> CSV',
                    titleAttr: 'CSV',
                    className: 'btn btn-default btn-sm',
                    exportOptions: {
                        columns: ':visible'
                    }
                    },
                    {
                    extend:    'excel',
                    text:      '<i class="fa fa-files-o"></i> Excel',
                    titleAttr: 'Excel',
                    className: 'btn btn-default btn-sm',
                    exportOptions: {
                        columns: ':visible'
                    }
                    },
                    {
                    extend:    'pdf',
                    text:      '<i class="fa fa-file-pdf-o"></i> PDF',
                    titleAttr: 'PDF',
                    className: 'btn btn-default btn-sm',
                    exportOptions: {
                        columns: ':visible'
                    }
                    },                
                    {
                    extend:    'print',
                    text:      '<i class="fa fa-print"></i> Print',
                    titleAttr: 'Print',
                    className: 'btn btn-default btn-sm',
                    exportOptions: {
                        columns: ':visible'
                    }
                    },   
                ]
            } );
            codeListTable.buttons().container().appendTo('#tableActions');
    
This discussion has been closed.