javascript - 将分页移到数据表之外

标签 javascript jquery datatables

我正在尝试将默认分页移到表格之外。 Datables 文档说只有一种分页绑定(bind),即 .page() 用于更改当前页面。问题是它没有考虑到诸如达到页面限制时禁用按钮、当前页面等的情况...有什么方法可以让我只复制表外的分页按钮而不编写所有分页功能用手?

<table id="table_id" class="display">
  <thead>
      <tr>
          <th>Column 1</th>
          <th>Column 2</th>
      </tr>
  </thead>
</table>
<div id="custom-pagination">
</div>
<script>
let dt = $('#table_id').DataTable();

$(dt).on( 'draw.dt', function () {
  $(dt).find('.datatTables_paginate').appendTo('#custom-pagination'); 
});

</script>

最佳答案

对我来说,这已经过测试并且有效:

$('#table').DataTable({
    ... other options ... ,
    initComplete: (settings, json)=>{
        $('.dataTables_paginate').appendTo('body');
    },
});

但是如果同一页面中有其他数据表,则需要使用表 ID 来绑定(bind)元素,如下所示:

$('#table1').DataTable({
    ... other options ... ,
    initComplete: (settings, json)=>{
        $('#table1_paginate').appendTo('body');
    },
});

所以!

关于javascript - 将分页移到数据表之外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52103710/

相关文章:

javascript - 在 jQuery 中只选择整个 css 类的一个 div

javascript - 使用 Jquery 检查时通过复选框更改背景颜色

javascript - 数据表: click on button does not open view

javascript - 如何删除多选中的空值

javascript - 通过 id 和 index 索引

javascript - 根据 ID 插入多个项目 - Laravel

jquery - jquery中隐藏列表项

c# - 如何从数据表中的服务器端jquery数据表获取图像src值?

jquery - 需要帮助使用 DataTable 中的数据操作 MySQL 中的数据

javascript - 如何在循环中的 Coffeescript 中使用 setTimeout