Change values of select box of "show 10 entries" of jquery datatable

JqueryDatatables

Jquery Problem Overview


By default, jquery datatable shows 10 by default and has

options : 10,25,50,100

How can I change these options?

Jquery Solutions


Solution 1 - Jquery

Don't forget to change the iDisplayLength as well:

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

Solution 2 - Jquery

$(document).ready(function() {
    $('#example').dataTable( {
    "aLengthMenu": [[25, 50, 75, -1], [25, 50, 75, "All"]],
    "pageLength": 25
    } );
} );

aLengthMenu : This parameter allows you to readily specify the entries in the length drop down menu that DataTables shows when pagination is enabled. It can be either a 1D array of options which will be used for both the displayed option and the value, or a 2D array which will use the array in the first position as the value, and the array in the second position as the displayed options (useful for language strings such as 'All').

Update

Since DataTables v1.10, the options you are looking for are pageLength and lengthMenu

Solution 3 - Jquery

In my case , aLengthMenu is not working. So i used this. And it is working.

jQuery('#dyntable3').dataTable({            
            oLanguage: {sLengthMenu: "<select>"+
            "<option value='100'>100</option>"+
            "<option value='200'>200</option>"+
            "<option value='300'>300</option>"+
            "<option value='-1'>All</option>"+
            "</select>"},
            "iDisplayLength": 100
            
        });

Thank you

Solution 4 - Jquery

According to datatables.net the proper way to do this is adding the lengthMenu property with an array of values.

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

Solution 5 - Jquery

 $('#tblSub1View').dataTable({
                    "bJQueryUI": true,
                    "sPaginationType": "full_numbers",
                    "bDestroy": true,
                    "aoColumnDefs": [{
                        'bSortable': false,
                        'aTargets': [0, 1]
                    }],
                    "aLengthMenu": [[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]],
                    "iDisplayLength": 10,
                });

Solution 6 - Jquery

if you click some button,then change the datatables the displaylenght,you can try this :

 $('.something').click( function () {
var oSettings = oTable.fnSettings();
oSettings._iDisplayLength = 50;
oTable.fnDraw();
});

oTable = $('#example').dataTable();

Solution 7 - Jquery

you can achieve this easily without writing Js. Just add an attribute called data-page-length={put your number here}. see example below, I used 100 for example

<table id="datatable-keytable" data-page-length='100' class="p-table table table-bordered" width="100%">

Solution 8 - Jquery

If you want to use 'lengthMenu' together with buttons(copy, export), you have to use this option dom: 'lBfrtip'. Here https://datatables.net/reference/option/dom you can find meaning of each symbol. For example, if you will use like this 'Bfrtip', lengthMenu will not appears.

Solution 9 - Jquery

enter image description here pageLength: 50,

worked for me Thanks

Versions for reference

jquery-3.3.1.js

/1.10.19/js/jquery.dataTables.min.js

/buttons/1.5.2/js/dataTables.buttons.min.js

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionrjmcbView Question on Stackoverflow
Solution 1 - JquerydavesaveView Answer on Stackoverflow
Solution 2 - JqueryPriyank PatelView Answer on Stackoverflow
Solution 3 - JqueryMira PadaliaView Answer on Stackoverflow
Solution 4 - JqueryMZaragozaView Answer on Stackoverflow
Solution 5 - Jqueryuser3789888View Answer on Stackoverflow
Solution 6 - JquerynihaoqiulinheView Answer on Stackoverflow
Solution 7 - JquerySodruldeen MustaphaView Answer on Stackoverflow
Solution 8 - JqueryKirill AView Answer on Stackoverflow
Solution 9 - Jquerysubramanya46View Answer on Stackoverflow