Javascript PHP How to make a realtime count of table row when change -


i have table when type on input field show data searched realtime, mean filtered data when type in textbox.

i did filtered want add features shows text count how many rows filtered.

like this

enter image description here

this filtering code

function searchtable(inputval) { var table = $('#tbldata'); table.find('tr').each(function(index, row) {     var allcells = $(row).find('td');     if(allcells.length)     {         var found = false;         allcells.each(function(index, td)         {             var regexp = new regexp(inputval, 'i');             if(regexp.test($(td).text()))             {                 found = true;                 return false;             }         });         if(found == true)$(row).show();else $(row).hide();     } }); } 

you can count / hidden / shown childs using jquery selectors @ end of code.

you can use these selectors respectively; tr, tr:hidden, tr:visible

function searchtable(inputval) {     var table = $('#tbldata');     table.find('tr').each(function(index, row) {         var allcells = $(row).find('td');         if (allcells.length) {             var found = false;             allcells.each(function(index, td) {                 var regexp = new regexp(inputval, 'i');                 if (regexp.test($(td).text())) {                     found = true;                     return false;                 }             });             if (found == true) $(row).show();             else $(row).hide();         }     });     /* use these values , print / append html. */     var allchilds = $('#tbldata').find('tr').length;     var shownchilds = $('#tbldata').find('tr:visible').length;     var hiddenchilds = $('#tbldata').find('tr:hidden').length;     /* use these values , print / append html. */     var counttemplate = "your template, total:"+allchilds;     $("#counts").html(counttemplate);  } 

Comments