Johnson
Johnson

Reputation: 1536

@Media Print Class in Datatable

Why my class to add text-aligndid not work on @media print?

I made an EXAMPLE PLUNKER

I want that Right Element stay on right when user clicks on Print button

Style

@media print {
  td.text-right-print {
    text-align: right!important
  }
}

Tabela

  <table class="table" id="example">
    <thead>
      <tr>
        <th>Left Thead</th>
        <th>Right Thead</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Left Element</td>
        <td align="right" class="text-right-print">Right Element</td>
      </tr>
      <tbody>
  </table>

Thanks!

Upvotes: 1

Views: 1221

Answers (1)

rahul
rahul

Reputation: 7663

You can use the customize method of jquery datatable.

$(document).ready(function() {
      $('#example').DataTable({
        dom: 'Bfrtip',
        buttons: [
         {
                extend: 'print',
                customize: function ( win ) {
                    $(win.document.body).find('table tr td:nth-child(2)')
                        .addClass('rightAlign');
                }
            }
        ]
      });
    });

EXAMPLE PLUNKER

Please find the link below for more information:

DataTable Print Customization

Upvotes: 4

Related Questions