2014-07-25 97 views
0

我有許多名稱的信息表。第一欄是名,第二欄是姓,第三欄是號碼。我想根據用戶輸入顯示所有行,但只希望搜索過濾器通過具有id的特定列。按特定列jQuery表格過濾器

jQuery代碼:我有:

(document.ready(function() 


$("#searchHere").keyup(function() { 
    var $row = $("table tr"); 
    var $col = $("td").each().index(); 
    var input = this.value.toLowerCase(); 

    $row.show().filter(function() { 
    $(this).find("td").eq(col).text().toLowerCase(); 
    return $(this).text(input); 
    }).hide(); 
}); 

的HTML代碼

<input id="searchHere" placeholder="Search Me"> 

<table> 
<tr> 
    <td id='firstName'>John</td> 
    <td id='lastName'>Doe</td> 
    <td>One Two Three</td> 
</tr> 

<tr> 
    <td id='firstName'>John</td> 
    <td id='lastName'>Smith</td> 
    <td>Two Three</td> 
</tr> 
</table> 

我已經提到這個職位,但我想不通的最後一塊拼圖。

How to perform a real time search and filter on a HTML table

回答

0

你可以有一個全球性的搜索框,看起來在每個單元相對於獨立的輸入。

+1

是的,我切換到1搜索欄瀏覽所有的TD ID。 – bryan151

+0

如果這已回答您的問題,請通過單擊打勾將其標記爲解決方案。很高興我能幫上忙 :) – swiss196