Use bPaginate (the old Hungarian style) or paginate to enable or disable pagination. You can use expressions to define parameters:
$('#tbl_member').dataTable({ "bPaginate" : $('#tbl_member tbody tr').length>10, "iDisplayLength": 10, "bAutoWidth": false, "aoColumnDefs": [ {"bSortable": true, "aTargets": [0,2]} ] });
This works both in data versions 1.9.x and in 1.10.x. The demo shows two tables with one with fewer than 10 entries and the other with a lot more → http://jsfiddle.net/t2xcfLap/3/
Hide pagination controls after updating AJAX. Assuming the JSON response is in the form
{ "draw": 1, "recordsTotal": 3, "recordsFiltered": 3, "data": [ [...], ] }
then
table.on('xhr', function(e, settings, json, xhr) { if (json.recordsTotal<10) { $("#example_paginate").hide(); $("#example_length").hide(); } else { $("#example_paginate").show(); $("#example_length").show(); } })
demo → http://jsfiddle.net/yyo5231z/
The controls entered are named in the form <tableId>_length , <tableId>_paginate . Therefore, if your table has an id table , then the above should be $("#table_paginate").hide(); etc.
The reason for the different approach compared to the first answer using a static table is that you cannot change pagination "on the fly" without reinitializing the table.
source share