Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show length menu of DataTable JQuery?

How to show length menu of a JQuery DataTable? It disappear upon activating exportation (COPY, EXCEL, PDF). I already added the lengthMenu but it is not showing the drop down. This is what i did:

$(document).ready(function() {
    var table = $('#example').DataTable( {
        lengthChange: false,
        buttons: [ 'copy', 'excel', 'pdf' ],
        responsive: true,
        'columnDefs': [ {
                'targets': [6], /* column index */
                'orderable': false, /* true or false */
                'lengthMenu': [[10, 25, 50, -1], [10, 25, 50, "All"]]
        }]
    } );
    table.buttons().container().appendTo( '#example_wrapper .col-md-6:eq(0)' );
} );

I am using the jquery 3.3.1 and datatables 1.10.19 via cdn.

like image 800
Anirudh Lou Avatar asked Nov 02 '25 01:11

Anirudh Lou


1 Answers

Try to add the dom param like dom: 'Blfrtip'. See also the documentation

$(document).ready(function() {
    var table = $('#example').DataTable( {
        lengthChange: true,
        buttons: [ 'copy', 'excel', 'pdf' ],
        responsive: true,
        dom: 'Blfrtip',
        columnDefs: [ {
                targets: [6], /* column index */
                orderable: false, /* true or false */
                lengthMenu: [[10, 25, 50, -1], [10, 25, 50, "All"]]
        }]
    } );
    table.buttons.container.appendTo( '#example_wrapper .col-md-6:eq(0)' );
} );
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="//cdn.datatables.net/1.10.19/js/jquery.dataTables.min.js"></script>
<link href="//cdn.datatables.net/1.10.19/css/jquery.dataTables.min.css" rel="stylesheet"/>

<table id="example">
  <thead>
    <tr>
      <th>Example</th>
      <th>Example</th>
      <th>Example</th>
      <th>Example</th>
      <th>Example</th>
      <th>Example</th>
      <th>Example</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Example</td>
      <td>Example</td>
      <td>Example</td>
      <td>Example</td>
      <td>Example</td>
      <td>Example</td>
      <td>Example</td>
    </tr>
  </tbody>
</table>
  
like image 178
Dontwan Avatar answered Nov 03 '25 17:11

Dontwan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!