How to show all rows by default in JQuery DataTable
Asked Answered
A

9

92

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]
    });
Analyst answered 25/2, 2012 at 11:58 Comment(0)
R
268

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
});
Resor answered 4/10, 2012 at 12:41 Comment(3)
Or "paging": false if you use DataTables 1.10 new API.Hanoverian
Or <table data-display-length='-1'> if you want to use DOM options (DataTables 1.10+, see datatables.net/manual/data/orthogonal-data#HTML-5).Epagoge
The meat of this very correct answer is iDisplayLength: -1Recliner
Q
17

The option you should use is iDisplayLength:

$('#adminProducts').dataTable({
  'iDisplayLength': 100
});
Quinonoid answered 25/2, 2012 at 12:11 Comment(0)
D
6
$('#table').DataTable({
   "lengthMenu": [ [5, 10, 25, 50, -1], [5, 10, 25, 50, "All"] ]
});
Diachronic answered 25/8, 2015 at 10:19 Comment(0)
O
3

It will Load by default all entries.

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

Or if using 1.10+

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

If you want to load by default 25 not all do this.

$('#example').dataTable({
    aLengthMenu: [
        [25, 50, 100, 200, -1],
        [25, 50, 100, 200, "All"]
    ],
});
Okwu answered 17/12, 2021 at 7:20 Comment(0)
A
2

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">

Addams answered 28/9, 2016 at 0:36 Comment(1)
perfecto mondo! The best answer given the secnario where a global DataTables() initialization is doneOverdose
F
2

This one works for me:

    $(document).ready(function() {
    $('#example').DataTable( {
        "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]]
      } );
    } );
Fascinator answered 19/10, 2016 at 6:43 Comment(0)
P
1

Here is the entire functional javascript for your .html file

<!--- javascript -->
<script type="text/javascript">
  $(document).ready(function(){
    $('#sortable').dataTable({
        'iDisplayLength': 100
    })})
</script>
Petrol answered 9/3, 2018 at 6:41 Comment(0)
A
0

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
            });
        }
})
Archiepiscopate answered 25/2, 2012 at 12:4 Comment(0)
B
0

you have to download the bootstrap-table.min.js and make some modification to it..

  • If you download the bootstrap-table.min.js, just open it, and try to find "pageList:[10," make it as "pageList:[10,15,20,25,50,100,"All"]" make sure that "All" written as this.

  • Default page size can be changed as well from the same line "pageSize:10" you can change it as pageSize:"All".

  • Other options can be modified as well.

  • Don't forget to include it or linked to new place after completed your modification.

I hope it is clear and easy enough to be done.

Boa answered 10/7, 2019 at 9:13 Comment(1)
I tried all the above answers and it didn't work.. Just follow the above Instructions.Boa

© 2022 - 2024 — McMap. All rights reserved.