Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DataTables - how do you set a default value for lengthMenu?

DataTables allows you to change the options in the dropdown menu for number of records shown per page: https://datatables.net/reference/option/lengthMenu

However, if you define it as per the example:

"lengthMenu": [ 10, 25, 50, 75, 100 ]

You will get a default option of 10, because this appears first in the array.

What if you want to use something else (e.g. 50 or 75) as the default option? I can't see any method on their documentation that allows this. I understand you could use jquery to target by element value, but that seems like a terrible idea.

like image 827
Andy Avatar asked Jun 26 '17 14:06

Andy


1 Answers

Can you try this ? :)

$('#example').dataTable( {
  "pageLength": 50
} );
like image 165
Fered Avatar answered Nov 15 '22 05:11

Fered