admin管理员组文章数量:1356219
I have a DataTable with pagination enabled and I need to disable this setting and show all the results without pager by pressing a button.
I'm trying to access the already defined settings, change the paging to false, and redraw the table, but it doesn't work. I searched and tried similar forum threads without success.
Any idea how can I achieve that?
Here's a demo with my not-working code
HTML:
<div id="main_wrapper">
<button class="form_button destroy_pager" type="button" onclick="" title="Destroy pager">Destroy pager</button>
<table id="example" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
</tr>
</thead>
<tbody>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
</tbody>
</table>
</div>
jQuery:
$(document).ready(function() {
var oTable = $('#example').DataTable({
'bPaginate': true,
'iDisplayLength': 5
});
$('button.destroy_pager').on('click', function() {
var oSettings = oTable.settings;
oSettings.bPaginate = false;
oTable.draw();
});
});
EDIT: I need to have the pager enabled when I initialise the DataTable. The problem is that I have to disable it after the button press.
Thanks in advance
I have a DataTable with pagination enabled and I need to disable this setting and show all the results without pager by pressing a button.
I'm trying to access the already defined settings, change the paging to false, and redraw the table, but it doesn't work. I searched and tried similar forum threads without success.
Any idea how can I achieve that?
Here's a demo with my not-working code
HTML:
<div id="main_wrapper">
<button class="form_button destroy_pager" type="button" onclick="" title="Destroy pager">Destroy pager</button>
<table id="example" cellpadding="0" cellspacing="0" border="0">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Column 3</th>
<th>Column 4</th>
</tr>
</thead>
<tbody>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
<td>Data 3</td>
<td>Data 4</td>
</tr>
</tbody>
</table>
</div>
jQuery:
$(document).ready(function() {
var oTable = $('#example').DataTable({
'bPaginate': true,
'iDisplayLength': 5
});
$('button.destroy_pager').on('click', function() {
var oSettings = oTable.settings;
oSettings.bPaginate = false;
oTable.draw();
});
});
EDIT: I need to have the pager enabled when I initialise the DataTable. The problem is that I have to disable it after the button press.
Thanks in advance
Share Improve this question edited May 8, 2015 at 7:49 chimos asked May 7, 2015 at 14:37 chimoschimos 6642 gold badges15 silver badges35 bronze badges4 Answers
Reset to default 4You should destroy and reinitilize the datatable with bPaginate
option set to false
on button click
$(document).ready(function() {
var table = $('#example');
var tableOptions = {
'bPaginate': true,
'iDisplayLength': 5
};
table.DataTable(tableOptions);
$('button.destroy_pager').on('click', function() {
table.DataTable().destroy()
tableOptions.bPaginate = false;
table.DataTable(tableOptions);
});
});
demo
Use sDom
option. Try sDom: 'ft'
option. It's work for me.
Take a look here: http://datatables/usage/options#sDom
i have an idea to preparing table style before set row number per page. but this make me wondering how datatable api store elements style. if i can set table style and declaring datatable object in the same time. it will make my code more performance
$('#example').DataTable({
'bPaginate': false
});
use the above code.
jsFiddle
本文标签: javascriptHow to disable DataTables paging after initializationStack Overflow
版权声明:本文标题:javascript - How to disable DataTables paging after initialization? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743955726a2568097.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论