Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show records per page drop down along with export button on datatables

Unable to show records per page drop down after displaying the export buttons. I want to display both of them on my table. Here is my code:

$(document).ready(function() {
    $('#dataTables-example').DataTable({
        pageLength: 5,
        dom: 'Bfrtip',
        buttons: ['csv', 'excel', 'pdf', 'print'],
        responsive: true
    });
    $('.datetext').datepicker({
        format: "yyyy-mm-dd"
    });
});

Records per page drop down displayed if I remove the buttons on the tables, But I want to display both of them. How to display both of them?

like image 697
rbstack Avatar asked Dec 21 '15 20:12

rbstack


2 Answers

This layout is done here:

dom: 'Bfrtip',

So you have several options for this, and I don't know what you wish to do, but try this:

dom: 'flit',

This will show the selector on the left. The buttons you are adding are normally added to the right, so you need to set this to the left.

like image 163
Franco Avatar answered Sep 21 '22 02:09

Franco


If i'm not wrong you are looking to have both pagelength and export buttons visible together. As per me, rather than going for a native drop down you can actually get a real nice button click drop down with the below code, in addition to your native export buttons. You just need to pass the 'pageLength' argument for initializing the DT with additional button which would be the placeholder for page length drop down. Example would be.

$(document).ready(function() {
    $('#example').DataTable( {
        dom: 'Bfrtip',
        // Configure the drop down options.
        lengthMenu: [
            [ 10, 25, 50, -1 ],
            [ '10 rows', '25 rows', '50 rows', 'Show all' ]
        ],
        // Add to buttons the pageLength option.
        buttons: [
            'pageLength','excel','print'
        ]
    });
});

Do not forget to include the select js and css. You can find the here

like image 26
user1697113 Avatar answered Sep 18 '22 02:09

user1697113