Created
June 18, 2013 21:56
-
-
Save rderoldan1/5809826 to your computer and use it in GitHub Desktop.
Search in a table with coffeescript, hide not matched
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ -> | |
$('#search').keyup -> | |
searchTable($(this).val()) | |
searchTable = (inputVal) -> | |
table = $('.table') | |
table.find('tr').each (index, row) -> | |
if index != 0 | |
allCells = $(row).find('td') | |
if(allCells.length > 0) | |
found = false | |
allCells.each (index, td) -> | |
regExp = new RegExp(inputVal, 'i') | |
if(regExp.test($(td).text())) | |
found = true; | |
return false; | |
if(found == true) | |
$(row).fadeIn() | |
else | |
$(row).fadeOut() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= fields_for :search do%> | |
<%= label_tag :search %> | |
<%= text_field_tag :search %> | |
<% end %> | |
<table class="table"> | |
<tr class="table_head"> | |
<td>Cliente</td> | |
<td>Fecha de Na</td> | |
<td>Edad</td> | |
<td>Direccion</td> | |
<td>Estudio</td> | |
<td>telefono</td> | |
<td>Número celular</td> | |
</tr> | |
<% @clientes.each do |c| %> | |
<tr class="table_body"> | |
<td><%= c.cliente %></td> | |
<td><%# c.fecha %></td> | |
<td><%= c.edad %></td> | |
<td><%= c.dir %></td> | |
<td><%= c.est %></td> | |
<td><%= c.tel %></td> | |
<td><%= c.num %></td> | |
</tr> | |
<% end %> | |
</table> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment