How to change results per page value in datatables

前端 未结 7 1048
日久生厌
日久生厌 2021-01-30 21:35

Datatables has an option to select the number of records shown per page. The default value starts from 10, 25, 50 and 100. How can I change it to start from 5 instead of 10? 10

相关标签:
7条回答
  • 2021-01-30 21:55

    I realize that this question is old, but the accepted answer does not answer the OP's question.

    The answer is to override the aLengthMenu option when initializing the dataTable. See here: http://datatables.net/examples/advanced_init/length_menu.html

    0 讨论(0)
  • 2021-01-30 21:56

    You can simply add:

    "lengthMenu": [ 
     [10, 25, 50, -1], 
     [10, 25, 50, "All"] 
    ] // remember to add  "," if you initialize more option manually
    

    or if you only want to add this option

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

    which will give you a drop-down to select the number of records per page in pagination.

    0 讨论(0)
  • 2021-01-30 21:59

    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

    0 讨论(0)
  • 2021-01-30 22:00

    The answer solved my problem of needing the following scenario

    $(document).ready( function(){
        $('#table').dataTable({
      "aLengthMenu": [[10, 25, 50, 100], ["10 Per Page", "25 Per Page", "50 Per Page", "100 Per Page"]]
        });
    });

    0 讨论(0)
  • 2021-01-30 22:02
    $.extend(true, $.fn.dataTable.defaults, {
        "lengthMenu": [[5, 10, 15, 20, 25], [5, 10, 15, 20, 25]],
        "pageLength": 5
    
    });
    
    0 讨论(0)
  • 2021-01-30 22:02

    It hardly for the the data tables 1.9
    "iDisplayLength": 50

    0 讨论(0)
提交回复
热议问题