【问题标题】:@Media Print Class in Datatable数据表中的@Media 打印类
【发布时间】:2017-10-24 12:37:31
【问题描述】:

为什么我的class 添加text-align@media print 上不起作用?

我发了EXAMPLE PLUNKER

当用户点击Print 按钮时,我希望Right Element 保持正确

风格

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

塔贝拉

  <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>

谢谢!

【问题讨论】:

    标签: jquery css datatable datatables


    【解决方案1】:

    可以使用jquery数据表的customize方法。

    $(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

    更多信息请点击以下链接:

    DataTable Print Customization

    【讨论】:

    • 很好,但是还有其他方法吗?我有一堆表,我只有一个 .js 来构建所有数据表
    • $(win.document.body).find(' table tr td .text-right-print ') 吗?
    • @Johnson 似乎数据表正在删除单击打印时的所有自定义样式,因此您将无法使用 text-right-print 找到
    • 这很奇怪,因为如果你在 css 中放入像 @media print { td { text-align: right } } 这样的 html 元素,它就可以工作。但是没有类... =(
    • 我猜是删除自定义类而不是样式。
    猜你喜欢
    • 2017-01-13
    • 2014-01-05
    • 1970-01-01
    • 2012-08-22
    • 1970-01-01
    • 2022-01-14
    • 2014-09-11
    • 2013-12-16
    • 2015-03-10
    相关资源
    最近更新 更多