<table>
<thead>
<th>Code</th>
<th>Name</th>
<th>barcode</th>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Milk</td>
<td>504</td>
</tr>
<tr>
<td>2</td>
<td>Cheese</td>
<td>302</td>
</tr>
<tr>
<td>3</td>
<td>Butter</td>
<td>654</td>
</tr>
</tbody>
Above is the table I created.Using jQuery I want to search for the data using a particular th .For example I want to search this able by using the code only So If I input 1 the first record will come, And If I want to search the table using the Name only when I start typing the name the particular record should come.Just I should want to apply (search by the code,search by the name,search by the barcode) those options.I have tried this but this return all the records of every field, I want to search by a particular field only this is the way I tried,
$(document).on('keyup', '#searchProduct', function(){
var searchKey = $(this).val().toLowerCase();
$('#productTable tbody tr').each(function(){
var str = $(this).text().toLowerCase();
if(str.indexOf(searchKey) == -1){
$(this).hide();
} else {
$(this).show();
}
});
});