我正在尝试将默认分页移到表格之外。 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/