Unable to find DataTable count when i search records
Unable to find DataTable count when i search records
I have used various filters on my data table and I an easily extract the number of rows now the table has using:
var count = $('#myTable').DataTable().data().count();
or just by getting length of the final filtered list.
It does not return right result and stays with the previous result when I search using the search box. Here is my search box implementation:
$('#searchText').keyup(function(){
table.search($(this).val()).draw();
});
When i use the data().count() after this draw() method. It sticks with previous values.
How can i get the updated table count in this after the search has been performed ?
This question has an accepted answers - jump to answer
Answers
Hi @TalhaDX ,
It's easiest to use
page.info()
for that info - see example here.Cheers,
Colin
@colin
My Data table is already initialized. So when I call this on searchText keyup method or even in document.ready it throws an error:
DataTables warning: table id=myTable - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3
How can i use this callback internally without initializing again.
PS: I am not using the data table, default search box.
Before, where you had
replace that with
Cheers,
Colin
Ahh finally. Great thanks