【问题标题】:jQuery datatable doesn't print all the pagesjQuery数据表不打印所有页面
【发布时间】:2019-05-08 07:12:53
【问题描述】:

我正在使用 jQuery 数据表(jQuery 版本:jquery-3.1.1.min.js)。我需要打印表中的所有数据(在我的场景中,我有 56 行,每页 10 条记录,然后变成 6 页)。但它只打印数据的一部分(36 条记录)。但我也有 pdf 功能。它工作正常。当点击 pdf 按钮时,它会生成包含所有重新编码的 pdf

<script type="text/javascript" src="<c:url value='/static/js/jquery-3.1.1.min.js' />"></script>
<script src="<c:url value='/static/js/dataTables/jquery.dataTables.min.js' />"></script>
<script src="<c:url value='/static/js/dataTables/dataTables.buttons.min.js' />"></script>   
<script src="<c:url value='/static/js/dataTables/buttons.print.min.js' />"></script>


        <script>
            $(document).ready(function(){
                $('#adTable').DataTable({
                    dom: 'Bfrtip',
                    buttons: [
                         'pdf', 'print'
                    ]
                });
            });
        </script>



    <table id="adTable" class="table table-hover">
        <thead>
            <tr>
                <th>Index</th>
                <th>Subject</th>
                <th>Category</th>
                <th>Status</th>

            </tr>
        </thead>
        <tbody>
            <c:forEach var="obj" items="${list}" varStatus="loop">
                <tr>
                    <td>${loop.index+1}</td>
                    <td>${obj.subject}</td>
                    <td>${obj.category}</td>
                    <td>${obj.status}</td>
                </tr>
            </c:forEach>
        </tbody>
    </table>

【问题讨论】:

    标签: javascript jquery html datatables jquery-pagination


    【解决方案1】:

    我找到了解决方案。问题是由于我的 CSS 文件而发生的。 有一个 css 文件覆盖了我的 html 正文标签 overflow-x

    我的外部 css 文件如下所示

    body {
        padding: 0;
        margin: 0;
        height: 100%;
        min-height: 100%;
        font-family: 'Open Sans', sans-serif;
        color: #4f5f6f;
        overflow-x: hidden; }
    

    我改成下面的了。

    body {
        padding: 0;
        margin: 0;
        height: 100%;
        min-height: 100%;
        font-family: 'Open Sans', sans-serif;
        color: #4f5f6f;
        overflow-x: visible; }
    

    【讨论】:

      【解决方案2】:

      你可以使用下面的代码print all

      $(document).ready(function() {
          $('#example').DataTable( {
              dom: 'Bfrtip',
              buttons: [
                  {
                      extend: 'print',
                      text: 'Print all',
                      exportOptions: {
                          modifier: {
                              selected: null
                          }
                      }
                  },
                  {
                      extend: 'print',
                      text: 'Print selected'
                  }
              ],
              select: true
          } );
      } );
      

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-07
      • 2012-01-11
      • 1970-01-01
      • 2017-01-08
      • 1970-01-01
      • 1970-01-01
      • 2018-01-06
      相关资源
      最近更新 更多