How to change results per page value in datatables How to change results per page value in datatables javascript javascript

How to change results per page value in datatables


The fully correct answer would be to use both and display length to 5:

$(document).ready( function(){    $('#table').dataTable({    "iDisplayLength": 5,    "aLengthMenu": [[5, 10, 25, 50, -1], [5, 10, 25, 50, "All"]]    });});

If you use JUST "iDisplayLength", then the dropdown will not have that length in options later or when the page loads (instead you will see the first option, IE 10 by default). If you JUST use "aLengthMenu", then your results will still default to 10 instead of the first menu option.


You will want to use the iDisplayLength parameter when you initialize the DataTable object. Here's the example they list in their documentation:

$(document).ready( function() {    $('#example').dataTable( {        "iDisplayLength": 50    } );} )

More information can be found here: http://www.datatables.net/usage/options


$.extend(true, $.fn.dataTable.defaults, {    "lengthMenu": [[5, 10, 15, 20, 25], [5, 10, 15, 20, 25]],    "pageLength": 5});