Print button orientation = landscape

Print button orientation = landscape

jvcunhajvcunha Posts: 81Questions: 10Answers: 1
edited October 2016 in Free community support

Hi,
always portrait print? landascape not working in print button?

buttons: [
    {
        extend: 'print',
        text: '<img src="images/printer24x24.png" alt="">',
        titleAttr: 'Imprimir',
        columns: ':not(.select-checkbox)',
        orientation: 'landscape'
    }
]

Replies

  • allanallan Posts: 63,133Questions: 1Answers: 10,399 Site admin

    Thanks for your question - however, per the forum rules can you link to a test case showing the issue please. This will allow the issue to be debugged.

    Information on how to create a test page, if you can't provide a link to your own page can be found here.

    Thanks,
    Allan

  • jvcunhajvcunha Posts: 81Questions: 10Answers: 1

    Send link in PM, thanks

  • zayderszayders Posts: 5Questions: 2Answers: 0

    Hi, you can have a landscape orientation by adding this :

    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);
             }
          },
    ]
    

    Hope this is why you want and it may help !

  • jvcunhajvcunha Posts: 81Questions: 10Answers: 1

    Hi zayders, thanks for solution. Its perfect !

  • allanallan Posts: 63,133Questions: 1Answers: 10,399 Site admin

    Very clever - thanks for posting that!

    Allan

  • REJISREJIS Posts: 5Questions: 2Answers: 0

    So, is this the solution, or is this supposed to be fixed in the code for the print button? PDF works with the normal setting, but Print is still broke with the latest code I just got.

  • allanallan Posts: 63,133Questions: 1Answers: 10,399 Site admin

    Yes - this is the solution. The Print button doesn't offer a landscape option.

    Allan

  • smdmuneersmdmuneer Posts: 2Questions: 1Answers: 0

    Thank you for this Solution. Unfortunately this solution not working in IE11.

  • aswayzeaswayze Posts: 1Questions: 0Answers: 0

    Just curious has a solution been created since your post? Also, I'm new at all this and I was wondering how do I add in the other buttons for excel, copy, csv, and pdf? And is their anything more to add for pdfs since their is no Landscape layout option either?

  • kthorngrenkthorngren Posts: 21,132Questions: 26Answers: 4,918

    All the Buttons docs can be found here which will explain how to install and use the other button types you listed:
    https://datatables.net/extensions/buttons/

    This example shows how to use landscape with PDFs.

    Kevin

  • cacocaco Posts: 1Questions: 0Answers: 0

    The solution from @zayders works for me too. Unfortunately until now it looks like we don't have a simple key/value pair solution to define landscape for "print" button option.

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

    You can use the orientation for defining landscape or portrait, as shown in the firm code snippet,

    Colin

Sign In or Register to comment.