Print button prints hidden columns?

Print button prints hidden columns?

morrow47morrow47 Posts: 4Questions: 2Answers: 0

Below is the code I have. th table hides the columns but when i print all columns print. Does anyone know what I am doing wrong.

$(document).ready(function () {

        var table = $('#earthquake').DataTable({
            data: dataSet,
            "bScrollCollapse": true,
            select: true,
            "bProcessing": true,
            scrollY: '65vh',
            paging: true,
            iDisplayLength: 20,
            "bDeferRender": true,
            deferRender: true,
            "bAutoWidth": false,
            "iScrollLoadGap": 100,

            "dom": 'Bfrtip',
            stateSave: true,
            buttons: [
                 {
                     text: 'Copy',
                     extend: 'copy',
                     exportOptions: {
                         rows: function (idx, data, node) {
                             // If rows are selected, export those, if not, export all
                             if ($dt.rows({ selected: true }).any())
                                 return $.inArray(parseInt(data.asset_id), $dt.rows({ selected: true })) !== -1;

                             return true;
                         }
                     }
                 },
                 {
                     extend: 'pdfHtml5',
                     orientation: 'landscape',
                     pageSize: 'A4',
                     columns: ':visible',

                 },
                 'excel',
                 {
                     extend: 'print',
                     columns: ':visible',
                     autoPrint: true,
                     orientation: 'landscape',
                     pageSize: 'A4',
                  },
                   {
                 extend: 'colvisGroup',
                 text: 'Minimum Columns',
                 show: [1, 2, 3, 4, 5, 16],
                 hide: [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19]
             },
        {
            extend: 'colvisGroup',
            text: 'Show all',
            show: [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19]
        },
         {
             extend: 'colvis',
             postfixButtons: ['colvisRestore'],
             collectionLayout: 'fixed two-column'
         },

            ],
              columns: [
            {
                title: "Time",
                "bSearchable": false
            },
            {
                title: "Place"
            },
            {
                title: "Country"
            },
            {
                title: "Latitude",
                "bSearchable": false,
                "type": ["num", "num0fmt"],
                "className": "dt-body-right"
            },
            {
                title: "Longitude",
                "bSearchable": false,
                "type": ["num", "num0fmt"],
                "className": "dt-body-right"
            },
            {
                title: "Magnitude",
                "bSearchable": false,
                "type": ["num", "num0fmt"],
            "className": "dt-body-right"
            },
            {
                title: "Mag Error",
                "bSearchable": false,
                "bSearchable": false,
                "type": ["num", "num0fmt"],
                "className": "dt-body-right"
            },
            {
                title: "Depth/Miles",
                "bSearchable": false,
                "bSearchable": false,
                "type": ["num", "num0fmt"],
                "className": "dt-body-right"
            },
            {
                title: "Depth Error",
                "bSearchable": false,
                "bSearchable": false,
                "type": ["num", "num0fmt"],
                "className": "dt-body-right"
            },
            {
                title: "Mag_Type",
                "bSearchable": false
            },
            {
                title: "NST",
                "bSearchable": false,
                "bSearchable": false,
                "type": ["num", "num0fmt"],
                "className": "dt-body-right"
            },
            {
                title: "Mag NST",
                "bSearchable": false,
                "bSearchable": false,
                "type": ["num", "num0fmt"],
                "className": "dt-body-right"
            },
            {
                title: "Gap",
                "bSearchable": false,
                "bSearchable": false,
                "type": ["num", "num0fmt"],
                "className": "dt-body-right"
            },
            {
                title: "DMin",
                "bSearchable": false,
                "bSearchable": false,
                "type": ["num", "num0fmt"],
                "className": "dt-body-right"
            },
            {
                title: "RMS",
                "bSearchable": false,
                "bSearchable": false,
                "type": ["num", "num0fmt"],
                "className": "dt-body-right"
            },
            {
                title: "Net"
            },
            {
                title: "Id"
            },
            {
                title: "Update",
                "bSearchable": false
            },
            {
                title: "Type",
                "bSearchable": false
            }
            ],

            "aaSorting": [[0, "desc"]]
        })
 });      

Answers

  • morrow47morrow47 Posts: 4Questions: 2Answers: 0

    I found my problem. I forgot to put in the exportOptions. Print should of been:
    {
    extend: 'print',
    exportOptions:{
    columns: ':visible',
    autoPrint: true,
    orientation: 'landscape'
    }

    Now I have to get the print to change to Landscape. It still prints Portrait.

This discussion has been closed.