Select only displayed rows in Jquery Multiple DataTables

Select only displayed rows in Jquery Multiple DataTables

ayush1795ayush1795 Posts: 3Questions: 1Answers: 0
edited December 2018 in Free community support

I have multiple Jquery Datatables (number of table is dynamic). I have created multiple tables with the help of

$(document).ready(function() {
    $('table.display').DataTable();
} );

I want to add select and deselect all button which will select and deselect only visible rows.

What code should I add so that these buttons are added into all tables.

thanks

Replies

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @ayush1795 ,

    This example here shows what you need to do.

    Cheers,

    Colin

  • ayush1795ayush1795 Posts: 3Questions: 1Answers: 0

    @colin , Thank you but I have multiple tables and number of tables are not fixed. The example you gave me works for only one table. help me out

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    Hi @ayush1795 ,

    We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.

    Cheers,

    Colin

  • rf1234rf1234 Posts: 2,986Questions: 87Answers: 421
    edited December 2018

    This is a custom button that does what you need. If you also want to select invisible data tables and to ignore filtering (i.e. also select rows that are filtered out) modify as per your requirements.

    //custom button to select all rows of all visible data tables
    //only selecting filtered rows
    $.fn.dataTable.ext.buttons.selectAll = {
        text: 'selectAll',
        action: function ( e, dt, button, config ) {
            $.fn.dataTable
                .tables( { visible: true, api: true } )
                .rows({ search: 'applied' }).select();
        }
    };
    
This discussion has been closed.