2017-05-30 11 views
1

私は私の小枝に検索フィルタを実装したいと思います。私はJQueryのツリーテーブルライブラリを使用していますが、これはこれまで行ってきたことですが、動作していないようです。理由が分かっている人は誰ですか?jQueryの小文字の検索フィルタ

これは私のHTMLです:

<table id="example"> 
    <tbody> 
    <thead> 
     <tr> 
     <th>Tree data</th> 
     </tr> 
     <input class="search" placeholder="Search" /> 
     <p class="log"></p> 
    </thead> 
</tbody> 

そして、これは私が検索フィルタのために実装されている機能である:

var $rows = $('#example tr').treetable({expandable: true}); 
$('#search').keyup(function() { 
    var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase(); 

    $rows.show().filter(function() { 
    var text = $(this).text().replace(/\s+/g, ' ').toLowerCase(); 
    return !~text.indexOf(val); 
    }).hide(); 
}); 

答えて

0

まず、それは$('.search').keyup ...の代わり$('#search').keyup...する必要があります。

二つ目は、私が思うに、より良い方法は次のとおりです。頭が常に残る。このように

var $rows = $('#tree_table tbody tr').treetable({expandable: true}); 
$('.search').keyup(function() { 
    var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase(); 
    $rows.show().filter(function() { 
     var text = $(this).text().replace(/\s+/g, ' ').toLowerCase(); 
     return !~text.indexOf(val); 
    }).hide(); 
}); 

関連する問題