How to detect when all rows in a table are selected?

How to detect when all rows in a table are selected?

lpacelpace Posts: 10Questions: 5Answers: 0

I'd like to make a button and modal appear when all rows of my table are selected to prompt the user to submit the data to my server. Can you provide an example of detecting when all rows are selected?
my code is below, if(rmaTable.rows({"selected":true})) seems to work if ANY row is selected, not ALL.

var rmaTable = $('#rmas').DataTable({
  {"url": ""+customerno,                        
   "columns": [null,
     { "data": "Record.RECID" },
     { "data": "Record.QSHP" },
     { "data": "Record.PART_NO" },
     { "data": "Record.DESCRIPTION" },
  "columnDefs": [ {
            "orderable": false,
            "className": 'select-checkbox',
            "targets":   0,
            "data": null,
                "targets": -1,
                "data": null,
                "defaultContent": "<button class='button'type='button'>SELECT</button>",
        "select": {
            "style":    'multi',
            //"selector": 'td:first-child'
  Listen for keypresses from the RMA pickup input control.
  upon receiving key code for "Enter", compare the value to those in the dataTable #rmas.
  Mark the row in the table as "picked up" (check box) and add the barcode value to a JSON object.

var scanned = document.getElementById("rma-pickups").value;
document.getElementById("rma-pickups").value = '';
 alert("all rows selected!");

}); //end .change callback function


  • kthorngrenkthorngren Posts: 19,462Questions: 26Answers: 4,610

    Maybe compare the length of rows() to rows() with the selector-modifier of {selected: true}. You can use the count() API to get the number of rows. Something like this:

    if( rmaTable.rows({"selected":true}).count() === rmaTable.rows().count()  )
     alert("all rows selected!");


Sign In or Register to comment.