hi ,
I am doing search in my html table in column wise.
in this table i am not able to apply search
Can you please help me how to exclude second row in table.
I exclude first row using this:-
var $rows = $('#table tr').not(':first');
But not able to exclude second row.
please help me
<p>Filter table:</p>
<br />
<table id="table" cellspacing="0">
<tr>
<th>Code</th>
<th>First</th>
<th>Second</th>
<th>Letter</th>
</tr>
<tr>
<th><input type="text" id="search1" placeholder="Code" /></th>
<th><input type="text" id="search2" placeholder="First" /></th>
<th><input type="text" id="search3" placeholder="Second" /></th>
<th><input type="text" id="search4" placeholder="Letter" /></th>
</tr>
<tr>
<td>AA</td>
<td>DDD</td>
<td>NULL</td>
<td>Z</td>
</tr>
<tr>
<td>EE</td>
<td>VYX</td>
<td>ALL</td>
<td>J,D</td>
</tr>
<tr>
<td>RR</td>
<td>ROUND</td>
<td>NULL</td>
<td>C</td>
</tr>
</table>
<script type="text/javascript">
var $rows = $('#table tr').not(':first');
var filters = { col1: '', col2: '', col3: '', col4: '' };
$('#search1').keyup(function () {
var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
filters.col1 = val;
applyFilters();
});
$('#search2').keyup(function () {
var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
filters.col2 = val;
applyFilters();
});
$('#search3').keyup(function () {
var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
filters.col3 = val;
applyFilters();
});
$('#search4').keyup(function () {
var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
filters.col4 = val;
applyFilters();
});
function applyFilters() {
$rows.show();
$rows.filter(function () {
var text = $(this).find('td:nth-child(1)').text().replace(/\s+/g, ' ').toLowerCase();
return !~text.indexOf(filters.col1);
}).hide();
$rows.filter(function () {
var text = $(this).find('td:nth-child(2)').text().replace(/\s+/g, ' ').toLowerCase();
return !~text.indexOf(filters.col2);
}).hide();
$rows.filter(function () {
var text = $(this).find('td:nth-child(3)').text().replace(/\s+/g, ' ').toLowerCase();
return !~text.indexOf(filters.col3);
}).hide();
$rows.filter(function () {
var text = $(this).find('td:nth-child(4)').text().replace(/\s+/g, ' ').toLowerCase();
return !~text.indexOf(filters.col4);
}).hide();
};
</script>