How to show all rows by default in JQuery DataTabl

2019-01-16 18:00发布

问题:

Does anybody know how to show all rows by default in jQuery datatable?

I have tried this code, but it only shows 10 rows by default.

   $("#adminProducts").dataTable({
        "aLengthMenu": [100]
    });

回答1:

Use:

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

Or if using 1.10+

$('#example').dataTable({
    paging: false
});


回答2:

The option you should use is iDisplayLength:

$('#adminProducts').dataTable({
  'iDisplayLength': 100
});


回答3:

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


回答4:

This one works for me:

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


回答5:

If you're using DataTables 1.10+ you can use the data-* attribute in your <table> tag data-page-length="-1"

This assumes you have "-1" defined in your datatable default configuration, such as below

$.extend(true, $.fn.dataTable.defaults, { 
    lengthMenu: [[10, 25, 50, 250, -1], [10, 25, 50, 250, "All"]]
});

Your javascript becomes simply $("table").DataTables(); and you're able to customize the display for every table within in the HTML; IE. if you have second, smaller table in the same page that should be limited to 10 rows, <table data-page-length="10">



回答6:

use 'fnDrawCallback'

  $('#dataTable').dataTable({
        "bJQueryUI": true,
        "sPaginationType": "full_numbers",
        "fnInitComplete": function(){
            $('.display_results').show();
        },
        "fnDrawCallback": function() {
            $('.def').click(function(){
                var msg = $(this).next().text();
                $('.messages').messageBox()//Custom Dialog
            });
        }
})


回答7:

Here is the entire functional javascript for your .html file

<!--- javascript -->
<script type="text/javascript">
  $(document).ready(function(){
    $('#sortable').dataTable({
        'iDisplayLength': 100
    })})
</script>