KoolReport's Forum

Official Support Area, Q&As, Discussions, Suggestions and Bug reports.
Forum's Guidelines

Datatable Button Print, Default Orientation to Landscape #2106

Closed Keith opened this topic on on May 28, 2021 - 1 comments

Keith commented on May 28, 2021

Is it possible to set the default print orientation to landscape?

Currently I have my print button set up like so: I've tried adding an orientation attribute but that doesn't seem to work. `

      "buttons"    => [
        array(
            "extend"        => "print",
            "orientation" => "landscape",
            'footer'        => TRUE,
            'exportOptions' => [
                "format" => [
                    "body" => "function ( data, row, column, node ) {
                            if (!window.columnIndex) window.columnIndex = 0;
                            if (column != 0) return data;
                            else {
                                if(columnIndex > row){
                                    columnIndex = 0
                                }
                                window.columnIndex += 1;
                                return window.columnIndex;
                            }
                        }"
                ]
            ]
        ),

Sebastian Morales commented on May 31, 2021

Keith, pls try this code:

"buttons" => [
        [
            "extend" => "print",
            "customize" => "function(win)
            {
 
                var last = null;
                var current = null;
                var bod = [];
 
                var css = '@page { size: landscape; }',
                    head = win.document.head || win.document.getElementsByTagName('head')[0],
                    style = win.document.createElement('style');
 
                style.type = 'text/css';
                style.media = 'print';
 
                if (style.styleSheet)
                {
                  style.styleSheet.cssText = css;
                }
                else
                {
                  style.appendChild(win.document.createTextNode(css));
                }
 
                head.appendChild(style);
         }"
     ],
] 

Build Your Excellent Data Report

Let KoolReport help you to make great reports. It's free & open-source released under MIT license.

Download KoolReport View demo
help needed

DataGrid