"Panel Tables with Filter"
Bootstrap 3.2.0 Snippet by imatheusmoreira

<link href="//netdna.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css"> <script src="//netdna.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> <script src="//code.jquery.com/jquery-1.11.1.min.js"></script> <!------ Include the above in your HEAD tag ----------> <div class="container"> <h1>Click en <small>(<i class="glyphicon glyphicon-search"></i>) </small>para filtrar datos</h1> <div class="row"> <div class="col-md-6"> <div class="panel panel-primary"> <div class="panel-heading"> <h3 class="panel-title">Roster Tigres de Chinandega</h3> <div class="pull-right"> <span class="clickable filter" data-toggle="tooltip" title="Filtrar Datos" data-container="body"> <i class="glyphicon glyphicon-search"></i> </span> </div> </div> <div class="panel-body"> <input type="text" class="form-control" id="dev-table-filter" data-action="filter" data-filters="#dev-table" placeholder="Filtrar Jugadores" /> </div> <table class="table table-hover" id="dev-table"> <thead> <tr> <th>Nombre</th> <th>Posición</th> <th>País</th> </tr> </thead> <tbody> <tr> <td>Douglas Arguello</td> <td>P</td> <td>Nicaragua</td> </tr> <tr> <td>Junior Téllez</td> <td>P</td> <td>Nicaragua</td> </tr> <tr> <td>Pedro Wilder Rayo</td> <td>P</td> <td>Nicaragua</td> </tr> <tr> <td>Carlos Teller</td> <td>P</td> <td>Nicaragua</td> </tr> <tr> <td>Henry Córdoba</td> <td>P</td> <td>Nicaragua</td> </tr> <tr> <td>Juan Pablo López</td> <td>P</td> <td>Nicaragua</td> </tr> <tr> <td>Javier Herrera</td> <td>P</td> <td>Nicaragua</td> </tr> <tr> <td>Adolfo Matamoros</td> <td>C</td> <td>Nicaragua</td> </tr> <tr> <td>Wiston Dávila</td> <td>C</td> <td>Nicaragua</td> </tr> <tr> <td>Edgard Montiel</td> <td>1B</td> <td>Nicaragua</td> </tr> <tr> <td>Dazzy Sharp</td> <td>1B</td> <td>Nicaragua</td> </tr> <tr> <td>Iván Marín</td> <td>SS</td> <td>Nicaragua</td> </tr> <tr> <td>Marvin Martínez</td> <td>IF</td> <td>Nicaragua</td> </tr> <tr> <td>Dwain Fox</td> <td>IF</td> <td>Nicaragua</td> </tr> <tr> <td>Esteban Ramírez</td> <td>OF</td> <td>Nicaragua</td> </tr> <tr> <td>Jen Argeñal</td> <td>OF</td> <td>Nicaragua</td> </tr> <tr> <td>Casey Logan Haerther</td> <td> </td> <td>USA</td> </tr> <tr> <td>Luis Allen</td> <td> </td> <td>Venezuela</td> </tr> <tr> <td>Wuilliams Vásquez</td> <td> </td> <td>Venezuela</td> </tr> <tr> <td>Paul Estrada</td> <td> </td> <td>Venezuela</td> </tr> <tr> <td>Abraham Elvira Delgado</td> <td> </td> <td>México</td> </tr> <tr> <td>Jonathan Vargas</td> <td> </td> <td>Venezuela</td> </tr> <tr> <td>Curt Smith</td> <td> </td> <td>Curacao</td> </tr> <tr> <td>Enmanuel Meza</td> <td>OF</td> <td>Nicaragua</td> </tr> <tr> <td>Horace Rigby</td> <td>P</td> <td>Nicaragua</td> </tr> <tr> <td>Davis Hodgson</td> <td>Gerente General</td> <td>Nicaragua</td> </tr> </tbody> </table> </div> </div> </div>
.row{ margin-top:40px; padding: 0 10px; } .clickable{ cursor: pointer; } .panel-heading div { margin-top: -18px; font-size: 15px; } .panel-heading div span{ margin-left:5px; } .panel-body{ display: none; }
/** * I don't recommend using this plugin on large tables, I just wrote it to make the demo useable. It will work fine for smaller tables * but will likely encounter performance issues on larger tables. * * <input type="text" class="form-control" id="dev-table-filter" data-action="filter" data-filters="#dev-table" placeholder="Filter Developers" /> * $(input-element).filterTable() * * The important attributes are 'data-action="filter"' and 'data-filters="#table-selector"' */ (function(){ 'use strict'; var $ = jQuery; $.fn.extend({ filterTable: function(){ return this.each(function(){ $(this).on('keyup', function(e){ $('.filterTable_no_results').remove(); var $this = $(this), search = $this.val().toLowerCase(), target = $this.attr('data-filters'), $target = $(target), $rows = $target.find('tbody tr'); if(search == '') { $rows.show(); } else { $rows.each(function(){ var $this = $(this); $this.text().toLowerCase().indexOf(search) === -1 ? $this.hide() : $this.show(); }) if($target.find('tbody tr:visible').size() === 0) { var col_count = $target.find('tr').first().find('td').size(); var no_results = $('<tr class="filterTable_no_results"><td colspan="'+col_count+'">No se encontraron resultados</td></tr>') $target.find('tbody').append(no_results); } } }); }); } }); $('[data-action="filter"]').filterTable(); })(jQuery); $(function(){ // attach table filter plugin to inputs $('[data-action="filter"]').filterTable(); $('.container').on('click', '.panel-heading span.filter', function(e){ var $this = $(this), $panel = $this.parents('.panel'); $panel.find('.panel-body').slideToggle(); if($this.css('display') != 'none') { $panel.find('.panel-body input').focus(); } }); $('[data-toggle="tooltip"]').tooltip(); })

Related: See More


Questions / Comments: