Print Button: keep classes in cells and rows

Print Button: keep classes in cells and rows

calle gicalle gi Posts: 3Questions: 1Answers: 0

From the documentation (https://datatables.net/reference/button/print) I got the following:

The constructed table does not retain the full information from the original table (table row and cell classes are not copied across for example), but the stylesheets from the original document are copied to the print document so the basic styling of the table can be retained.

Why are the classes not copied? Is there a specific reason?
e.g. I want to keep styling classes like (using bootstrap theme) text-nowrap and maybe text-right or text-center...

I've located the function in the plugin where the table is copied. Should I change my copy of this plugin to fit my needs or should I manipulate the copied table via the customize function of the print plugin?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,934Questions: 1Answers: 10,156 Site admin
    Answer ✓

    Why are the classes not copied? Is there a specific reason?

    Yes - performance. It is slow to read the class names and then apply them in the generated document. It is certainly possible, and you could modify the code to have it do that but it doesn't do it at the moment. Perhaps a good idea for a future enhancement that you could optionally enable, acknowledging the performance cost.

    Regards,
    Allan

  • calle gicalle gi Posts: 3Questions: 1Answers: 0
    edited September 2015

    ok thanks.
    For the moment, I manipulate the DOM with following commands to apply some extra styling:

    , buttons: [
    {
    extend: 'print'
    , autoPrint: false
    , customize: function (win) {
        var w = $(win.document.body);
    
        w.find('td:nth-child(2)').addClass('text-nowrap');
        w.find('td:nth-child(1)').addClass('text-nowrap');
        }
    }]
    
  • jfri_2007jfri_2007 Posts: 25Questions: 6Answers: 0

    hey , i have a similar problem, i need mantein the align like the original table when i print, i have 6 columns, only the 5 and 6 have className: 'text-right', targets: [6].
    can you tell me an idea how to keep this? thanks you

  • jfri_2007jfri_2007 Posts: 25Questions: 6Answers: 0

    i used that w.find('td:nth-child(1)').addClass(,) , problem solved!

This discussion has been closed.