Reputation: 9720
I use jquery datatable in page above table I have selector for records per page
<div id="NewsTable_length" class="dataTables_length">
<label><select size="1" name="NewsTable_length" aria-controls="NewsTable">
<option value="25" selected="selected">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select> records per page</label>
</div>
below table I have pagination
<div class="dataTables_paginate paging_bootstrap pagination">
<ul>
<li class="prev disabled"><a href="#">←
<span class="hidden-480">Prev</span></a></li>
<li class="active"><a href="#">1</a></li>
<li class="next disabled"><a href="#">
<span class="hidden-480">Next</span> → </a></li>
</ul>
</div>
I want to hide dataTables_paginate :
$('.dataTables_paginate').hide();
in:
"fnDrawCallback": function () {
},
when Total rows < NewsTable_length.selected
any suggestions? thanks in advance,..
Upvotes: 2
Views: 3516
Reputation: 1440
You can try this code
var oTable = $('#tableTxn').DataTable({
"processing": true,
"serverSide": true,
"searching": false,
"iDisplayLength": 10,
"bSort": false,
"bFilter": true,
"bLengthChange": true,
"lengthMenu": [10, 20, 30],
"ajax": {
data: { },
"type": "post",
"url": "",
},
drawCallback: function(settings) {
var pagination = $(this).closest('.dataTables_wrapper').find('.dataTables_paginate');
pagination.toggle(this.api().page.info().pages > 1);
}
});
Upvotes: 0
Reputation: 4652
In addition to the accepted answer, if you want to hide it based on the current length that the user has selected, you can change the hard-coded 10
to oSettings._iDisplayLength
.
If you want to hide the pagination when you've filtered down the tableto 1 page, you can change the oSettings.fnRecordsTotal()
to oSettings.fnRecordsDisplay()
.
Upvotes: 1
Reputation: 146
"fnDrawCallback": function ( oSettings ){
if(oSettings.fnRecordsTotal() < 10){
$('.dataTables_length').hide();
$('.dataTables_paginate').hide();
} else {
$('.dataTables_length').show();
$('.dataTables_paginate').show();
}
}
Upvotes: 5