[Answer]-Table row filtering with js or jquery

1👍

Mocked up the functionaltiy you requested, using some slow, simple, exhaustive checks. —http://jsfiddle.net/B2Muh/3/

$(function () {
    $filterArgs = $("ul li").filter(function () {
        var txt = $(this).text();
        return txt.indexOf("Filter") < 0;
    });
    $filterArgs.click(function () {
        $(this).toggleClass('active');
        $("table tr").hide();
        $("table tr td").each(function () {
            $rowData = $(this);
            $filterArgs.filter(".active").each(function () {
                if ($rowData.text() == $(this).text()) {
                    $rowData.parent().show();
                    return false;
                }
            });
        });
    });
});

0👍

I’ve written a sample code. I think this is what you want.

    $('body').on('click','li',function(){

    var filterText=$(this).html().trim();
    var splicedTextArray=filterText.split(" ");
    var filter=splicedTextArray[0].toLowerCase();

    $('tr').each(function(index,value){

        var valueText=$(this).find('td:first').html();
        var isRegexmatch=valueText.toLowerCase().indexOf(filter);

        if(isRegexmatch<0)
        {
        $(this).hide();
        }else
        {
        $(this).show();
        }


    });

});

See it in action on JSFiddle

Leave a comment