Table Filters with jQuery

0

I have implemented a table filter with jQuery, as per the code below, but I would like to implement a register return counter as I search.

$(function(){
    $(".input-search").keyup(function(){
        //pega o css da tabela 
        var tabela = $(this).attr('alt');
        if( $(this).val() != ""){
            // OCULTA VALORES NÃO ENCONTRADOS.
            $("."+tabela+" tbody>tr").hide();
            // EXIBE OS RESULTADOS ENCONTRADOS.
            $("."+tabela+" td:contains-ci('" + $(this).val() + "')").parent("tr").show();

        } else{
            //EXIBE TABELA TODA 
            $("."+tabela+" tbody>tr").show();

        }
    }); 
});
$.extend($.expr[":"], {
    "contains-ci": function(elem, i, match, array) {
        return (elem.textContent || elem.innerText || $(elem).text() || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
    }

});
    
asked by anonymous 30.05.2017 / 16:52

1 answer

0

If I understood correctly what I need, I think it worked. I added the counter right at the start to get access to the scope, then we reset it so that it does not take away other counts. Then, when the item is displayed, we add the count to have the total of records displayed.

Updated code:

    $(function() {

        var contador = 0;

        $(".input-search").keyup(function() {

            contador = 0;

            //pega o css da tabela 
            var tabela = $(this).attr('alt');
            if ($(this).val() != "") {
                // OCULTA VALORES NÃO ENCONTRADOS.
                $("." + tabela + " tbody>tr").hide();
                // EXIBE OS RESULTADOS ENCONTRADOS.
                $("." + tabela + " td:contains-ci('" + $(this).val() + "')").parent("tr").show();

                contador = $("." + tabela + " td:contains-ci('" + $(this).val() + "')").length;

            } else {
                //EXIBE TABELA TODA 
                $("." + tabela + " tbody>tr").show();

            }
        });
    });

    $.extend($.expr[":"], {
        "contains-ci": function(elem, i, match, array) {
            return (elem.textContent || elem.innerText || $(elem).text() || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
        }
    });
    
30.05.2017 / 17:04