Filtering Table rows using Jquery

前端 未结 9 1298
悲&欢浪女
悲&欢浪女 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: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

提交回复
热议问题