add more options in records per page dropdown using datatable jquery

General Electric picture General Electric · Jun 5, 2014 · Viewed 8.4k times · Source

I've been using the datatable jquery (http://datatables.net/ ) plugin.

Everything is working fine, but now I want to be able to select more than the default options of records per page, by default I can choose 10 , 25 , 50 , 100. I want to add 15 and 30 to this list.

How can I do that, I searched on internet but could't find any answer.

Thanks

Answer

Daniel picture Daniel · Jun 5, 2014

Use pageLength and lengthMenu for setting the default view, like this:

$('#example').DataTable({
        "pageLength": 15,
        "lengthMenu": [[10, 15, 25, 35, 50, 100, -1], [10, 15, 25, 35, 50, 100, "All"]]
    });

old api

  $('#example').dataTable({
        "iDisplayLength": 15,
        "aLengthMenu": [[10, 15, 25, 35, 50, 100, -1], [10, 15, 25, 35, 50, 100, "All"]]
    });

Second array will hold the values for that will be displayed in the drop down menu

Read more: DataTables example - Page length options