Created
March 2, 2021 17:37
-
-
Save jmarreros/b61ecf11076dd3b22c7c399f3f63cc87 to your computer and use it in GitHub Desktop.
This file contains 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
/* | |
Se requiere pasar un objeto vars_table, que contenga el selector de la tabla HTML y el placeholder, por ejemplo: | |
let vars_table = { | |
"select": "table.table-data", | |
"placeholder": "Buscar empleados" | |
} | |
*/ | |
(function( $ ) { | |
'use strict'; | |
const select_table = vars_table.table; | |
const search_input = ` <section class="container-search"> | |
<input type="search" id="table-search" name="table-search" placeholder="${vars_table.placeholder}" /> | |
</section>`; | |
// insertar input | |
$(search_input).insertBefore(select_table); | |
// Búsqueda | |
let rows = $(select_table).find('tr').not(':first'); | |
$('#table-search').keyup(function() { | |
const search_value = $.trim($(this).val()).replace(/ +/g,' ').toLowerCase(); | |
rows.show().filter( function(){ | |
const row_value = $(this).text().toLowerCase(); | |
return !~row_value.indexOf(search_value); | |
}).hide(); | |
}); | |
})( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment