disable pagination if there is only one page in datatables disable pagination if there is only one page in datatables javascript javascript

disable pagination if there is only one page in datatables


Building off of Nicola's answer, you can use the fnDrawCallback() callback and the oSettings object to hide the table pagination after it's been drawn. With oSettings, you don't need to know anything about the table settings (records per page, selectors specific to the table, etc.)

The following checks to see if the per-page display length is greater than the total records and hides the pagination if it is:

$('#your_table_selector').dataTable({    "fnDrawCallback": function(oSettings) {        if (oSettings._iDisplayLength > oSettings.fnRecordsDisplay()) {            $(oSettings.nTableWrapper).find('.dataTables_paginate').hide();        } else {             $(oSettings.nTableWrapper).find('.dataTables_paginate').show();        }    }});

Documentation


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";   }}


See my feature plugin conditionalPaging.

Usage:

$('#myTable').DataTable({    conditionalPaging: true});or$('#myTable').DataTable({    conditionalPaging: {        style: 'fade',        speed: 500 // optional    }});