How to get number of selected rows? (server-side)

How to get number of selected rows? (server-side)

culterculter Posts: 102Questions: 24Answers: 0

Hi, I'm trying to get the number of selected rows, but always get 0. I have server-side processing on if that matters. I tried this code:

$(document).ready(function() {
 var table = $('#dates').DataTable( {} );


var dataA = table
                .rows()
                .data();

console.log( "DataLength: " + dataA.length );



var info = table.page.info();

$('#tableInfo').html(
    'Currently showing page '+(info.page+1)+' of '+info.pages+' pages.'
);


});

Thank you for any advice.

Answers

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

    Hi @culter ,

    If you're using the Responsive plugin, you can use

    table.rows({selected:true}).count()
    

    Cheers,

    Colin

  • culterculter Posts: 102Questions: 24Answers: 0

    Hi Colin, thank you for the response. I turned responsive to true and tried to retrieve the count of selected rows with

     console.log(table.rows({selected:true}).count());
    

    but as previously I got 0.

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

    Hi @culter ,

    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

This discussion has been closed.