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.

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;
});
});
This discussion has been closed.
Answers
You can use
count()
to count therows()
. In order to get the number of rows displayed after searching use theselector-modifier
of{search:'applied'}
. For example:table.rows( {search:'applied'} ).count();
Kevin