disable pagination if there is only one page in datatables
datatables, javascript, pagination
Solution
You must hide them dynamically I think, you can use `fnDrawCallback()`
$('#example').dataTable({
"fnDrawCallback": function(oSettings) {
if ($('#example tr').length < 11) {
$('.dataTables_paginate').hide();
}
}
});
EDIT - another way found here could be
"fnDrawCallback":function(){
if ( $('#example_paginate span span.paginate_button').size()) {
$('#example_paginate')[0].style.display = "block";
} else {
$('#example_paginate')[0].style.display = "none";
}
}
Problem
I am implementing datatbales and according to my requirement, most of the things have been resolved except the pagination issue. In my case for every time pagination navigation is displaying. I want to disable the pagination navigation if there is only one page at all.How to do that? My code is like: JS ``` <script> function fnFilterColumn(i) { $('#example').dataTable().fnFilter( $("#col" + (i + 1) + "_filter").val(), i ); } $(document).ready(function() { $('#example').dataTable({ "bProcessing": true, "sAjaxSource": "datatable-interestdb.php", "bJQueryUI": true, "sPaginationType": "full_numbers", "sDom": 'T<"clear">lfrtip', "oTableTools": { "aButtons": [ { "sExtends": "csv", "sButtonText": "Save to CSV" } ] }, "oLanguage": { "sSearch": "Search all columns:" } }); $("#example").dataTable().columnFilter({ aoColumns: [ null, null, null, null ] }); $("#col1_filter").keyup(function() { fnFilterColumn(0); }); }); </script> ``` HTML ``` <table cellpadding="3" cellspacing="0" border="0" class="display userTable" aria-describedby="example_info"> <tbody> <tr id="filter_col1"> <td>Interest:</td> <td> <input type="text" name="col1_filter" id="col1_filter"> </td> </tr> </tbody> </table> <table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="form_table display" id="example"> <thead> <tr> <th class="sorting_asc" width="25%">Interest</th> <th width="25%">Name</th> <th width="25%">Email</th> <th width="25%">Contact No</th> </tr> </thead> <tbody> <tr> <td colspan="4" class="dataTables_empty">Loading data from server</td> </tr> </tbody> <tfoot> <tr> <th></th> <th></th> <th></th> <th></th> </tr> </tfoot> </table> ```