Change values of select box of “show 10 entries” of jquery datatable

后端 未结 9 1397
攒了一身酷
攒了一身酷 2021-01-30 12:24

By default, jquery datatable shows 10 by default and has

options : 10,25,50,100

How can I change these options?

相关标签:
9条回答
  • 2021-01-30 13:02
     $('#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,
                    });
    
    0 讨论(0)
  • 2021-01-30 13:03

    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%">
    
    0 讨论(0)
  • 2021-01-30 13:05

    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

    0 讨论(0)
  • 2021-01-30 13:09

    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.

    0 讨论(0)
  • 2021-01-30 13:10

    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"]]
        } );
    } );
    
    0 讨论(0)
  • 2021-01-30 13:15

    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
        });
    } );
    
    0 讨论(0)
提交回复
热议问题