How to change results per page value in datatables

前端 未结 7 1049
日久生厌
日久生厌 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 22:19

    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.

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