how to get the current length of row after search on search filed in datatables.

how to get the current length of row after search on search filed in datatables.

akash_123akash_123 Posts: 7Questions: 4Answers: 0

this is my

<

script>

$(document).ready(function() {
var table = $('#emp_example').DataTable({

      scrollX: true,
      fixedColumns: {
            leftColumns: 2
       }
  });

  $('#emp_example').on(' keyup search.dt', function() {
      var value = $('.dataTables_filter input').val();
      // alert('*** '+value); // <-- the val

      var table = document.getElementById('emp_example')
      rows = table.getElementsByTagName('tr')
      alert('rows length '+rows.length);

      var totalCount = 0;

      for(i = 2; i<rows.length;i++)
      {
        cells = rows[i].getElementsByTagName('td');
        //alert('cells is '+cells.length);
        if (!cells.length) {
          continue;
        }

        //alert('cells[7].innerHTML  '+cells[7].innerHTML);
        totalCount = parseInt(totalCount) + parseInt(cells[7].innerHTML);
        //alert('totalCount '+totalCount)  
      } 
      var x = document.getElementById("emp_example").rows[rows.length-1].cells;
      x[7].innerHTML = totalCount;   
  }); 

});

Answers

  • kthorngrenkthorngren Posts: 21,166Questions: 26Answers: 4,921

    You can use count() to count the rows(). In order to get the number of rows displayed after searching use the selector-modifier of {search:'applied'}. For example: table.rows( {search:'applied'} ).count();

    Kevin

This discussion has been closed.