Filtering Table rows using Jquery

前端 未结 9 1274
悲&欢浪女
悲&欢浪女 2020-11-30 19:19

I found a Jquery script that does the table filtering stuff based on input field. This script basically takes the filter, splits each word and filters table rows with each w

相关标签:
9条回答
  • 2020-11-30 20:13

    nrodic has an amazing answer, and I just wanted to give a small update to let you know that with a small extra function you can extend the contains methid to be case insenstive:

    $.expr[":"].contains = $.expr.createPseudo(function(arg) {
        return function( elem ) {
            return $(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
        };
    });
    
    0 讨论(0)
  • 2020-11-30 20:14

    tr:not(:contains(.... work for me

    function busca(busca){
        $("#listagem tr:not(:contains('"+busca+"'))").css("display", "none");
        $("#listagem tr:contains('"+busca+"')").css("display", "");
    }
    
    0 讨论(0)
  • 2020-11-30 20:16

    There's no need to build an array. You can address the DOM directly.

    Try :

    rows.hide();
    $.each(data, function(i, v){
        rows.filter(":contains('" + v + "')").show();
    });
    

    DEMO

    EDIT

    To discover the qualifying rows without displaying them immediately, then pass them to a function :

    $("#searchInput").keyup(function() {
        var rows = $("#fbody").find("tr").hide();
        var data = this.value.split(" ");
        var _rows = $();//an empty jQuery collection
        $.each(data, function(i, v) {
            _rows.add(rows.filter(":contains('" + v + "')");
        });
        myFunction(_rows);
    });
    

    UPDATED DEMO

    0 讨论(0)
提交回复
热议问题